[clang] [clang-format] Add Natural option for SortIncludes (PR #210788)
Tshaka Lekholoane via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 25 03:11:50 PDT 2026
================
@@ -3647,6 +3656,24 @@ static void sortCppIncludes(const FormatStyle &Style,
LHSFilenameLower = Includes[LHSI].Filename.lower();
RHSFilenameLower = Includes[RHSI].Filename.lower();
}
+ if (Style.SortIncludes.Natural) {
+ if (Includes[LHSI].Priority != Includes[RHSI].Priority)
+ return Includes[LHSI].Priority < Includes[RHSI].Priority;
+ if (Style.SortIncludes.IgnoreCase) {
+ if (int Cmp = StringRef(LHSStemLower).compare_numeric(RHSStemLower))
+ return Cmp < 0;
+ }
+ if (int Cmp = StringRef(LHSStem).compare_numeric(RHSStem))
+ return Cmp < 0;
+ if (Style.SortIncludes.IgnoreCase) {
+ if (int Cmp = StringRef(LHSFilenameLower)
+ .compare_numeric(RHSFilenameLower)) {
+ return Cmp < 0;
+ }
+ }
+ return StringRef(Includes[LHSI].Filename)
+ .compare_numeric(Includes[RHSI].Filename) < 0;
+ }
return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem,
LHSFilenameLower, Includes[LHSI].Filename) <
std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem,
----------------
tshakalekholoane wrote:
I just pushed the changes, @HazardyKnusperkeks. Please, let me know if this captures what you want. I also not sure if assigning a lambda or using something like `std::invoke` would be considered more idiomatic.
https://github.com/llvm/llvm-project/pull/210788
More information about the cfe-commits
mailing list