Skip to content

Instantly share code, notes, and snippets.

@tmd45
Last active August 29, 2015 14:13
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 tmd45/523ce74db437eebfe51f to your computer and use it in GitHub Desktop.
Save tmd45/523ce74db437eebfe51f to your computer and use it in GitHub Desktop.
Convert to Zenkaku | Hankaku test
require 'nkf'
class Convert
def self.to_han(text)
puts "----- to_han -----"
print_cp(text)
text = NKF.nkf('-wZ0', text)
print_cp(text)
end
def self.to_zen(text)
puts "----- to_zen -----"
print_cp(text)
# ASCII文字種を一度半角文字にして揃える
text = NKF.nkf('-wZ0', text)
# 半角英数字記号(ASCII)を全角英数字記号に変換
text = text.tr("!-~\s", "!-~ ")
print_cp(text)
end
private
def self.print_cp(text)
p text
text.each_codepoint {|cp| $stdout << "U+" << cp.to_s(16) << " " }
$stdout << "\n"
end
end
data = ARGV[0]
Convert.to_han(data)
Convert.to_zen(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment