diff --git a/8to7.d b/8to7.d new file mode 100644 index 0000000..20cbad1 --- /dev/null +++ b/8to7.d @@ -0,0 +1,36 @@ +module main; +import std.stdio; +import std.uni : isWhite; +import std.string : strip, empty; +import std.array; +import std.format.read : formattedRead; + +void main() { + ubyte b; + while(!stdin.eof()) { + string line = strip(readln()); + if (line.empty) { return; } + + auto pieces = line.split!isWhite; + + foreach (string p; pieces) { + if (1 == formattedRead(p, "%x", &b)) { + writef("%02x ", b & 0x7F); + } + } + write(" "); + + foreach (string p; pieces) { + if (1 == formattedRead(p, "%x", &b)) { + b = b & 0x7F; + if (b < 32 || b >= 127) { + write("."); + } else { + writef("%s", cast(char)b); + } + } + } + + writeln(); + } +}