class Regextest::Front::Repeat::Repeat
Constants
- TstOptGreedy
Constants for the class
- TstOptPossessive
- TstOptReluctant
Attributes
max_value[R]
min_value[R]
option[R]
Public Class Methods
new(param)
click to toggle source
Constructor
# File lib/regextest/front/repeat.rb, line 16 def initialize(param) @min_value = 1 @max_value = 1 @option = 0 set_values(param) if(param) end
Public Instance Methods
is_possessive?()
click to toggle source
a++. etc.
# File lib/regextest/front/repeat.rb, line 81 def is_possessive? ((@option & TstOptPossessive) != 0) end
is_reluctant?()
click to toggle source
a+?, etc.
# File lib/regextest/front/repeat.rb, line 76 def is_reluctant? ((@option & TstOptReluctant) != 0) end
set_values(param)
click to toggle source
get minimum, maximum, and option
# File lib/regextest/front/repeat.rb, line 25 def set_values(param) case param when '?', '??', '?+' @min_value = 0 @max_value = 1 @option |= TstOptGreedy if(param.size == 1) @option |= TstOptReluctant if(param == "??") @option |= TstOptPossessive if(param[-1] == "+") when '*', '*?', '*+' @min_value = 0 @max_value = TstConstRepeatMax @option |= TstOptGreedy if(param.size == 1) @option |= TstOptReluctant if(param[-1] == "?") @option |= TstOptPossessive if(param[-1] == "+") when '+', '+?', '++' @min_value = 1 @max_value = TstConstRepeatMax @option |= TstOptGreedy if(param.size == 1) @option |= TstOptReluctant if(param[-1] == "?") @option |= TstOptPossessive if(param == "++") when /^\{(\d+)\}([\?\+]?)$/ # {3}, etc. @min_value = $1.to_i @max_value = $1.to_i @option |= TstOptGreedy if(!$2) @option |= TstOptReluctant if($2 == "?") @option |= TstOptPossessive if($2 == "+") when /^\{(\d+),(\d+)\}([\?\+]?)$/ # {2,3}, etc. @min_value = $1.to_i @max_value = $2.to_i @option |= TstOptGreedy if(!$2) @option |= TstOptReluctant if($2 == "?") @option |= TstOptPossessive if($2 == "+") when /^\{,(\d+)\}([\?\+]?)$/ # {,3}, etc. @min_value = 0 @max_value = $1.to_i @option |= TstOptGreedy if(!$2) @option |= TstOptReluctant if($2 == "?") @option |= TstOptPossessive if($2 == "+") when /^\{(\d+),\}([\?\+]?)$/ # {3,}, etc. @min_value = $1.to_i @max_value = TstConstRepeatMax @max_value = @min_value + TstConstRepeatMax if(@max_value < @min_value) @option |= TstOptGreedy if(!$2) @option |= TstOptReluctant if($2 == "?") @option |= TstOptPossessive if($2 == "+") else raise "Error: repeat notation #{param} invalid" end end