Skip to content

Instantly share code, notes, and snippets.

@Kimtaro
Created February 16, 2009 14:36
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 Kimtaro/65191 to your computer and use it in GitHub Desktop.
Save Kimtaro/65191 to your computer and use it in GitHub Desktop.
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