The line separator on Unix is \n
and on Windows is the sequence \r\n
. It is common to find files on any system with both separators; handling both of them on all systems as separators is beneficial for any program.
The easiest solution I can think is to reduce the slice size by one if the last character is a \r
.
var slice: []u8 = try readUntilDelimiterOrEofAlloc(...).?;
const len = slice.len;
if (slice[len - 1] == '\r') {
slice = slice[0..(len - 1)];
}