Skip to content

Instantly share code, notes, and snippets.

@ochaochaocha3
Created December 6, 2014 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 ochaochaocha3/28676a0dcf68f687a325 to your computer and use it in GitHub Desktop.
Save ochaochaocha3/28676a0dcf68f687a325 to your computer and use it in GitHub Desktop.
IRC メッセージの文字コード変換:ISO-2022-JP -> UTF-8
# vim: fileencoding=utf-8
s = "\x31\x33\x3A\x35\x39\x3A\x34\x36\x20\x3C\x23\e\x24\x42\x24\x62\x24\x4E\x3D\x71\x24\x2D\e\x28\x42\x3A\x4C\x65\x6F\x5F\x47\x75\x6E\x7A\x3E\x20\e\x24\x42\x21\x44\x21\x44\x24\x3D\x24\x6C\x24\x4F\e\x28\x42\x02\e\x24\x42\x36\x58\x34\x77\e\x28\x42\x0F\e\x24\x42\x21\x4A\x47\x7A\x21\x4B\x21\x64\x24\x4A\x24\x4E\x24\x4F\e\x28\x42"
s.force_encoding('ISO-2022-JP')
replaced_chars = s.chars.map do |ch|
ch.bytes[0] == 0x0F ? "\x18".encode('ISO-2022-JP') : ch
end
p replaced_chars.join.encode('UTF-8').gsub("\x18", "\x0F")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment