[clang] 587859d - clang-format: use `pb` as a canonical raw string delimiter for google style
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 9 00:07:58 PST 2021
Author: Krasimir Georgiev
Date: 2021-03-09T09:07:14+01:00
New Revision: 587859d977e88648bee1888dce5175ef827f212e
URL: https://github.com/llvm/llvm-project/commit/587859d977e88648bee1888dce5175ef827f212e
DIFF: https://github.com/llvm/llvm-project/commit/587859d977e88648bee1888dce5175ef827f212e.diff
LOG: clang-format: use `pb` as a canonical raw string delimiter for google style
This updates the canonical text proto raw string delimiter to `pb` for Google style, moving codebases towards a simpler and more consistent style.
Also updates a behavior where the canonical delimiter was not applied for raw strings with empty delimiters detected via well-known enclosing functions that expect a text proto, effectively making the canonical delimiter more viral. This feature is not widely used so this should be safe and more in line with promoting the canonicity of the canonical delimiter.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D97688
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTestRawStrings.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index ffb328f7de13..cbf016f4b166 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1651,7 +1651,7 @@ unsigned ContinuationIndenter::reformatRawStringLiteral(
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)"'.
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 674f3e1220f7..120202caa3cd 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1137,7 +1137,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
"ParseTestProto",
"ParsePartialTestProto",
},
- /*CanonicalDelimiter=*/"",
+ /*CanonicalDelimiter=*/"pb",
/*BasedOnStyle=*/"google",
},
};
diff --git a/clang/unittests/Format/FormatTestRawStrings.cpp b/clang/unittests/Format/FormatTestRawStrings.cpp
index 6310fe510fd3..6f9a0d650ba2 100644
--- a/clang/unittests/Format/FormatTestRawStrings.cpp
+++ b/clang/unittests/Format/FormatTestRawStrings.cpp
@@ -782,11 +782,16 @@ a = ParseTextProto<ProtoType>(R"(key:value)");)test",
}
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",
More information about the cfe-commits
mailing list