class Test::Unit::Diff::UTF8Line
Constants
- AMBIGUOUS
- WIDE_CHARACTERS
from unicode.org/reports/tr11/
Public Class Methods
new(line)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 373 def initialize(line) @line = line @characters = @line.unpack("U*") end
wide_character?(character)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 348 def wide_character?(character) binary_search_ranges(character, WIDE_CHARACTERS) or binary_search_ranges(character, AMBIGUOUS) end
Private Class Methods
binary_search_ranges(character, ranges)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 354 def binary_search_ranges(character, ranges) if ranges.size.zero? false elsif ranges.size == 1 ranges[0].include?(character) else half = ranges.size / 2 range = ranges[half] if range.include?(character) true elsif character < range.begin binary_search_ranges(character, ranges[0...half]) else binary_search_ranges(character, ranges[(half + 1)..-1]) end end end
Public Instance Methods
[](*args)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 378 def [](*args) result = @characters[*args] if result.respond_to?(:pack) result.pack("U*") else result end end
compute_width(start, _end)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 399 def compute_width(start, _end) width = 0 start.upto(_end - 1) do |i| if self.class.wide_character?(@characters[i]) width += 2 else width += 1 end end width end
each(&block)
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 387 def each(&block) @characters.each(&block) end
size()
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 391 def size @characters.size end
to_s()
click to toggle source
# File test-unit-3.5.3/lib/test/unit/diff.rb, line 395 def to_s @line end