lib/regextest/front/char-class.rb in regextest-0.1.5 vs lib/regextest/front/char-class.rb in regextest-0.1.6
- old
+ new
@@ -18,17 +18,17 @@
@@unicode_whole_set = nil
attr_reader :candidates, :offset, :length
# Constructor
- def initialize(value)
+ def initialize(value, caller_type = nil)
TstLog("CharClass: #{value}")
@@ascii_whole_set ||= get_ascii_whole_set
@@unicode_whole_set ||= get_unicode_whole_set
+ @caller_type = caller_type
-
- @reg_options = @@parse_options[:reg_options]
+ @options = nil
case value
when Array
@candidates = value
@offset = -1 # value[0].offset
@length = -1 # value[-1].offset + value[-1].length - value[0].offset
@@ -196,21 +196,26 @@
end
# fixes charset using options
def set_options(options)
TstLog("CharClass set_options: #{options[:reg_options].inspect}")
+ @options = options
# call set_options of other bracket
@candidates.each do |candidate|
if candidate.respond_to?(:set_options)
candidate.set_options(options)
end
end
and_process(options) if @other_char_classes.size > 0
- ignore_process(options)
+ # somehow ignore process must be skipped when unicode
+ # class (\p{lower} etc.) in outside of bracket
+ if @caller_type != :LEX_UNICODE_CLASS
+ ignore_process(options)
+ end
# reverse char set
if @is_reverse
set_reverse(options)
end
@@ -220,14 +225,17 @@
# transform to json format
def json
#if @candidates.size > 1
@@id += 1
+ charset = @options[:reg_options].charset
"{" +
"\"type\": \"LEX_CHAR_CLASS\", \"id\": \"CC#{@@id}\", " +
"\"offset\": #{@offset}, \"length\": #{@length}, " +
"\"value\": [" + @candidates.map{|elem| elem.json}.join(",") +
- "]}"
+ "], " +
+ "\"charset\": \"#{charset}\"" +
+ "}"
#else
# @candidates[0].json
#end
end
end