Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created November 12, 2009 19:03
Show Gist options
  • Save stepancheg/233188 to your computer and use it in GitHub Desktop.
Save stepancheg/233188 to your computer and use it in GitHub Desktop.
size_t find_newline(const char* ptr, size_t len) {
size_t i = 0;
while (i < len) {
if (ptr[i] == '\n')
return i + 1;
if (ptr[i] == '\r') {
if (i + 1 < len && ptr[i + 1] == '\n')
return i + 2;
else
return i + 1;
}
++i;
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment