Skip to content

Instantly share code, notes, and snippets.

@kn
Last active December 22, 2015 21:19
Show Gist options
  • Save kn/6532899 to your computer and use it in GitHub Desktop.
Save kn/6532899 to your computer and use it in GitHub Desktop.
A collection of utility methods for Japanese chars.
# -*- 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
@kn
Copy link
Author

kn commented Sep 12, 2013

cc/ @amiruci

@amiruci
Copy link

amiruci commented Sep 12, 2013

awesome. thanks @kn

@amiruci
Copy link

amiruci commented Sep 12, 2013

their cool emoticons don't work in gist comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment