[clang] [clang-format] Add Natural option for SortIncludes (PR #210788)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 26 12:18:52 PDT 2026
================
@@ -3632,13 +3641,17 @@ static void sortCppIncludes(const FormatStyle &Style,
if (Style.SortIncludes.Enabled) {
stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
+ if (Includes[LHSI].Priority != Includes[RHSI].Priority)
+ return Includes[LHSI].Priority < Includes[RHSI].Priority;
+
SmallString<128> LHSStem, RHSStem;
if (Style.SortIncludes.IgnoreExtension) {
LHSStem = Includes[LHSI].Filename;
RHSStem = Includes[RHSI].Filename;
llvm::sys::path::replace_extension(LHSStem, "");
llvm::sys::path::replace_extension(RHSStem, "");
}
+
std::string LHSStemLower, RHSStemLower;
std::string LHSFilenameLower, RHSFilenameLower;
if (Style.SortIncludes.IgnoreCase) {
----------------
HazardyKnusperkeks wrote:
While at it, maybe just add two StringRefs initialized to the LHS rsp. RHS Filename and reassign the StringRef inside this if. That should simplify the remaining code. (And also not compare two empty strings in case of case sensitive sorting.)
https://github.com/llvm/llvm-project/pull/210788
More information about the cfe-commits
mailing list