mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
strings.bif/sub,gsub: Respect anchors in pattern
Anchors within pattern passed to sub() or gsub() were previously ignored, replacing any occurrence of '<text>' even when '^<text>' was used as a pattern. This is a pretty user-visible change (and we even have anchored patterns within the base scripts), but seems "the right thing to do". Relates to #3455
This commit is contained in:
parent
d9b8154c4e
commit
e339e93e69
5 changed files with 76 additions and 1 deletions
|
@ -789,15 +789,22 @@ StringValPtr StringVal::Replace(RE_Matcher* re, const String& repl, bool do_all)
|
|||
vector<std::pair<int, int>> cut_points;
|
||||
|
||||
int size = 0; // size of result
|
||||
bool bol = true;
|
||||
const bool eol = true;
|
||||
|
||||
while ( n > 0 ) {
|
||||
// Find next match offset.
|
||||
int end_of_match;
|
||||
while ( n > 0 && (end_of_match = re->MatchPrefix(&s[offset], n)) <= 0 ) {
|
||||
while ( n > 0 ) {
|
||||
end_of_match = re->MatchPrefix(&s[offset], n, bol, eol);
|
||||
if ( end_of_match > 0 )
|
||||
break;
|
||||
|
||||
// This character is going to be copied to the result.
|
||||
++size;
|
||||
|
||||
// Move on to next character.
|
||||
bol = false;
|
||||
++offset;
|
||||
--n;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue