Skip to content

Instantly share code, notes, and snippets.

@dg-nvm
dg-nvm / file.c
Created October 25, 2019 08:17
Finding line endings algo
for (i = 0; i < ulen; i++) {
if (ubuf[i] == '\r' && (i + 1 < ulen && ubuf[i + 1] == '\n')) {
n_crlf++;
last_line_end = i;
}
if (ubuf[i] == '\r' && (i + 1 >= ulen || ubuf[i + 1] != '\n')) {
n_cr++;
last_line_end = i;
}
if (ubuf[i] == '\n' && ((int)i - 1 < 0 || ubuf[i - 1] != '\r')){