Module: AnyAscii

Defined in:
lib/any_ascii.rb

Class Method Summary collapse

Class Method Details

.transliterate(string) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/any_ascii.rb', line 17

def self.transliterate(string)
	if string.ascii_only?
		return string
	end
	result = ''
	string.each_codepoint { |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
	}
	return result
end