diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-02-28 19:05:45 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-02-28 19:05:45 +1100 |
| commit | 068af3d9d4d7fd8f442ec365d3c9f6a3c02c64a7 (patch) | |
| tree | 7f8ae51a7a51cc29db838475f04ebf56d251f901 /src | |
| parent | 3d5a0c672e6f3cf87944b33712e17531aa42c607 (diff) | |
Use std::find when detecting end of line format
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer_utils.cc | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index effb7cc7..76910483 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -132,13 +132,9 @@ decltype(auto) parse_file(StringView filename, Func&& func) } bool has_crlf = false, has_lf = false; - for (auto it = pos; it != end; ++it) - { - if (*it == '\n') - ((it != pos and *(it-1) == '\r') ? has_crlf : has_lf) = true; - } - const bool crlf = has_crlf and not has_lf; - auto eolformat = crlf ? EolFormat::Crlf : EolFormat::Lf; + for (auto it = std::find(pos, end, '\n'); it != end; it = std::find(it+1, end, '\n')) + ((it != pos and *(it-1) == '\r') ? has_crlf : has_lf) = true; + auto eolformat = (has_crlf and not has_lf) ? EolFormat::Crlf : EolFormat::Lf; FsStatus fs_status{file.st.st_mtim, file.st.st_size, murmur3(file.data, file.st.st_size)}; return func(parse_lines(pos, end, eolformat), bom, eolformat, fs_status); |
