summaryrefslogtreecommitdiff
path: root/src/regexp.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/regexp.zig')
-rw-r--r--src/regexp.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 86132f60..4cbca57e 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -58,7 +58,7 @@ pub const Regex = struct {
/// Timed on this machine's ReleaseSafe build: 10M steps of the worst
/// patterns take 45-80 ms, and a Debug build is ten times slower.
- pub const budget: u64 = if (builtin.mode == .Debug) 4_000_000 else 32_000_000;
+ pub const budget: u64 = if (builtin.mode == .debug) 4_000_000 else 32_000_000;
pub const e_long = std.fmt.comptimePrint("bad regular expression: longer than mvzr's {d} operations (about {d} pattern characters)", .{ max_ops, max_ops });
pub const e_anchor = "bad regular expression: in a pattern with \\n, ^ can only come first and $ only just before a \\n";
@@ -503,10 +503,10 @@ test "a class with non-ASCII runes matches those runes: [éa-z], a range of them
}
test "a pattern past 64 characters compiles, and one past the limit says so" {
- var long = try Regex.compile("a" ** 200);
- const text = "x" ++ "a" ** 200 ++ "\n";
+ var long = try Regex.compile(&@as([200]u8, @splat('a')));
+ const text = "x" ++ &@as([200]u8, @splat('a')) ++ "\n";
try std.testing.expectEqual(@as(usize, 1), (try long.find(text, 0, text.len, text.len)).?.start);
- try std.testing.expectError(error.TooLong, Regex.compile("a" ** (max_ops + 8)));
+ try std.testing.expectError(error.TooLong, Regex.compile(&@as([max_ops + 8]u8, @splat('a'))));
try std.testing.expectError(error.Bad, Regex.compile("a[b"));
}
@@ -546,13 +546,13 @@ test "a search that would backtrack without end runs out of budget, promptly" {
// As long a chain as mvzr compiles, over runs one `a` short of it: 2^20
// steps from every start.
for (0..line.len / 20) |i| line[i * 20 + 19] = 'b';
- var chain = try Regex.compile("a?" ** 20 ++ "a" ** 20);
+ var chain = try Regex.compile(std.mem.asBytes(&@as([20][2]u8, @splat("a?".*))) ++ &@as([20]u8, @splat('a')));
try std.testing.expectError(error.TooSlow, chain.find(&line, 0, line.len, line.len));
}
test "the match is the leftmost, however long the line" {
// A window cut into the identifier would find `x... =` from its middle.
- const text = "let " ++ "x" ** 100 ++ " = 1";
+ const text = "let " ++ &@as([100]u8, @splat('x')) ++ " = 1";
var assign = try Regex.compile("\\s*(\\w+)\\s*=");
const m = (try assign.find(text, 0, text.len, text.len)).?;
try std.testing.expectEqual(@as(usize, 3), m.start);