[your code here] minimal hex viewer
Justin Whear
mrjnewt at gmail.com
Thu Jan 4 00:25:59 UTC 2018
// Reads bytes from stdin and writes a hexadecimal view like a
no-frills xxd.
// All the actual formatting work is done by format's sweet range
syntax
void main(string[] args)
{
import std.getopt;
uint bytesPerLine = 8;
args.getopt(
"cols|c", &bytesPerLine
);
import std.stdio;
import std.range : chunks;
import std.algorithm : map, copy;
import std.string : format;
import std.ascii : newline;
stdin.byChunk(bytesPerLine)
.map!(bytes => bytes.format!"%(%02X %)%s"(newline))
.copy(stdout.lockingTextWriter());
}
More information about the Digitalmars-d
mailing list