Mercurial > jwe > octave
diff liboctave/regexp.cc @ 14536:6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
* NEWS: Announce new options.
* liboctave/regexp.cc (regexp::match): Add processing option for zero length
matches.
* liboctave/regexp.h (class opts): Add emptymatch option to constructors,
setter/getter routines, private variable.
* DLD-FUNCTIONS/regexp.cc (parse_options): Add emptymatch to options parsing routine.
* DLD-FUNCTIONS/regexp.cc (octregexp): Ignore emptymatch when determing output ordering
of arguments.
* DLD-FUNCTIONS/regexp.cc (Fregexp): Add new options to docstring. Add %!tests for new
behavior.
* DLD-FUNCTIONS/regexp.cc (Fregexprep): Add %!tests for new behavior.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 07 Apr 2012 09:43:53 -0700 |
parents | 6cc30975e262 |
children |
line wrap: on
line diff
--- a/liboctave/regexp.cc Fri Apr 06 19:21:16 2012 -0400 +++ b/liboctave/regexp.cc Sat Apr 07 09:43:53 2012 -0700 @@ -315,9 +315,9 @@ } else if (matches == PCRE_ERROR_NOMATCH) break; - else if (ovector[1] <= ovector[0]) + else if (ovector[1] <= ovector[0] && ! options.emptymatch ()) { - // Zero sized match. Skip to next char. + // Zero length match. Skip to next char. idx = ovector[0] + 1; if (idx < buffer.length ()) continue; @@ -400,7 +400,16 @@ regexp::match_element new_elem (named_tokens, tokens, match_string, token_extents, start, end); lst.push_back (new_elem); - idx = ovector[1]; + + if (ovector[1] <= ovector[0]) + { + // Zero length match. Skip to next char. + idx = ovector[0] + 1; + if (idx <= buffer.length ()) + continue; + } + else + idx = ovector[1]; if (options.once () || idx >= buffer.length ()) break;