module Stringex::Unidecoder
def code_group(unpacked_character)
def code_group(unpacked_character) "x%02x" % (unpacked_character >> 8) end
def decode(string)
Returns string with its UTF-8 characters transliterated to ASCII ones
def decode(string) string.chars.map{|char| decoded(char)}.join end
def decoded(character)
def decoded(character) localized(character) || from_yaml(character) end
def encode(codepoint)
def encode(codepoint) ["0x#{codepoint}".to_i(16)].pack("U") end
def from_yaml(character)
def from_yaml(character) return character unless character.ord > 128 unpacked = character.unpack("U")[0] CODEPOINTS[code_group(unpacked)][grouped_point(unpacked)] rescue # Hopefully this won't come up much # TODO: Make this note something to the user that is reportable to me perhaps "?" end
def get_codepoint(character)
def get_codepoint(character) "%04x" % character.unpack("U")[0] end
def grouped_point(unpacked_character)
def grouped_point(unpacked_character) unpacked_character & 255 end
def in_yaml_file(character)
Returns string indicating which file (and line) contains the
def in_yaml_file(character) unpacked = character.unpack("U")[0] "#{code_group(unpacked)}.yml (line #{grouped_point(unpacked) + 2})" end
def localized(character)
def localized(character) Localization.translate(:transliterations, character) end