extract windowsSafe()
This commit is contained in:
parent
3b4c64eaa5
commit
3c2e69d5d6
1 changed files with 12 additions and 4 deletions
16
src/main.zig
16
src/main.zig
|
@ -41,13 +41,21 @@ fn nextLine(reader: FileReader, buffer: []u8) !?[]const u8 {
|
||||||
buffer,
|
buffer,
|
||||||
'\n',
|
'\n',
|
||||||
)) orelse return null;
|
)) orelse return null;
|
||||||
// trim annoying windows-only carriage return character
|
return windowsSafe(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim annoying windows-only carriage return character
|
||||||
|
fn windowsSafe(line: []u8) []u8 {
|
||||||
if (os.tag == .windows) {
|
if (os.tag == .windows) {
|
||||||
line = mem.trimRight(u8, line, "\r");
|
return mem.trimRight(u8, line, "\r");
|
||||||
}
|
}
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
test "basic test" {
|
test "windowsSage strips carriage return on windows" {
|
||||||
try testing.expectEqual(10, 3 + 7);
|
if (os.tag == .windows) {
|
||||||
|
try testing.expectEqualSlices(u8, "line\n\r", "line\n");
|
||||||
|
} else {
|
||||||
|
try testing.expectEqualSlices(u8, "line\n\r", "line\n\r");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue