#!/usr/local/bin/ruby -w # cp932.rb # ver.0.1 Aug.8.24 create # eaa5 - fcfc # ed40 - eefc (eeec) # fa40 (fa5c) - fc4b module CP932 # < ShiftJIS def quote(chunk, q1 = "", q2 = "") chunk.split(//s).collect { |ch| a = ch.unpack("C*") if a.size == 2 code = a[0] * 0x100 + a[1] if (0xed40 <= code && code <= 0xeefc) || (0xfa40 <= code && code <= 0xfc4b) q1 + "%04x" % code + q2 else ch end else ch end }.join end module_function :quote end if __FILE__ == $0 while gets print CP932::quote($_) end end