Created
June 9, 2011 18:49
-
-
Save coldnebo/1017423 to your computer and use it in GitHub Desktop.
ruby 1.9.2 character encoding helper
This file contains 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
class String | |
def hexbytes | |
self.bytes.to_a.map {|c| c.to_s(16).upcase}.join | |
end | |
def hexchars | |
self.chars.to_a.map {|c| c.hexbytes} | |
end | |
def unicodechars | |
self.chars.to_a.map {|c| c.hexbytes} | |
end | |
def debug | |
puts "%-8s: %s" % ["encoding", encoding.name] | |
puts "%-8s: %-4s" % ["chars", to_series(chars.to_a)] | |
puts "%-8s: %-4s" % ["hex", to_series(hexchars)] | |
end | |
def to_series(array) | |
array.map {|c| c.rjust(4)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment