Skip to content

Instantly share code, notes, and snippets.

@mvidner mvidner/chardump.rb
Created Sep 7, 2016

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.