Module: Alchemist::UnicodeMonospace
- Defined in:
- lib/alchemist/unicode_monospace.rb
Defined Under Namespace
Modules: StringExtensions
Constant Summary
collapse
- DATA_FILE =
File.join(File.dirname(__FILE__), 'EastAsianWidth.txt')
Class Method Summary
collapse
Class Method Details
.build_east_asian_widths ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/alchemist/unicode_monospace.rb', line 26
def self.build_east_asian_widths
widths = {}
File.open(DATA_FILE) do |io|
io.each_line do |line|
next if line =~ /^#/
code_spec, width, _ = line.split(/;|#/)
codes = if code_spec =~ /\.\./
min,max = code_spec.split '..'
(min.to_i(16)..max.to_i(16)).to_a
else
[code_spec.to_i(16)]
end
codes.each do |code|
widths[code] = width && width.strip
end
end
end
widths
end
|
.east_asian_width(c) ⇒ Object
16
17
18
|
# File 'lib/alchemist/unicode_monospace.rb', line 16
def self.east_asian_width(c)
east_asian_widths[c]
end
|
.east_asian_widths ⇒ Object
20
21
22
|
# File 'lib/alchemist/unicode_monospace.rb', line 20
def self.east_asian_widths
@east_asian_widths ||= build_east_asian_widths
end
|