8c9b844c
refactor: documented scans with indexOfPos, not a hand-rolled window
a73x 2026-08-27 08:09
Commit message
src/cli/flags.zig
| Old | New | ||
|---|---|---|---|
| @@ -156,11 +156,9 @@ pub fn flagName(comptime field: []const u8) []const u8 { | |||
| 156 | /// A flag is named only where the word ENDS: `--sock` must not be answered | 156 | /// A flag is named only where the word ENDS: `--sock` must not be answered |
| 157 | /// by prose that says `--socket`. | 157 | /// by prose that says `--socket`. |
| 158 | pub fn documented(name: []const u8, usage: []const u8) bool { | 158 | pub fn documented(name: []const u8, usage: []const u8) bool { |
| 159 | if (name.len == 0 or usage.len < name.len) return false; | ||
| 160 | var at: usize = 0; | 159 | var at: usize = 0; |
| 161 | while (at + name.len <= usage.len) : (at += 1) { | 160 | while (std.mem.indexOfPos(u8, usage, at, name)) |i| : (at = i + 1) { |
| 162 | if (!std.mem.eql(u8, usage[at..][0..name.len], name)) continue; | 161 | const end = i + name.len; |
| 163 | const end = at + name.len; | ||
| 164 | if (end == usage.len) return true; | 162 | if (end == usage.len) return true; |
| 165 | switch (usage[end]) { | 163 | switch (usage[end]) { |
| 166 | ' ', '\n', ']' => return true, | 164 | ' ', '\n', ']' => return true, |