Module: AnyAscii

Defined in:
lib/any_ascii.rb

Class Method Summary collapse

Class Method Details

.transliterate(string) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/any_ascii.rb', line 21

def self.transliterate(string)
  if string.ascii_only?
    return string
  end
  result = ''
  string.each_codepoint do |cp|
    if cp <= 127
      result << cp
    else
      block_num = cp >> 8
      lo = cp & 0xff
      block = BLOCKS[block_num]
      if block.length > lo
        result << block[lo]
      end
    end
  end
  return result
end