ReviewOS

also looking at this

zig-utils/zig-regex

Migrate to zig 0.16

#5
Closed illya-laifu wants to merge zig-0.16-migrations into main
13 files +222 -239
examples/basic.zigmodified+9-13
Changes to examples/basic.zig
@@ -1,17 +1,13 @@
11const std = ;
22const Regex = .Regex;
33
4pub fn main() !void {
5 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 defer _ = gpa.deinit();
7 const allocator = gpa.allocator();
8
4pub fn main(init: std.process.Init) !void {
95 std.debug.print("\n=== Zig Regex Examples ===\n\n", .{});
106
117 // Example 1: Simple literal matching
128 {
139 std.debug.print("Example 1: Literal matching\n", .{});
14 var regex = try Regex.compile(allocator, "hello");
10 var regex = try Regex.compile(init.gpa, "hello");
1511 defer regex.deinit();
1612
1713 const matches = try regex.isMatch("hello");
@@ -22,7 +18,7 @@ pub fn main() !void {
2218 // Example 2: Alternation
2319 {
2420 std.debug.print("Example 2: Alternation (cat|dog)\n", .{});
25 var regex = try Regex.compile(allocator, "cat|dog");
21 var regex = try Regex.compile(init.gpa, "cat|dog");
2622 defer regex.deinit();
2723
2824 std.debug.print(" 'cat' matches: {}\n", .{try regex.isMatch("cat")});
@@ -34,7 +30,7 @@ pub fn main() !void {
3430 // Example 3: Star quantifier
3531 {
3632 std.debug.print("Example 3: Star quantifier (a*)\n", .{});
37 var regex = try Regex.compile(allocator, "a*");
33 var regex = try Regex.compile(init.gpa, "a*");
3834 defer regex.deinit();
3935
4036 std.debug.print(" '' matches: {}\n", .{try regex.isMatch("")});
renamed throughout · 14 hidden lines
Changes to examples/basic.zig
@@ -46,12 +42,12 @@ pub fn main() !void { renamed throughout
4642 // Example 4: Finding matches
4743 {
4844 std.debug.print("Example 4: Finding matches\n", .{});
49 var regex = try Regex.compile(allocator, "world");
45 var regex = try Regex.compile(init.gpa, "world");
5046 defer regex.deinit();
5147
5248 if (try regex.find("hello world")) |match_result| {
5349 var mut_match = match_result;
54 defer mut_match.deinit(allocator);
50 defer mut_match.deinit(init.gpa);
5551 std.debug.print(" Found '{s}' at position {d}-{d}\n", .{ match_result.slice, match_result.start, match_result.end });
5652 }
5753 std.debug.print("\n", .{});
renamed throughout · 14 hidden lines
Changes to examples/basic.zig
@@ -60,11 +56,11 @@ pub fn main() !void { renamed throughout
6056 // Example 5: Replace
6157 {
6258 std.debug.print("Example 5: Replace\n", .{});
63 var regex = try Regex.compile(allocator, "world");
59 var regex = try Regex.compile(init.gpa, "world");
6460 defer regex.deinit();
6561
66 const result = try regex.replace(allocator, "hello world", "Zig");
67 defer allocator.free(result);
62 const result = try regex.replace(init.gpa, "hello world", "Zig");
63 defer init.gpa.free(result);
6864
6965 std.debug.print(" Replaced: '{s}'\n", .{result});
7066 std.debug.print("\n", .{});