This revision was automatically updated to reflect the committed changes. Closed by commit rG587859d977e8: clang-format: use `pb` as a canonical raw string delimiter for google style (authored by krasimir).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97688/new/ https://reviews.llvm.org/D97688 Files: clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/Format.cpp clang/unittests/Format/FormatTestRawStrings.cpp Index: clang/unittests/Format/FormatTestRawStrings.cpp =================================================================== --- clang/unittests/Format/FormatTestRawStrings.cpp +++ clang/unittests/Format/FormatTestRawStrings.cpp @@ -782,11 +782,16 @@ } TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) { - FormatStyle Style = getRawStringPbStyleWithColumns(25); + FormatStyle Style = getRawStringPbStyleWithColumns(35); Style.RawStringFormats[0].CanonicalDelimiter = "proto"; + Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO"); + expect_eq(R"test(a = R"proto(key: value)proto";)test", format(R"test(a = R"pb(key:value)pb";)test", Style)); + expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test", + format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style)); + // Don't update to canonical delimiter if it occurs as a raw string suffix in // the raw string content. expect_eq(R"test(a = R"pb(key: ")proto")pb";)test", Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1137,7 +1137,7 @@ "ParseTestProto", "ParsePartialTestProto", }, - /*CanonicalDelimiter=*/"", + /*CanonicalDelimiter=*/"pb", /*BasedOnStyle=*/"google", }, }; Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1651,7 +1651,7 @@ StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText); StringRef NewDelimiter = getCanonicalRawStringDelimiter(Style, RawStringStyle.Language); - if (NewDelimiter.empty() || OldDelimiter.empty()) + if (NewDelimiter.empty()) NewDelimiter = OldDelimiter; // The text of a raw string is between the leading 'R"delimiter(' and the // trailing 'delimiter)"'.
Index: clang/unittests/Format/FormatTestRawStrings.cpp =================================================================== --- clang/unittests/Format/FormatTestRawStrings.cpp +++ clang/unittests/Format/FormatTestRawStrings.cpp @@ -782,11 +782,16 @@ } TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) { - FormatStyle Style = getRawStringPbStyleWithColumns(25); + FormatStyle Style = getRawStringPbStyleWithColumns(35); Style.RawStringFormats[0].CanonicalDelimiter = "proto"; + Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO"); + expect_eq(R"test(a = R"proto(key: value)proto";)test", format(R"test(a = R"pb(key:value)pb";)test", Style)); + expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test", + format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style)); + // Don't update to canonical delimiter if it occurs as a raw string suffix in // the raw string content. expect_eq(R"test(a = R"pb(key: ")proto")pb";)test", Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1137,7 +1137,7 @@ "ParseTestProto", "ParsePartialTestProto", }, - /*CanonicalDelimiter=*/"", + /*CanonicalDelimiter=*/"pb", /*BasedOnStyle=*/"google", }, }; Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1651,7 +1651,7 @@ StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText); StringRef NewDelimiter = getCanonicalRawStringDelimiter(Style, RawStringStyle.Language); - if (NewDelimiter.empty() || OldDelimiter.empty()) + if (NewDelimiter.empty()) NewDelimiter = OldDelimiter; // The text of a raw string is between the leading 'R"delimiter(' and the // trailing 'delimiter)"'.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits