[PATCH] D39279: Stringizing raw string literals containing newline
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 15:54:31 PST 2017
vsapsai added a comment.
On the first glance string erase and insert seem to be done correctly. But we can still improve the tests. Can you please add tests for tricky cases where new line or backslash appear in unexpected places? Some of the examples are
R"ab\
cd"
R"ab
c"
R"ab
\"
R"ab
\\"
I didn't check if all of them are valid but I hope you got the idea.
================
Comment at: lib/Lex/Lexer.cpp:223
+ ++e;
+ } else if (auto Size = getEscapedNewLineSize(Result.substr(i).data())) {
+ Result.erase(Result.begin() + i, Result.begin() + i + Size);
----------------
`getEscapedNewLineSize` mentions
> P[-1] is known to be a "\" or a trigraph equivalent on entry to this function.
Is this precondition correct in this case?
And `std::string::substr` creates a copy of a substring. It is inefficient in the loop and looks like you don't really need `std::string` here anyway.
https://reviews.llvm.org/D39279
More information about the cfe-commits
mailing list