module Forkforge::UnicodeData
Constants
- FILE
- LOCAL
- REMOTE
Public Instance Methods
code_points()
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 22 def code_points @codepoints ||= CodePoints.new hash end
compose_cp(cp, tag = :font, thorough = true)
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 60 def compose_cp cp, tag = :font, thorough = true cp = __to_code_point cp return Forkforge::CodePoint.new(hash[cp]) unless (t = CharacterDecompositionMapping::Tag.tag(tag)).valid? @cdm[tag] = all_character_decomposition_mapping(/#{t.tag}/).values if @cdm[tag].nil? # FIXME Could we distinguish “<wide> 0ABC” and “0A00 0ABC” in more elegant way? lmbd = ->(v) { v[:character_decomposition_mapping] =~ /[^\dA-Fa-f]\s+#{cp}\Z/ } thorough ? \ @cdm[tag].select(&lmbd).map { |cp| Forkforge::CodePoint.new(cp) } : Forkforge::CodePoint.new(@cdm[tag].find(&lmbd) || hash[cp]) end
decompose_cp(cp, tags = [])
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 72 def decompose_cp cp, tags = [] normalized = __to_code_point cp mapping = get_character_decomposition_mapping cp return normalized if mapping.vacant? cps = mapping.split ' ' return normalized if ![*tags].vacant? && \ cps.inject(false) { |memo, cp| memo || (CharacterDecompositionMapping::Tag::tag?(cp) && ![*tags].include?(CharacterDecompositionMapping::Tag::tag(cp).sym)) } cps.reject { |cp| Forkforge::CharacterDecompositionMapping::Tag::tag? cp }.map { |cp| decompose_cp cp, tags } end
hash()
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 18 def hash i_hash(REMOTE, LOCAL, FILE, CodePoint::UNICODE_FIELDS, false) end
info(cp)
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 26 def info cp cp = cp.codepoints.first if String === cp && cp.length == 1 hash[__to_code_point(cp)] end
infos(string)
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 31 def infos string string.codepoints.map { |cp| hash[__to_code_point(cp)] } end
to_char(cp, action = :code_point)
click to toggle source
TODO return true/false whether the normalization was done?
# File lib/forkforge/internal/unicode_data.rb, line 36 def to_char cp, action = :code_point elem = hash[__to_code_point(cp)] __to_char(elem[action].vacant? ? elem[:code_point] : elem[action]) end
to_codepoint(cp)
click to toggle source
# File lib/forkforge/internal/unicode_data.rb, line 41 def to_codepoint cp Forkforge::CodePoint.new info cp end