Last active
August 29, 2015 14:13
-
-
Save tmd45/523ce74db437eebfe51f to your computer and use it in GitHub Desktop.
Convert to Zenkaku | Hankaku test
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
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