Created
September 7, 2016 15:11
-
-
Save mvidner/cdd59ac9215539ba003e5fa7460e58ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# coding: utf-8 | |
def char_as_4hex(c) | |
format("%04x", c.ord) | |
end | |
REPLACEMENT = "\ufffd" # � | |
FSI = "\u2068" # First Strong Isolate | |
PDI = "\u2069" # Pop Directional Isolate | |
LRM = "\u200e" | |
LRO = "\u202d" | |
PDF = "\u202c" | |
def char_as_isolate(c) | |
c = REPLACEMENT if c == "\n" || c == "\t" | |
# "#{FSI}#{c}#{PDI}" | |
# "#{LRM}#{c}#{LRM}" | |
"#{LRO}#{c}#{PDF}" | |
end | |
def dump_chars(char_array) | |
elements = char_array.map {|c| char_as_4hex(c)} + | |
[":"] + | |
char_array.map {|c| char_as_isolate(c) } | |
puts elements.join " " | |
end | |
ARGF.each_char.each_slice(16) do |ca| | |
dump_chars(ca) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment