diff options
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 3 | ||||
-rw-r--r-- | lib/Format/UsingDeclarationsSorter.cpp | 23 |
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index bc8fef8bda..aa5990e8c0 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -696,7 +696,8 @@ private: CurrentToken->Type = TT_PointerOrReference; consumeToken(); if (CurrentToken && - CurrentToken->Previous->isOneOf(TT_BinaryOperator, tok::comma)) + CurrentToken->Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator, + tok::comma)) CurrentToken->Previous->Type = TT_OverloadedOperator; } if (CurrentToken) { 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; |