also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
formatting only · 7 hidden lines
| @@ -49,6 +49,7 @@ pub const Match = struct { formatting only | ||
| 49 | 49 | ``` |
| 50 | 50 | |
| 51 | 51 | **Methods:** |
| 52 | ||
| 52 | 53 | - `deinit(allocator: std.mem.Allocator)` - Free capture group memory |
| 53 | 54 | |
| 54 | 55 | --- |
| @@ -64,12 +65,14 @@ pub fn compile(allocator: std.mem.Allocator, pattern: []const u8) !Regex | ||
| 64 | 65 | ``` |
| 65 | 66 | |
| 66 | 67 | **Parameters:** |
| 68 | ||
| 67 | 69 | - `allocator` - Memory allocator for the regex and its internal structures |
| 68 | 70 | - `pattern` - The regex pattern string |
| 69 | 71 | |
| 70 | 72 | **Returns:** `Regex` or error |
| 71 | 73 | |
| 72 | 74 | **Errors:** |
| 75 | ||
| 73 | 76 | - `RegexError.EmptyPattern` - Pattern string is empty |
| 74 | 77 | - `RegexError.InvalidPattern` - Syntax error in pattern |
| 75 | 78 | - `RegexError.UnexpectedCharacter` - Invalid character in pattern |
formatting only · 7 hidden lines
| @@ -80,6 +83,7 @@ pub fn compile(allocator: std.mem.Allocator, pattern: []const u8) !Regex formatting only | ||
| 80 | 83 | - `RegexError.UnmatchedBracket` - Unbalanced brackets |
| 81 | 84 | |
| 82 | 85 | **Example:** |
| 86 | ||
| 83 | 87 | ```zig |
| 84 | 88 | const allocator = std.heap.page_allocator; |
| 85 | 89 | var regex = try Regex.compile(allocator, "\\d{3}-\\d{4}"); |
formatting only · 7 hidden lines
| @@ -99,6 +103,7 @@ pub fn compileWithFlags( formatting only | ||
| 99 | 103 | ``` |
| 100 | 104 | |
| 101 | 105 | **Parameters:** |
| 106 | ||
| 102 | 107 | - `allocator` - Memory allocator |
| 103 | 108 | - `pattern` - The regex pattern string |
| 104 | 109 | - `flags` - Compilation flags (see [Flags](#flags)) |
formatting only · 7 hidden lines
| @@ -106,6 +111,7 @@ pub fn compileWithFlags( formatting only | ||
| 106 | 111 | **Returns:** `Regex` or error |
| 107 | 112 | |
| 108 | 113 | **Example:** |
| 114 | ||
| 109 | 115 | ```zig |
| 110 | 116 | var regex = try Regex.compileWithFlags( |
| 111 | 117 | allocator, |
formatting only · 7 hidden lines
| @@ -124,6 +130,7 @@ pub fn deinit(self: *Regex) void formatting only | ||
| 124 | 130 | ``` |
| 125 | 131 | |
| 126 | 132 | **Example:** |
| 133 | ||
| 127 | 134 | ```zig |
| 128 | 135 | var regex = try Regex.compile(allocator, "pattern"); |
| 129 | 136 | defer regex.deinit(); // Always call deinit when done |
| @@ -142,11 +149,13 @@ pub fn isMatch(self: *const Regex, input: []const u8) !bool | ||
| 142 | 149 | ``` |
| 143 | 150 | |
| 144 | 151 | **Parameters:** |
| 152 | ||
| 145 | 153 | - `input` - The string to search in |
| 146 | 154 | |
| 147 | 155 | **Returns:** `true` if match found, `false` otherwise |
| 148 | 156 | |
| 149 | 157 | **Example:** |
| 158 | ||
| 150 | 159 | ```zig |
| 151 | 160 | var regex = try Regex.compile(allocator, "\\d+"); |
| 152 | 161 | defer regex.deinit(); |
| @@ -169,11 +178,13 @@ pub fn find(self: *const Regex, input: []const u8) !?Match | ||
| 169 | 178 | ``` |
| 170 | 179 | |
| 171 | 180 | **Parameters:** |
| 181 | ||
| 172 | 182 | - `input` - The string to search in |
| 173 | 183 | |
| 174 | 184 | **Returns:** `Match` if found, `null` otherwise |
| 175 | 185 | |
| 176 | 186 | **Example:** |
| 187 | ||
| 177 | 188 | ```zig |
| 178 | 189 | var regex = try Regex.compile(allocator, "\\d+"); |
| 179 | 190 | defer regex.deinit(); |
| @@ -200,12 +211,14 @@ pub fn findAll( | ||
| 200 | 211 | ``` |
| 201 | 212 | |
| 202 | 213 | **Parameters:** |
| 214 | ||
| 203 | 215 | - `allocator` - Allocator for the results array |
| 204 | 216 | - `input` - The string to search in |
| 205 | 217 | |
| 206 | 218 | **Returns:** Array of `Match` objects (caller owns, must free) |
| 207 | 219 | |
| 208 | 220 | **Example:** |
| 221 | ||
| 209 | 222 | ```zig |
| 210 | 223 | var regex = try Regex.compile(allocator, "\\d+"); |
| 211 | 224 | defer regex.deinit(); |
formatting only · 7 hidden lines
| @@ -247,6 +260,7 @@ pub fn replace( formatting only | ||
| 247 | 260 | ``` |
| 248 | 261 | |
| 249 | 262 | **Parameters:** |
| 263 | ||
| 250 | 264 | - `allocator` - Allocator for the result string |
| 251 | 265 | - `input` - The input string |
| 252 | 266 | - `replacement` - The replacement string |
formatting only · 7 hidden lines
| @@ -254,6 +268,7 @@ pub fn replace( formatting only | ||
| 254 | 268 | **Returns:** New string with first match replaced (caller owns, must free) |
| 255 | 269 | |
| 256 | 270 | **Example:** |
| 271 | ||
| 257 | 272 | ```zig |
| 258 | 273 | var regex = try Regex.compile(allocator, "\\d+"); |
| 259 | 274 | defer regex.deinit(); |
formatting only · 7 hidden lines
| @@ -278,6 +293,7 @@ pub fn replaceAll( formatting only | ||
| 278 | 293 | ``` |
| 279 | 294 | |
| 280 | 295 | **Parameters:** |
| 296 | ||
| 281 | 297 | - `allocator` - Allocator for the result string |
| 282 | 298 | - `input` - The input string |
| 283 | 299 | - `replacement` - The replacement string |
formatting only · 7 hidden lines
| @@ -285,6 +301,7 @@ pub fn replaceAll( formatting only | ||
| 285 | 301 | **Returns:** New string with all matches replaced (caller owns, must free) |
| 286 | 302 | |
| 287 | 303 | **Example:** |
| 304 | ||
| 288 | 305 | ```zig |
| 289 | 306 | var regex = try Regex.compile(allocator, "\\d+"); |
| 290 | 307 | defer regex.deinit(); |
| @@ -312,12 +329,14 @@ pub fn split( | ||
| 312 | 329 | ``` |
| 313 | 330 | |
| 314 | 331 | **Parameters:** |
| 332 | ||
| 315 | 333 | - `allocator` - Allocator for the results array |
| 316 | 334 | - `input` - The string to split |
| 317 | 335 | |
| 318 | 336 | **Returns:** Array of string slices (caller owns array, must free) |
| 319 | 337 | |
| 320 | 338 | **Example:** |
| 339 | ||
| 321 | 340 | ```zig |
| 322 | 341 | var regex = try Regex.compile(allocator, ","); |
| 323 | 342 | defer regex.deinit(); |
formatting only · 7 hidden lines
| @@ -357,6 +376,7 @@ pub const CompileFlags = packed struct { formatting only | ||
| 357 | 376 | When `true`, the pattern matches both uppercase and lowercase letters. |
| 358 | 377 | |
| 359 | 378 | **Example:** |
| 379 | ||
| 360 | 380 | ```zig |
| 361 | 381 | var regex = try Regex.compileWithFlags( |
| 362 | 382 | allocator, |