1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#!/usr/bin/env ruby
str = ARGV[0]
def string_object_to_utf16 str
[str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_16BE
end
def string_object_to_utf8 str
[str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_8
end
def utf16_to_utf8 str
str.encode ::Encoding::UTF_8
end
def decode_hexified_utf16_string_object str
utf16_to_utf8 string_object_to_utf16 str
end
def decode_hexified_utf8_string_object str
string_object_to_utf8 str
end
if ARGV[1] == 'utf8'
puts decode_hexified_utf8_string_object ARGV[0].dup
else
puts decode_hexified_utf16_string_object ARGV[0].dup
end
|