Module: AnyAscii

Defined in:
lib/any_ascii.rb

Overview

Unicode to ASCII transliteration

Class Method Summary collapse

Class Method Details

.transliterate(string) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/any_ascii.rb', line 7

def self.transliterate(string)
  return string if string.ascii_only?

  result = String.new('')
  string.each_codepoint do |cp|
    if cp <= 127
      result << cp
    else
      block_num = cp >> 8
      lo = cp & 0xff
      block = BLOCKS[block_num]
      result << block[lo] if lo < block.length
    end
  end
  result
end