summaryrefslogtreecommitdiffstats
path: root/lib/Format/UsingDeclarationsSorter.cpp
diff options
context:
space:
mode:
authorDavid L. Jones <dlj@google.com>2017-11-15 01:40:05 +0000
committerDavid L. Jones <dlj@google.com>2017-11-15 01:40:05 +0000
commitfdfce82b87b73e18577d493e84bdabe2585b95d0 (patch)
treee8d9290e273dba03920bf15a8c7742fcf5ed0b87 /lib/Format/UsingDeclarationsSorter.cpp
parent41af1698c520ea38edf83e7c91f1e519d34f20c1 (diff)
parenta7540887e8b5cb34ee28c12bef863bad85c65b6f (diff)
Creating branches/google/testing and tags/google/testing/2017-11-14 from r317716upstream/google/testing
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/google/testing@318248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UsingDeclarationsSorter.cpp')
-rw-r--r--lib/Format/UsingDeclarationsSorter.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/Format/UsingDeclarationsSorter.cpp b/lib/Format/UsingDeclarationsSorter.cpp
index d6753b545e..e9c535da92 100644
--- a/lib/Format/UsingDeclarationsSorter.cpp
+++ b/lib/Format/UsingDeclarationsSorter.cpp
@@ -33,8 +33,27 @@ struct UsingDeclaration {
UsingDeclaration(const AnnotatedLine *Line, const std::string &Label)
: Line(Line), Label(Label) {}
+ // Compares lexicographically with the exception that '_' is just before 'A'.
bool operator<(const UsingDeclaration &Other) const {
- return StringRef(Label).compare_lower(Other.Label) < 0;
+ size_t Size = Label.size();
+ size_t OtherSize = Other.Label.size();
+ for (size_t I = 0, E = std::min(Size, OtherSize); I < E; ++I) {
+ char Rank = rank(Label[I]);
+ char OtherRank = rank(Other.Label[I]);
+ if (Rank != OtherRank)
+ return Rank < OtherRank;
+ }
+ return Size < OtherSize;
+ }
+
+ // Returns the position of c in a lexicographic ordering with the exception
+ // that '_' is just before 'A'.
+ static char rank(char c) {
+ if (c == '_')
+ return 'A';
+ if ('A' <= c && c < '_')
+ return c + 1;
+ return c;
}
};
@@ -77,7 +96,7 @@ void endUsingDeclarationBlock(
SmallVectorImpl<UsingDeclaration> *UsingDeclarations,
const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
bool BlockAffected = false;
- for (const UsingDeclaration& Declaration : *UsingDeclarations) {
+ for (const UsingDeclaration &Declaration : *UsingDeclarations) {
if (Declaration.Line->Affected) {
BlockAffected = true;
break;