clang
20.0.0git
lib
Format
UsingDeclarationsSorter.cpp
Go to the documentation of this file.
1
//===--- UsingDeclarationsSorter.cpp ----------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// This file implements UsingDeclarationsSorter, a TokenAnalyzer that
11
/// sorts consecutive using declarations.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#include "
UsingDeclarationsSorter.h
"
16
#include "
clang/Format/Format.h
"
17
#include "llvm/Support/Debug.h"
18
#include "llvm/Support/Regex.h"
19
20
#include <algorithm>
21
22
#define DEBUG_TYPE "using-declarations-sorter"
23
24
namespace
clang
{
25
namespace
format {
26
27
namespace
{
28
29
// The order of using declaration is defined as follows:
30
// Split the strings by "::" and discard any initial empty strings. The last
31
// element of each list is a non-namespace name; all others are namespace
32
// names. Sort the lists of names lexicographically, where the sort order of
33
// individual names is that all non-namespace names come before all namespace
34
// names, and within those groups, names are in case-insensitive lexicographic
35
// order.
36
int
compareLabelsLexicographicNumeric(StringRef A, StringRef B) {
37
SmallVector<StringRef, 2> NamesA;
38
A.split(NamesA,
"::"
,
/*MaxSplit=*/
-1,
/*KeepEmpty=*/
false
);