Last active
December 22, 2015 21:19
-
-
Save kn/6532899 to your computer and use it in GitHub Desktop.
A collection of utility methods for Japanese chars.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require 'nkf' | |
def full2half(str) | |
NKF.nkf('-wxZ4Z1', str).gsub('-', 'ー') | |
end | |
def is_half?(str) | |
!!(/^[ -~。-゚]*$/.match str) | |
end | |
def is_full?(str) | |
!!(/^[^ -~。-゚]*$/.match str) | |
end | |
def is_full_katakana?(str) | |
!!(/^[ァ-ヺ ー]*$/.match str) | |
end | |
def is_full_hiragana?(str) | |
!!(/^[ぁ-ゖ ー]*$/.match str) | |
end | |
def is_half_katakana?(str) | |
!!(/^[ヲ-ン ]*$/.match str) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cc/ @amiruci