return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
}
+bool likelyXml(StringRef Code) {
+ return Code.ltrim().startswith("<");
+}
+
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName, unsigned *Cursor) {
tooling::Replacements Replaces;
if (!Style.SortIncludes)
return Replaces;
- if (Style.Language == FormatStyle::LanguageKind::LK_JavaScript &&
- isMpegTS(Code))
+ if (likelyXml(Code) ||
+ (Style.Language == FormatStyle::LanguageKind::LK_JavaScript &&
+ isMpegTS(Code)))
return Replaces;
if (Style.Language == FormatStyle::LanguageKind::LK_JavaScript)
return sortJavaScriptImports(Style, Code, Ranges, FileName);
FormatStyle Expanded = expandPresets(Style);
if (Expanded.DisableFormat)
return tooling::Replacements();
- if (Expanded.Language == FormatStyle::LK_JavaScript && isMpegTS(Code))
+ if (likelyXml(Code) ||
+ (Expanded.Language == FormatStyle::LK_JavaScript && isMpegTS(Code)))
return tooling::Replacements();
typedef std::function<tooling::Replacements(const Environment &)>
EXPECT_EQ("auto c = u8'a';", format("auto c = u8'a';"));
}
+TEST_F(FormatTest, DoNotFormatLikelyXml) {
+ EXPECT_EQ("<!-- ;> -->",
+ format("<!-- ;> -->", getGoogleStyle()));
+ EXPECT_EQ(" <!-- >; -->",
+ format(" <!-- >; -->", getGoogleStyle()));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
EXPECT_EQ(26u, Ranges[0].getLength());
}
+TEST_F(SortIncludesTest, DoNotSortLikelyXml) {
+ EXPECT_EQ("<!--;\n"
+ "#include <b>\n"
+ "#include <a>\n"
+ "-->",
+ sort("<!--;\n"
+ "#include <b>\n"
+ "#include <a>\n"
+ "-->"));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang