module ZhongwenTools::Unicode
Public Class Methods
ascii?(str)
click to toggle source
# File lib/zhongwen_tools/unicode.rb, line 17 def self.ascii?(str) str.chars.to_a.size == str.bytes.to_a.size end
from_codepoint(str)
click to toggle source
# File lib/zhongwen_tools/unicode.rb, line 9 def self.from_codepoint(str) results = (str.split(/\\?u/) - ['']).map do |s| [s.hex].pack("U") end results.join end
multibyte?(str)
click to toggle source
# File lib/zhongwen_tools/unicode.rb, line 21 def self.multibyte?(str) !ascii?(str) end
to_codepoint(str)
click to toggle source
# File lib/zhongwen_tools/unicode.rb, line 5 def self.to_codepoint(str) str.chars.map{ |c| "\\u%04x" % c.unpack("U")[0] }.join end