aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-12-25 22:36:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:44:01 +0000
commit0eae32dcef82f6f06de6419a0d623d7def0cc8f6 (patch)
tree55b7e05be47b835fd137915bee1e64026c35e71c /contrib/llvm-project/clang/lib/Format/Format.cpp
parent4824e7fd18a1223177218d4aec1b3c6c5c4a444e (diff)
parent77fc4c146f0870ffb09c1afb823ccbe742c5e6ff (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/Format/Format.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Format/Format.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/contrib/llvm-project/clang/lib/Format/Format.cpp b/contrib/llvm-project/clang/lib/Format/Format.cpp
index 17de1075aeaa..be01daa38929 100644
--- a/contrib/llvm-project/clang/lib/Format/Format.cpp
+++ b/contrib/llvm-project/clang/lib/Format/Format.cpp
@@ -2586,12 +2586,31 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code,
bool MainIncludeFound = false;
bool FormattingOff = false;
+ llvm::Regex RawStringRegex(
+ "R\"(([\\[A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'\\-]|])*)\\(");
+ SmallVector<StringRef, 2> RawStringMatches;
+ std::string RawStringTermination = ")\"";
+
for (;;) {
auto Pos = Code.find('\n', SearchFrom);
StringRef Line =
Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
StringRef Trimmed = Line.trim();
+
+ // #includes inside raw string literals need to be ignored.
+ // or we will sort the contents of the string.
+ // Skip past until we think we are at the rawstring literal close.
+ if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
+ std::string CharSequence = RawStringMatches[1].str();
+ RawStringTermination = ")" + CharSequence + "\"";
+ FormattingOff = true;
+ }
+
+ if (Trimmed.contains(RawStringTermination)) {
+ FormattingOff = false;
+ }
+
if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off */")
FormattingOff = true;
else if (Trimmed == "// clang-format on" ||
@@ -3031,8 +3050,7 @@ reformat(const FormatStyle &Style, StringRef Code,
});
}
- if (Style.Language == FormatStyle::LK_JavaScript &&
- Style.JavaScriptQuotes != FormatStyle::JSQS_Leave)
+ if (Style.isJavaScript() && Style.JavaScriptQuotes != FormatStyle::JSQS_Leave)
Passes.emplace_back([&](const Environment &Env) {
return JavaScriptRequoter(Env, Expanded).process();
});
@@ -3041,7 +3059,7 @@ reformat(const FormatStyle &Style, StringRef Code,
return Formatter(Env, Expanded, Status).process();
});
- if (Style.Language == FormatStyle::LK_JavaScript &&
+ if (Style.isJavaScript() &&
Style.InsertTrailingCommas == FormatStyle::TCS_Wrapped)
Passes.emplace_back([&](const Environment &Env) {
return TrailingCommaInserter(Env, Expanded).process();