authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-24 04:12:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-24 04:12:07 -07:00
loga0b32e3f7a6571c509c4b2c48c8d56a24d082f5e
tree253015ce1a86cbbc5f2ae2cb395b0d9e6b8dda9c
parent8a90c3f231d442e4f6a75dd2d2fc74c000267a8a

add eatUntilStr for multi-byte eatUntil


1 files changed, 20 insertions(+), 0 deletions(-)

intrusive_parser.zig+20
......@@ -132,6 +132,22 @@ pub const Parser = struct {
132132 }
133133 }
134134
135 pub fn eatUntilStr(p: *Parser, test_s: []const u8) !?[2]usize {
136 const start = p.idx;
137 while (true) {
138 try p.peekAmt(1) orelse return null;
139 const amt = std.mem.indexOf(u8, p.slice(), test_s) orelse {
140 const left = p.avail();
141 p.idx += left;
142 continue;
143 };
144 p.idx += amt;
145 p.idx += test_s.len;
146 const end = p.idx;
147 return .{ start, end };
148 }
149 }
150
135151 // tag(u8) + len(u32) + bytes(N)
136152 pub fn addStr(p: *Parser, alloc: std.mem.Allocator, str: string) !usize {
137153 const adapter: AdapterStr = .{ .p = p };
......@@ -213,5 +229,9 @@ pub fn Mixin(comptime T: type) type {
213229 pub fn eatUntil(pp: *T, test_c: u8) !?[2]usize {
214230 return pp.parser.eatUntil(test_c);
215231 }
232
233 pub fn eatUntilStr(pp: *T, test_s: []const u8) !?[2]usize {
234 return pp.parser.eatUntilStr(test_s);
235 }
216236 };
217237}