lib/unicode/name.rb in unicode-name-1.13.1 vs lib/unicode/name.rb in unicode-name-1.13.2

- old
+ new

@@ -9,15 +9,22 @@ # Don't overwrite Module.name def self.unicode_name(char) codepoint = char.unpack("U")[0] require_relative "name/index" unless defined? ::Unicode::Name::INDEX + if res = INDEX[:NAMES][codepoint] - res - elsif INDEX[:CJK].any?{ |cjk_range| codepoint >= cjk_range[0] && codepoint <= cjk_range[1] } - "CJK UNIFIED IDEOGRAPH-%.4X" % codepoint - elsif codepoint >= HANGUL_START && codepoint <= HANGUL_END + return insert_words(res) + end + + INDEX[:CP_RANGES].each{|prefix, range| + if range.any?{ |range| codepoint >= range[0] && codepoint <= range[1] } + return "%s%.4X" %[prefix, codepoint] + end + } + + if codepoint >= HANGUL_START && codepoint <= HANGUL_END "HANGUL SYLLABLE %s" % hangul_decomposition(codepoint) else nil end end @@ -79,9 +86,20 @@ base = codepoint - HANGUL_START final = base % HANGUL_FINAL_MAX medial = (base % HANGUL_MEDIAL_MAX) / HANGUL_FINAL_MAX initial = base / HANGUL_MEDIAL_MAX "#{INDEX[:JAMO][:INITIAL][initial]}#{INDEX[:JAMO][:MEDIAL][medial]}#{INDEX[:JAMO][:FINAL][final]}" + end + + def self.insert_words(raw_name) + raw_name.chars.map{ |char| + codepoint = char.ord + if codepoint < INDEX[:REPLACE_BASE] + char + else + "#{INDEX[:COMMON_WORDS][codepoint - INDEX[:REPLACE_BASE]]} " + end + }.join.chomp end end end