authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-23 00:58:39 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-23 00:58:39 -07:00
log4158c34719217a07146114c12550dbec7d464fab
tree48e8c1bf953182045d54e5e4a609383be44004c4
parentd365a0cfdce7bd88d15feb9be887cdfca2c82b31

add trimByte


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

intrusive_parser.zig+16
......@@ -104,6 +104,18 @@ pub const Parser = struct {
104104 return p.slice()[0..n].*;
105105 }
106106
107 pub fn trimByte(p: *Parser, test_c: u8) !usize {
108 var amt: usize = 0;
109 while (true) {
110 const s = p.slice();
111 if (s.len == 0) break;
112 if (s[0] != test_c) break;
113 p.idx += 1;
114 amt += 1;
115 }
116 return amt;
117 }
118
107119 // tag(u8) + len(u32) + bytes(N)
108120 pub fn addStr(p: *Parser, alloc: std.mem.Allocator, str: string) !usize {
109121 const adapter: AdapterStr = .{ .p = p };
......@@ -177,5 +189,9 @@ pub fn Mixin(comptime T: type) type {
177189 pub fn shiftBytesN(pp: *T, comptime n: usize) ![n]u8 {
178190 return pp.parser.shiftBytesN(n);
179191 }
192
193 pub fn trimByte(pp: *T, test_c: u8) !usize {
194 return pp.parser.trimByte(test_c);
195 }
180196 };
181197}