@@ -276,7 +276,8 @@ Expected<std::string> NumericSubstitution::getResultRegex() const {
276276
277277Expected<std::string> NumericSubstitution::getResultForDiagnostics () const {
278278 // The "regex" returned by getResultRegex() is just a numeric value
279- // like '42', '0x2A', '-17', 'DEADBEEF' etc. This is already suitable for use in diagnostics.
279+ // like '42', '0x2A', '-17', 'DEADBEEF' etc. This is already suitable for use
280+ // in diagnostics.
280281 Expected<std::string> Literal = getResultRegex ();
281282 if (!Literal)
282283 return Literal;
@@ -293,35 +294,35 @@ Expected<std::string> StringSubstitution::getResultRegex() const {
293294}
294295
295296Expected<std::string> StringSubstitution::getResultForDiagnostics () const {
296- Expected<StringRef> VarVal = Context->getPatternVarValue (FromStr);
297- if (!VarVal)
298- return VarVal.takeError ();
299-
300- std::string Result;
301- Result.reserve (VarVal->size () + 2 );
302- raw_string_ostream OS (Result);
303-
304- OS << ' "' ;
305- // Escape the string if it contains any characters that
306- // make it hard to read, such as tabs, newlines, quotes, and non-printable characters.
307- // These are the characters that are escaped by write_escaped(),
308- // except we do not include backslashes, because they are
309- // common in Windows paths and escaping them would make the output
310- // harder to read.
311- // However, when we do escape, backslashes are escaped as well,
312- // otherwise the output would be ambiguous.
313- const bool NeedsEscaping = llvm::any_of (*VarVal, [](char C) {
314- return C == ' \t ' || C == ' \n ' || C == ' "' || !isPrint (C);
315- });
316- if (NeedsEscaping)
317- OS.write_escaped (*VarVal);
318- else
319- OS << *VarVal;
320- OS << ' "' ;
321- if (NeedsEscaping)
322- OS << " (escaped value)" ;
323-
324- return Result;
297+ Expected<StringRef> VarVal = Context->getPatternVarValue (FromStr);
298+ if (!VarVal)
299+ return VarVal.takeError ();
300+
301+ std::string Result;
302+ Result.reserve (VarVal->size () + 2 );
303+ raw_string_ostream OS (Result);
304+
305+ OS << ' "' ;
306+ // 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+ });
317+ if (NeedsEscaping)
318+ OS.write_escaped (*VarVal);
319+ else
320+ OS << *VarVal;
321+ OS << ' "' ;
322+ if (NeedsEscaping)
323+ OS << " (escaped value)" ;
324+
325+ return Result;
325326}
326327
327328bool Pattern::isValidVarNameStart (char C) { return C == ' _' || isAlpha (C); }
@@ -1252,7 +1253,8 @@ void Pattern::printSubstitutions(const SourceMgr &SM, StringRef Buffer,
12521253 SmallString<256 > Msg;
12531254 raw_svector_ostream OS (Msg);
12541255
1255- Expected<std::string> MatchedValue = Substitution->getResultForDiagnostics ();
1256+ Expected<std::string> MatchedValue =
1257+ Substitution->getResultForDiagnostics ();
12561258 // Substitution failures are handled in printNoMatch().
12571259 if (!MatchedValue) {
12581260 consumeError (MatchedValue.takeError ());
0 commit comments