lib/regextest/back/result.rb in regextest-0.1.6 vs lib/regextest/back/result.rb in regextest-0.1.8
- old
+ new
@@ -380,22 +380,30 @@
elsif @results.size == 0
@results.push (Regextest::Back::Element.any_char)
@results.push (Regextest::Back::Element.any_char)
bound_process(@results[0], @results[1])
elsif offset == @results.size
- @results.push (Regextest::Back::Element.any_char)
- if !bound_process(@results[-2], @results[-1])
+ if !is_end_anchor?
+ @results.push (Regextest::Back::Element.any_char)
+ if !bound_process(@results[-2], @results[-1])
+ return false
+ end
+ elsif !@results[-1].word_elements?
return false
end
elsif offset == 0
- if !unshift_params(1)
+ if !is_begin_anchor?
+ if !unshift_params(1)
+ return false
+ end
+ @results.unshift (Regextest::Back::Element.any_char)
+ if !bound_process(@results[0], @results[1])
+ return false
+ end
+ elsif !@results[0].word_elements?
return false
end
- @results.unshift (Regextest::Back::Element.any_char)
- if !bound_process(@results[0], @results[1])
- return false
- end
end
end
when :CMD_ANC_WORD_UNBOUND
offsets.uniq.size.times do | i |
offset = offsets[i]
@@ -407,22 +415,30 @@
elsif @results.size == 0
@results.push (Regextest::Back::Element.any_char)
@results.push (Regextest::Back::Element.any_char)
unbound_process(@results[0], @results[1])
elsif offset == @results.size
- @results.push (Regextest::Back::Element.any_char)
- if !unbound_process(@results[-2], @results[-1])
+ if !is_end_anchor?
+ @results.push (Regextest::Back::Element.any_char)
+ if !unbound_process(@results[-2], @results[-1])
+ return false
+ end
+ elsif @results[-1].word_elements?
return false
end
elsif offset == 0
- if !unshift_params(1)
+ if !is_begin_anchor?
+ if !unshift_params(1)
+ return false
+ end
+ @results.unshift (Regextest::Back::Element.any_char)
+ if !unbound_process(@results[0], @results[1])
+ return false
+ end
+ elsif @results[0].word_elements?
return false
end
- @results.unshift (Regextest::Back::Element.any_char)
- if !unbound_process(@results[0], @results[1])
- return false
- end
end
end
when :CMD_ANC_LOOK_BEHIND2
@start_offset = offsets.max
else
@@ -478,9 +494,27 @@
end
if elem1.empty? || elem2.empty?
return false
end
true
+ end
+
+ # return true if begin anchor exists
+ def is_begin_anchor?
+ (@positional_anchors[:CMD_ANC_STRING_BEGIN] &&
+ @positional_anchors[:CMD_ANC_STRING_BEGIN][0] == 0) ||
+ (@positional_anchors[:CMD_ANC_LINE_BEGIN] &&
+ @positional_anchors[:CMD_ANC_LINE_BEGIN][0] == 0)
+ end
+
+ # return true if end anchor exists
+ def is_end_anchor?
+ (@positional_anchors[:CMD_ANC_STRING_END] &&
+ @positional_anchors[:CMD_ANC_STRING_END][-1] == @results.size) ||
+ (@positional_anchors[:CMD_ANC_STRING_END2] &&
+ @positional_anchors[:CMD_ANC_STRING_END2][-1] == @results.size) ||
+ (@positional_anchors[:CMD_ANC_LINE_END] &&
+ @positional_anchors[:CMD_ANC_LINE_END][-1] == @results.size)
end
# Fixes results
def fix
@pre_match = fix_part(0, @start_offset-1)