C++ 以不区分大小写的方式生成叮当格式顺序包含

C++ 以不区分大小写的方式生成叮当格式顺序包含,c++,clang-format,C++,Clang Format,我正在尝试配置.clang格式。我的目的是让我的include组保持在代码中的状态,但按字母顺序排序。我用IncludeBlocks:Preserve设法接近我想要的内容,但它以区分大小写的方式对每个块中的include进行排序: 这是我应用我的格式后得到的 #包括“A1.h” #包括“B2.h” #包括“a2.h” #包括“b1.h” 这就是我想要实现的 #包括“A1.h” #包括“a2.h” #包括“b1.h” #包括“B2.h” 我使用的是10.0版的叮当格式。My.clang格式文件

我正在尝试配置.clang格式。我的目的是让我的include组保持在代码中的状态,但按字母顺序排序。我用
IncludeBlocks:Preserve
设法接近我想要的内容,但它以区分大小写的方式对每个块中的include进行排序:

这是我应用我的格式后得到的

#包括“A1.h”
#包括“B2.h”
#包括“a2.h”
#包括“b1.h”
这就是我想要实现的

#包括“A1.h”
#包括“a2.h”
#包括“b1.h”
#包括“B2.h”
我使用的是10.0版的叮当格式。My.clang格式文件,如果相关:

---
# Brompton's Clang Format file v0.0.1
#
# Changelog:
# v0.0.1 (25/9/2020):
# - First version of this file


# Base it on Google's Standard, with 4 spaces as indentation
BasedOnStyle: Google
IndentWidth: '4'
Standard: Cpp11
UseTab: Never

# Settings for C/C++
Language: Cpp
# 120 chars per line, reflow comments so they stay within limits
ColumnLimit: '120'
ReflowComments: 'true'

# Short includes alphabetically. Will respect "include groups"
SortIncludes: 'true'
IncludeBlocks: Preserve

# These control when to align text under certain conditions
# Align arguments after an open bracket ( '(', '[', '{'), on statements that are too long for a single line
AlignAfterOpenBracket: Align
# Align adjacent macros and variables, for enhanced readability.
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
# Align the '\' on scaped newlines, because it looks neater
AlignEscapedNewlines: Left

# These keep statements that could go on a single line to be collapsed. They take more space, but are more readable
# ... Code Blocks { ... }
AllowShortBlocksOnASingleLine: 'false'
# ... Switch cases
AllowShortCaseLabelsOnASingleLine: 'false'
# ... short functions, like getters and setters
AllowShortFunctionsOnASingleLine: Empty
# ... single line ifs
AllowShortIfStatementsOnASingleLine: Never
# ... single line loops
AllowShortLoopsOnASingleLine: 'false'

# Provides a more compact view when a function parameters or arguments take more than one line
BinPackArguments: 'true'
BinPackParameters: 'true'

# Indent cases on a switch, instead of leaving them at the same level than the switch statement.
IndentCaseLabels: 'true'
# Indent preprocessor the same way than code
IndentPPDirectives: BeforeHash
IndentWrappedFunctionNames: 'true'
NamespaceIndentation: All

# Put the pointer operator next to the type, instead of next to the variable name:
PointerAlignment: Left

# All about those extra spaces...
# ... remove spaces after an open-curly brace and before a close-curly brace
Cpp11BracedListStyle: 'true'
# ... space before a list, when used to initialise an object
SpaceBeforeCpp11BracedList: 'true'
# ... logical not (!) next to expression
SpaceAfterLogicalNot: 'false'
# ... space between the '=' on assignments
SpaceBeforeAssignmentOperators: 'true'
# ... space after and before the parentheses in a C-style cast.
SpacesInCStyleCastParentheses: 'false'
# ... spaces inside () and []
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
# ... spaces before a ( or a [, but only on control statements.
SpaceBeforeParens: 'ControlStatements'

...

谢谢

这是从LLVM 12开始添加的(将在Clang 13中发布?有点混乱);引用[强调我的]:

叮当声格式 选项
SortIncludes
已从布尔更新为带有 向后兼容性。除了前面的
true
/
false
状态(现在不区分大小写/
从不
),添加了第三个状态 (
区分大小写
),这会导致按字母顺序排序,并将大小写用作 打破僵局。

// Never (previously false)
#include "B/A.h"
#include "A/B.h"
#include "a/b.h"
#include "A/b.h"
#include "B/a.h"

// CaseInsensitive (previously true)
#include "A/B.h"
#include "A/b.h"
#include "B/A.h"
#include "B/a.h"
#include "a/b.h"

// CaseSensitive
#include "A/B.h"
#include "A/b.h"
#include "a/b.h"
#include "B/A.h"
#include "B/a.h"
已使用区分大小写的
示例更新了:

IncludeCategories(标准::向量)
[……]

每个正则表达式都可以用字段标记为区分大小写
区分大小写
,默认情况下不区分大小写

要在.clang格式文件中配置此文件,请使用:

IncludeCategories:
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
    SortPriority:    2
    CaseSensitive:   true
  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
    Priority:        3
  - Regex:           '<[[:alnum:].]+>'
    Priority:        4
  - Regex:           '.*'
    Priority:        1
    SortPriority:    0
IncludeCategories:
-Regex:“^”(llvm | llvm-c | clang | clang-c)/”
优先事项:2
排序优先级:2
区分大小写:对

-Regex:“^(排序很奇怪,根据测试,它不区分大小写,但我无法理解resultindecd的逻辑。当我注意到所有的搜索结果都提到它区分大小写时,我感到困惑。我在Ubuntu(在WSL上)尝试了v10和3.9,使用不同的样式(llvm、google)所有人都返回了相同的区分大小写的订单。