Skip to content

Commit 62b3a0f

Browse files
authored
Clean up libime include order and modernize for C++20 (#104)
1 parent 16bd90d commit 62b3a0f

90 files changed

Lines changed: 483 additions & 455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Standard: Cpp11
4141
IndentWidth: 4
4242
TabWidth: 4
4343
UseTab: Never
44+
LineEnding: LF
4445
BreakBeforeBraces: Attach
4546
SpacesInParentheses: false
4647
SpacesInAngles: false
@@ -51,9 +52,28 @@ SpaceBeforeAssignmentOperators: true
5152
ContinuationIndentWidth: 4
5253
CommentPragmas: '^ IWYU pragma:'
5354
ForEachMacros: [ Q_FOREACH, BOOST_FOREACH ]
55+
AttributeMacros: [ LIBIMECORE_EXPORT, LIBIMETABLE_EXPORT, LIBIMEPINYIN_EXPORT ]
5456
SpaceBeforeParens: ControlStatements
5557
DisableFormat: false
5658
SortIncludes: true
57-
AttributeMacros: [ LIBIMECORE_EXPORT, LIBIMETABLE_EXPORT, LIBIMEPINYIN_EXPORT ]
59+
IncludeCategories:
60+
# C system headers.
61+
- Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$'
62+
Priority: 20
63+
# C++ system headers (as of C++23).
64+
- Regex: '^[<"](algorithm|any|array|atomic|barrier|bit|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|charconv|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|compare|complex|concepts|condition_variable|coroutine|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|execution|expected|filesystem|flat_map|flat_set|format|forward_list|fstream|functional|future|generator|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|latch|limits|list|locale|map|mdspan|memory|memory_resource|mutex|new|numbers|numeric|optional|ostream|print|queue|random|ranges|ratio|regex|scoped_allocator|semaphore|set|shared_mutex|source_location|span|spanstream|sstream|stack|stacktrace|stdexcept|stdfloat|stop_token|streambuf|string|string_view|strstream|syncstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|variant|vector|version)[">]$'
65+
Priority: 30
66+
# Other libraries' h files (with angles).
67+
- Regex: '^<'
68+
Priority: 40
69+
# Friend project's h files.
70+
- Regex: '^[<"]fcitx'
71+
Priority: 44
72+
# Your project's h files.
73+
- Regex: '^[<"]libime'
74+
Priority: 45
75+
# Other libraries' h files (with quotes).
76+
- Regex: '^"'
77+
Priority: 50
5878
...
5979

src/libime/core/datrie.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
// <ynaga@tkl.iis.u-tokyo.ac.jp>
1212

1313
#include "datrie.h"
14-
#include "naivevector.h"
15-
#include "utils.h"
16-
#include "utils_p.h"
14+
#include <sys/types.h>
1715
#include <algorithm>
1816
#include <array>
1917
#include <cassert>
2018
#include <cmath>
2119
#include <cstdint>
2220
#include <cstring>
23-
#include <fcitx-utils/macros.h>
2421
#include <fstream>
2522
#include <ios>
2623
#include <istream>
@@ -32,9 +29,11 @@
3229
#include <stdexcept>
3330
#include <string>
3431
#include <string_view>
35-
#include <sys/types.h>
3632
#include <tuple>
3733
#include <vector>
34+
#include <fcitx-utils/macros.h>
35+
#include "naivevector.h"
36+
#include "utils_p.h"
3837

3938
namespace libime {
4039

@@ -1018,6 +1017,10 @@ DATrie<T> &DATrie<T>::operator=(DATrie<T> &&other) noexcept = default;
10181017

10191018
template <typename T>
10201019
DATrie<T> &DATrie<T>::operator=(const DATrie<T> &other) {
1020+
if (this == &other) {
1021+
return *this;
1022+
}
1023+
10211024
if (d) {
10221025
*d = *other.d;
10231026
} else {

src/libime/core/datrie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <cstddef>
1616
#include <cstdint>
17-
#include <fcitx-utils/macros.h>
1817
#include <functional>
1918
#include <istream>
2019
#include <memory>
@@ -23,6 +22,7 @@
2322
#include <string_view>
2423
#include <tuple>
2524
#include <vector>
25+
#include <fcitx-utils/macros.h>
2626

2727
namespace libime {
2828

src/libime/core/decoder.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55
*/
66

77
#include "decoder.h"
8-
#include "languagemodel.h"
9-
#include "lattice.h"
10-
#include "lattice_p.h"
11-
#include "segmentgraph.h"
12-
#include "utils.h"
13-
#include "utils_p.h"
148
#include <algorithm>
15-
#include <boost/container_hash/hash.hpp>
16-
#include <boost/functional/hash.hpp>
17-
#include <boost/ptr_container/ptr_vector.hpp>
189
#include <cassert>
1910
#include <chrono>
2011
#include <cstddef>
21-
#include <fcitx-utils/macros.h>
2212
#include <limits>
2313
#include <memory>
2414
#include <queue>
@@ -30,6 +20,16 @@
3020
#include <unordered_set>
3121
#include <utility>
3222
#include <vector>
23+
#include <boost/container_hash/hash.hpp>
24+
#include <boost/functional/hash.hpp>
25+
#include <boost/ptr_container/ptr_vector.hpp>
26+
#include <fcitx-utils/macros.h>
27+
#include "languagemodel.h"
28+
#include "lattice.h"
29+
#include "lattice_p.h"
30+
#include "segmentgraph.h"
31+
#include "utils.h"
32+
#include "utils_p.h"
3333

3434
namespace libime {
3535

src/libime/core/decoder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
#define _FCITX_LIBIME_CORE_DECODER_H_
88

99
#include <cstddef>
10+
#include <limits>
11+
#include <memory>
12+
#include <string_view>
13+
#include <utility>
1014
#include <fcitx-utils/macros.h>
1115
#include <libime/core/dictionary.h>
1216
#include <libime/core/languagemodel.h>
1317
#include <libime/core/lattice.h>
1418
#include <libime/core/libimecore_export.h>
1519
#include <libime/core/segmentgraph.h>
16-
#include <limits>
17-
#include <memory>
18-
#include <string_view>
19-
#include <utility>
2020

2121
namespace libime {
2222

src/libime/core/dictionary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
#include "dictionary.h"
8-
#include "segmentgraph.h"
98
#include <unordered_set>
9+
#include "segmentgraph.h"
1010

1111
void libime::Dictionary::matchPrefix(
1212
const SegmentGraph &graph, const GraphMatchCallback &callback,

src/libime/core/dictionary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#define _FCITX_LIBIME_CORE_DICTIONARY_H_
88

99
#include <functional>
10+
#include <memory>
11+
#include <unordered_set>
1012
#include <libime/core/lattice.h>
1113
#include <libime/core/libimecore_export.h>
1214
#include <libime/core/segmentgraph.h>
13-
#include <memory>
14-
#include <unordered_set>
1515

1616
namespace libime {
1717

src/libime/core/historybigram.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
* SPDX-License-Identifier: LGPL-2.1-or-later
55
*/
66
#include "historybigram.h"
7-
#include "constants.h"
8-
#include "datrie.h"
9-
#include "lattice.h"
10-
#include "utils_p.h"
11-
#include "zstdfilter.h"
127
#include <algorithm>
138
#include <array>
149
#include <cassert>
1510
#include <cmath>
1611
#include <cstddef>
1712
#include <cstdint>
18-
#include <fcitx-utils/macros.h>
19-
#include <fcitx-utils/stringutils.h>
2013
#include <functional>
2114
#include <istream>
2215
#include <iterator>
@@ -30,6 +23,13 @@
3023
#include <unordered_set>
3124
#include <utility>
3225
#include <vector>
26+
#include <fcitx-utils/macros.h>
27+
#include <fcitx-utils/stringutils.h>
28+
#include "constants.h"
29+
#include "datrie.h"
30+
#include "lattice.h"
31+
#include "utils_p.h"
32+
#include "zstdfilter.h"
3333

3434
namespace libime {
3535

src/libime/core/historybigram.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
#define _FCITX_LIBIME_CORE_HISTORYBIGRAM_H_
88

99
#include <cstddef>
10-
#include <fcitx-utils/macros.h>
1110
#include <istream>
12-
#include <libime/core/lattice.h>
13-
#include <libime/core/libimecore_export.h>
1411
#include <memory>
1512
#include <ostream>
1613
#include <string>
1714
#include <string_view>
1815
#include <unordered_set>
1916
#include <vector>
17+
#include <fcitx-utils/macros.h>
18+
#include <libime/core/lattice.h>
19+
#include <libime/core/libimecore_export.h>
2020

2121
namespace libime {
2222

src/libime/core/inputbuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
#include "inputbuffer.h"
77
#include <cstddef>
8-
#include <fcitx-utils/utf8.h>
98
#include <string_view>
9+
#include <fcitx-utils/utf8.h>
1010

1111
namespace libime {
1212

0 commit comments

Comments
 (0)