Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created September 7, 2016 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/cdd59ac9215539ba003e5fa7460e58ea to your computer and use it in GitHub Desktop.
Save mvidner/cdd59ac9215539ba003e5fa7460e58ea to your computer and use it in GitHub Desktop.
#!/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