Refactoring
This commit is contained in:
parent
7a56c8a662
commit
cc351d68ba
1 changed files with 13 additions and 13 deletions
26
src/main.zig
26
src/main.zig
|
@ -35,6 +35,19 @@ fn dumpInput(in: fs.File, out: fs.File, allocator: mem.Allocator) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LineIterator = struct {
|
||||||
|
reader: io.BufferedReader(4096, fs.File.Reader),
|
||||||
|
delimiter: u8,
|
||||||
|
allocator: mem.Allocator,
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
/// Caller owns returned memory
|
||||||
|
pub fn next(self: *Self) ?[]u8 {
|
||||||
|
return self.reader.reader().readUntilDelimiterOrEofAlloc(self.allocator, self.delimiter, 4096) catch null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
fn lineIterator(reader: fs.File.Reader, allocator: mem.Allocator) LineIterator {
|
fn lineIterator(reader: fs.File.Reader, allocator: mem.Allocator) LineIterator {
|
||||||
return LineIterator {
|
return LineIterator {
|
||||||
.reader = io.bufferedReader(reader),
|
.reader = io.bufferedReader(reader),
|
||||||
|
@ -62,19 +75,6 @@ test "lineIterator returns lines in buffer" {
|
||||||
try testing.expect(eof == null);
|
try testing.expect(eof == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const LineIterator = struct {
|
|
||||||
reader: io.BufferedReader(4096, fs.File.Reader),
|
|
||||||
delimiter: u8,
|
|
||||||
allocator: mem.Allocator,
|
|
||||||
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
/// Caller owns returned memory
|
|
||||||
pub fn next(self: *Self) ?[]u8 {
|
|
||||||
return self.reader.reader().readUntilDelimiterOrEofAlloc(self.allocator, self.delimiter, 4096) catch null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// trim annoying windows-only carriage return character
|
// trim annoying windows-only carriage return character
|
||||||
fn windowsSafe(line: []const u8) []const u8 {
|
fn windowsSafe(line: []const u8) []const u8 {
|
||||||
if (os.tag == .windows) {
|
if (os.tag == .windows) {
|
||||||
|
|
Loading…
Reference in a new issue