-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the MTL parser for the more general streaming API
This was straightforward, just had to be more careful with memory since it has to dupe strings out of the input stream.
- Loading branch information
Showing
4 changed files
with
155 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const std = @import("std"); | ||
|
||
pub fn LineIterator(comptime Reader: type) type { | ||
return struct { | ||
buffer: []u8, | ||
reader: Reader, | ||
|
||
pub fn next(self: *@This()) !?[]const u8 { | ||
var fbs = std.io.fixedBufferStream(self.buffer); | ||
self.reader.streamUntilDelimiter( | ||
fbs.writer(), | ||
'\n', | ||
fbs.buffer.len, | ||
) catch |err| switch (err) { | ||
error.EndOfStream => if (fbs.getWritten().len == 0) return null, | ||
else => |e| return e, | ||
}; | ||
var line = fbs.getWritten(); | ||
if (0 < line.len and line[line.len - 1] == '\r') | ||
line = line[0 .. line.len - 1]; | ||
return line; | ||
} | ||
}; | ||
} | ||
|
||
pub fn lineIterator(rdr: anytype, buffer: []u8) LineIterator(@TypeOf(rdr)) { | ||
return .{ .buffer = buffer, .reader = rdr }; | ||
} |