[PATCH] D68227: [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 30 13:09:35 PDT 2019
krasimir added inline comments.
================
Comment at: clang/lib/Format/Format.cpp:1891
+ if (compareIgnoringCarriageReturns(
+ result, Code.substr(IncludesBeginOffset, IncludesBlockSize)))
return;
----------------
Here `compartIgnoringCarriageReturns` is a bit imprecise: there could be `\r`-s not followed by `\n`-s in the source code.
Since we have constructed `result` with newlines as `\n`-s in this code, I'd suggest to instead implement a function that replaces all occurrences of `\r\n` with `\n` in a string (something like "stripNewlineCRs") and have a comparison like `result == stripNewlineCRs(...)` here. That shouldn't be much harder than this approach and will be a bit more precise.
I've looked around the Format code for preexisting functionality we can reuse, but it seems most of the `\r\n` handling is concerned with outputting the right newline encoding and not with reading it.
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68227/new/
https://reviews.llvm.org/D68227
More information about the cfe-commits
mailing list