Created
February 16, 2009 14:36
-
-
Save Kimtaro/65191 to your computer and use it in GitHub Desktop.
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 'test/unit' | |
require 'test/unit/ui/console/testrunner' | |
module Kaku | |
FULLWIDTH_ROMAJI = '!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' | |
HALFWIDTH_ROMAJI = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' | |
def fullwidth_to_halfwidth(text) | |
text.gsub(/\xEF[\xBC\xBD]./) do |m| | |
m[1] == 188 ? | |
(m[2] - 96).chr : | |
(m[2] - 32).chr | |
end.gsub(/\xE3\x80\x80/, " ") | |
end | |
end | |
class KakuTest < Test::Unit::TestCase | |
include Kaku | |
def test_fullwidth_to_halfwidth | |
assert_equal(HALFWIDTH_ROMAJI, fullwidth_to_halfwidth(FULLWIDTH_ROMAJI)) | |
end | |
end | |
Test::Unit::UI::Console::TestRunner.run(KakuTest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment