| ... | @@ -305,3 +305,21 @@ pub fn detct_mainfile(override: []const u8, dir: ?std.fs.Dir, name: []const u8) | ... | @@ -305,3 +305,21 @@ pub fn detct_mainfile(override: []const u8, dir: ?std.fs.Dir, name: []const u8) |
| 305 | } | 305 | } |
| 306 | return error.CantFindMain; | 306 | return error.CantFindMain; |
| 307 | } | 307 | } |
| | 308 | |
| | 309 | pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize { |
| | 310 | var i: usize = 0; |
| | 311 | var c: usize = 0; |
| | 312 | while (c < n) { |
| | 313 | i = indexOfAfter(haystack, needle, i) orelse return null; |
| | 314 | c += 1; |
| | 315 | } |
| | 316 | return i; |
| | 317 | } |
| | 318 | |
| | 319 | pub fn indexOfAfter(haystack: []const u8, needle: u8, after: usize) ?usize { |
| | 320 | for (haystack) |c, i| { |
| | 321 | if (i <= after) continue; |
| | 322 | if (c == needle) return i; |
| | 323 | } |
| | 324 | return null; |
| | 325 | } |