also looking at this
Migrate to zig 0.16
#5
13 files
+222
-239
| @@ -1,17 +1,13 @@ | ||
| 1 | 1 | const std = ; |
| 2 | 2 | const Regex = .Regex; |
| 3 | 3 | |
| 4 | pub fn main() !void { | |
| 5 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| 6 | defer _ = gpa.deinit(); | |
| 7 | const allocator = gpa.allocator(); | |
| 8 | ||
| 4 | pub fn main(init: std.process.Init) !void { | |
| 9 | 5 | std.debug.print("\n=== Zig Regex Examples ===\n\n", .{}); |
| 10 | 6 | |
| 11 | 7 | // Example 1: Simple literal matching |
| 12 | 8 | { |
| 13 | 9 | 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"); | |
| 15 | 11 | defer regex.deinit(); |
| 16 | 12 | |
| 17 | 13 | const matches = try regex.isMatch("hello"); |
| @@ -22,7 +18,7 @@ pub fn main() !void { | ||
| 22 | 18 | // Example 2: Alternation |
| 23 | 19 | { |
| 24 | 20 | 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"); | |
| 26 | 22 | defer regex.deinit(); |
| 27 | 23 | |
| 28 | 24 | std.debug.print(" 'cat' matches: {}\n", .{try regex.isMatch("cat")}); |
| @@ -34,7 +30,7 @@ pub fn main() !void { | ||
| 34 | 30 | // Example 3: Star quantifier |
| 35 | 31 | { |
| 36 | 32 | 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*"); | |
| 38 | 34 | defer regex.deinit(); |
| 39 | 35 | |
| 40 | 36 | std.debug.print(" '' matches: {}\n", .{try regex.isMatch("")}); |
renamed throughout · 14 hidden lines
| @@ -46,12 +42,12 @@ pub fn main() !void { renamed throughout | ||
| 46 | 42 | // Example 4: Finding matches |
| 47 | 43 | { |
| 48 | 44 | 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"); | |
| 50 | 46 | defer regex.deinit(); |
| 51 | 47 | |
| 52 | 48 | if (try regex.find("hello world")) |match_result| { |
| 53 | 49 | var mut_match = match_result; |
| 54 | defer mut_match.deinit(allocator); | |
| 50 | defer mut_match.deinit(init.gpa); | |
| 55 | 51 | std.debug.print(" Found '{s}' at position {d}-{d}\n", .{ match_result.slice, match_result.start, match_result.end }); |
| 56 | 52 | } |
| 57 | 53 | std.debug.print("\n", .{}); |
renamed throughout · 14 hidden lines
| @@ -60,11 +56,11 @@ pub fn main() !void { renamed throughout | ||
| 60 | 56 | // Example 5: Replace |
| 61 | 57 | { |
| 62 | 58 | std.debug.print("Example 5: Replace\n", .{}); |
| 63 | var regex = try Regex.compile(allocator, "world"); | |
| 59 | var regex = try Regex.compile(init.gpa, "world"); | |
| 64 | 60 | defer regex.deinit(); |
| 65 | 61 | |
| 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); | |
| 68 | 64 | |
| 69 | 65 | std.debug.print(" Replaced: '{s}'\n", .{result}); |
| 70 | 66 | std.debug.print("\n", .{}); |