lib/regextest/front/char-class.rb in regextest-0.1.6 vs lib/regextest/front/char-class.rb in regextest-0.1.8

- old
+ new

@@ -14,10 +14,11 @@ include Regextest::Common include Regextest::Front::Range @@id = 0 # a class variable for generating unique name of element @@ascii_whole_set = nil @@unicode_whole_set = nil + @@any_code_whole_set = nil attr_reader :candidates, :offset, :length # Constructor def initialize(value, caller_type = nil) @@ -78,24 +79,32 @@ def reverse TstLog("CharClass reverse"); @is_reverse = true end - def set_reverse(options) - TstLog("CharClass set_reverse"); + def set_reverse(options, default_whole_set = nil) + TstLog("CharClass set_reverse") + elems = @candidates.inject([]){|result, elem| result += elem.enumerate} + # Calc whole set of letters (depends on language environment) - @whole_set = get_whole_set(options) + @whole_set = default_whole_set || get_whole_set(options) # delete characters from whole set - whole = @whole_set.dup - @candidates.each do | candidate | - whole -= candidate.enumerate + whole = @whole_set.sort + if !default_whole_set && elems.find{| elem | !whole.bsearch {|x| elem <=> x }} + if options[:reg_options].is_unicode? + set_reverse(options, get_any_whole_set) + else # ascii or default mode + set_reverse(options, @@unicode_whole_set) + end + else + whole -= elems + + # reconstructing valid character set using TRange objects + @candidates = reconstruct_candidates(whole) end - - # reconstructing valid character set using TRange objects - @candidates = reconstruct_candidates(whole) self end # Reconstruct candidate letters def reconstruct_candidates(code_points) @@ -156,16 +165,25 @@ ascii_set = Regextest::Unicode.enumerate("ascii") print_set = Regextest::Unicode.enumerate("print") ascii_set & print_set end - # Get whole code set of unicode + # Get code set of specified unicode classes( by environment variable) def get_unicode_whole_set char_set = [] TstConstUnicodeCharSet.split("|").each do | elem | char_set |= Regextest::Unicode.enumerate(elem) end char_set + end + + # Get whole (assigned) unicode set + def get_any_whole_set + if @@any_code_whole_set + @@any_code_whole_set + else + @@any_code_whole_set = Regextest::Unicode.enumerate("assigned") + end end # enumerate nomimated letters def enumerate TstLog("CharClass enumerate")