Skip to content

Commit 3b90e54

Browse files
committed
Simplify NeedsEscaping
1 parent b3ec140 commit 3b90e54

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,14 @@ Expected<std::string> StringSubstitution::getResultForDiagnostics() const {
304304

305305
OS << '"';
306306
// Escape the string if it contains any characters that
307-
// make it hard to read, such as tabs, newlines, quotes, and non-printable
308-
// characters. These are the characters that are escaped by write_escaped(),
309-
// except we do not include backslashes, because they are
310-
// common in Windows paths and escaping them would make the output
311-
// harder to read.
312-
// However, when we do escape, backslashes are escaped as well,
313-
// otherwise the output would be ambiguous.
314-
const bool NeedsEscaping = llvm::any_of(*VarVal, [](char C) {
315-
return C == '\t' || C == '\n' || C == '"' || !isPrint(C);
316-
});
307+
// make it hard to read, such as non-printable characters (including all
308+
// whitespace except space) and double quotes. These are the characters that
309+
// are escaped by write_escaped(), except we do not include backslashes,
310+
// because they are common in Windows paths and escaping them would make the
311+
// output harder to read. However, when we do escape, backslashes are escaped
312+
// as well, otherwise the output would be ambiguous.
313+
const bool NeedsEscaping =
314+
llvm::any_of(*VarVal, [](char C) { return !isPrint(C) || C == '"'; });
317315
if (NeedsEscaping)
318316
OS.write_escaped(*VarVal);
319317
else

0 commit comments

Comments
 (0)