Skip to content

Commit

Permalink
Attempt match on empty string
Browse files Browse the repository at this point in the history
As the new test illustrates, a Kleene star pattern followed by `$` does,
in fact, match, but only on the empty string.  With this patch mvzr will
try a final pattern match on the empty string before giving up.
  • Loading branch information
mnemnion committed Nov 11, 2024
1 parent e22c155 commit fdd42e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.2.3",
.version = "0.2.4",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
7 changes: 6 additions & 1 deletion src/mvzr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn SizedRegex(ops: comptime_int, char_sets: comptime_int) type {
},
else => {
var matchlen: usize = 0;
while (matchlen < haystack.len) : (matchlen += 1) {
while (matchlen <= haystack.len) : (matchlen += 1) {
const matched = matchOuterPattern(patt, &regex.sets, haystack, matchlen);
if (matched) |m| {
return .{ matchlen, m.i };
Expand Down Expand Up @@ -2224,3 +2224,8 @@ test "repetition and word break" {
const regex = Regex.compile("[de]{2,}\\b").?;
try expect(!regex.isMatch("defense"));
}

test "match end" {
const regex = Regex.compile("a*$").?;
try std.testing.expect(regex.isMatch("bb"));
}

0 comments on commit fdd42e7

Please sign in to comment.