Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit bae35fc

Browse files
Apply LLVM code style to the entire C++ codebase.
1 parent f94c89f commit bae35fc

File tree

7 files changed

+415
-404
lines changed

7 files changed

+415
-404
lines changed

.clangd

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CompileFlags:
2+
Add: [-Iinclude, -std=c++20, -O3, -Wall, -Wextra, -Wshadow, -Wconversion, -Wpedantic, -Werror]
3+
Compiler: g++
4+
5+
Index:
6+
StandardLibrary: Yes
7+
8+
Diagnostics:
9+
ClangTidy:
10+
Add: modernize*
11+
Remove: modernize-use-trailing-return-type
12+
CheckOptions:
13+
readability-identifier-naming.VariableCase: snake_case
14+
UnusedIncludes: Strict
15+
16+
Hover:
17+
ShowAKA: Yes

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build
66
dist
77
*pytest*
88
*.dblite*
9+
.cache
910
CMakeCache.txt
1011
CMakeFiles
1112
CPPBuild

include/cpr-detector.hpp

+73-77
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,81 @@
1212

1313
namespace OS2DSRules {
1414

15-
namespace CPRDetector {
16-
17-
using Predicate = std::function<bool(char)>;
18-
19-
template<typename T>
20-
requires std::same_as<T, char>
21-
constexpr Predicate make_predicate(T d) noexcept {
22-
return [d](T c) { return c == d; };
23-
}
24-
25-
template<typename T, typename... Args>
26-
constexpr Predicate make_predicate(T d, Args... ds) noexcept {
27-
if constexpr(sizeof...(ds) > 0) {
28-
return [d, ds...](T c) {
29-
return make_predicate(d)(c) || make_predicate(ds...)(c);
30-
};
31-
} else
32-
return make_predicate(d);
33-
}
34-
35-
constexpr bool is_nonzero_digit(char c) noexcept {
36-
return '0' < c && c <= '9';
37-
}
38-
39-
constexpr bool is_digit(char c) noexcept {
40-
return '0' <= c && c <= '9';
41-
}
42-
43-
const auto is_separator = make_predicate(' ', '-', '/');
44-
45-
const auto is_previous_ok = make_predicate(char(0), ' ', '\n', '\t', '\0');
46-
47-
constexpr bool is_space(const char c) noexcept {
48-
return c == ' ';
49-
}
50-
51-
const int modulus11_factors[] = {4, 3, 2, 7, 6, 5, 4, 3, 2, 1};
52-
53-
class CPRDetector {
54-
private:
55-
enum class CPRDetectorState : unsigned char {
56-
Empty,
57-
First,
58-
Second,
59-
Third,
60-
Fourth,
61-
Fifth,
62-
Sixth,
63-
Seventh,
64-
Eighth,
65-
Match,
66-
};
67-
68-
bool check_mod11_;
69-
bool examine_context_;
70-
void reset(CPRDetectorState& state) noexcept;
71-
char update(char, CPRDetectorState, CPRDetectorState&, Predicate) noexcept;
72-
bool check_day_month(const std::string&, CPRDetectorState&) noexcept;
73-
void check_leap_year(const std::string&, CPRDetectorState&) noexcept;
74-
void check_and_append_cpr(std::string&, MatchResults&, size_t, size_t) noexcept;
75-
bool check_mod11(const MatchResult&) noexcept;
76-
77-
public:
78-
constexpr CPRDetector(bool check_mod11 = false, bool examine_context = false) noexcept
79-
: check_mod11_(check_mod11), examine_context_(examine_context) {}
80-
81-
constexpr CPRDetector(const CPRDetector&) noexcept;
82-
constexpr CPRDetector& operator=(const CPRDetector&) noexcept;
83-
84-
constexpr CPRDetector(CPRDetector&&) noexcept;
85-
constexpr CPRDetector& operator=(CPRDetector&&) noexcept;
86-
~CPRDetector() = default;
87-
88-
MatchResults find_matches(const std::string&) noexcept;
89-
90-
static const Sensitivity sensitivity = Sensitivity::Critical;
15+
namespace CPRDetector {
16+
17+
using Predicate = std::function<bool(char)>;
18+
19+
template <typename T>
20+
requires std::same_as<T, char>
21+
constexpr Predicate make_predicate(T d) noexcept {
22+
return [d](T c) { return c == d; };
23+
}
24+
25+
template <typename T, typename... Args>
26+
constexpr Predicate make_predicate(T d, Args... ds) noexcept {
27+
if constexpr (sizeof...(ds) > 0) {
28+
return [d, ds...](T c) {
29+
return make_predicate(d)(c) || make_predicate(ds...)(c);
9130
};
92-
}; // namespace CPRDetector
31+
} else
32+
return make_predicate(d);
33+
}
34+
35+
constexpr bool is_nonzero_digit(char c) noexcept { return '0' < c && c <= '9'; }
36+
37+
constexpr bool is_digit(char c) noexcept { return '0' <= c && c <= '9'; }
38+
39+
const auto is_separator = make_predicate(' ', '-', '/');
40+
41+
const auto is_previous_ok = make_predicate(char(0), ' ', '\n', '\t', '\0');
42+
43+
constexpr bool is_space(const char c) noexcept { return c == ' '; }
44+
45+
const int modulus11_factors[] = {4, 3, 2, 7, 6, 5, 4, 3, 2, 1};
46+
47+
class CPRDetector {
48+
private:
49+
enum class CPRDetectorState : unsigned char {
50+
Empty,
51+
First,
52+
Second,
53+
Third,
54+
Fourth,
55+
Fifth,
56+
Sixth,
57+
Seventh,
58+
Eighth,
59+
Match,
60+
};
61+
62+
bool check_mod11_;
63+
bool examine_context_;
64+
void reset(CPRDetectorState &state) noexcept;
65+
char update(char, CPRDetectorState, CPRDetectorState &, Predicate) noexcept;
66+
bool check_day_month(const std::string &, CPRDetectorState &) noexcept;
67+
void check_leap_year(const std::string &, CPRDetectorState &) noexcept;
68+
void check_and_append_cpr(std::string &, MatchResults &, size_t,
69+
size_t) noexcept;
70+
bool check_mod11(const MatchResult &) noexcept;
71+
72+
public:
73+
constexpr CPRDetector(bool check_mod11 = false,
74+
bool examine_context = false) noexcept
75+
: check_mod11_(check_mod11), examine_context_(examine_context) {}
76+
77+
constexpr CPRDetector(const CPRDetector &) noexcept;
78+
constexpr CPRDetector &operator=(const CPRDetector &) noexcept;
79+
80+
constexpr CPRDetector(CPRDetector &&) noexcept;
81+
constexpr CPRDetector &operator=(CPRDetector &&) noexcept;
82+
~CPRDetector() = default;
83+
84+
MatchResults find_matches(const std::string &) noexcept;
85+
86+
static const Sensitivity sensitivity = Sensitivity::Critical;
87+
};
9388

89+
}; // namespace CPRDetector
9490
}; // namespace OS2DSRules
9591

9692
#endif

include/os2dsrules.hpp

+32-44
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,47 @@
1010

1111
namespace OS2DSRules {
1212

13-
enum class Sensitivity {
14-
Information = 0,
15-
Notice = 250,
16-
Warning = 500,
17-
Problem = 750,
18-
Critical = 1000,
19-
};
13+
enum class Sensitivity {
14+
Information = 0,
15+
Notice = 250,
16+
Warning = 500,
17+
Problem = 750,
18+
Critical = 1000,
19+
};
2020

21-
struct MatchResult {
22-
MatchResult(const std::string match,
23-
const size_t start,
24-
const size_t end,
25-
const Sensitivity sensitivity = Sensitivity::Critical,
26-
const double probability = 1.0) noexcept
27-
: start_(start), end_(end), match_{match}, sensitivity_(sensitivity), probability_(probability) {
28-
};
21+
struct MatchResult {
22+
MatchResult(const std::string match, const size_t start, const size_t end,
23+
const Sensitivity sensitivity = Sensitivity::Critical,
24+
const double probability = 1.0) noexcept
25+
: start_(start), end_(end), match_{match}, sensitivity_(sensitivity),
26+
probability_(probability){};
2927

30-
size_t start() const noexcept {
31-
return start_;
32-
}
28+
size_t start() const noexcept { return start_; }
3329

34-
size_t end() const noexcept {
35-
return end_;
36-
}
30+
size_t end() const noexcept { return end_; }
3731

38-
const std::string match() const noexcept {
39-
return match_;
40-
}
32+
const std::string match() const noexcept { return match_; }
4133

42-
Sensitivity sensitivity() const noexcept {
43-
return sensitivity_;
44-
}
34+
Sensitivity sensitivity() const noexcept { return sensitivity_; }
4535

46-
double probability() const noexcept {
47-
return probability_;
48-
}
36+
double probability() const noexcept { return probability_; }
4937

50-
private:
51-
const size_t start_;
52-
const size_t end_;
53-
const std::string match_;
54-
const Sensitivity sensitivity_;
55-
const double probability_;
56-
};
38+
private:
39+
const size_t start_;
40+
const size_t end_;
41+
const std::string match_;
42+
const Sensitivity sensitivity_;
43+
const double probability_;
44+
};
5745

58-
using MatchResults = std::vector<MatchResult>;
46+
using MatchResults = std::vector<MatchResult>;
5947

60-
template<typename Rule>
61-
concept ScannerRule = requires(Rule rule, std::string s) {
62-
{ Rule::sensitivity } -> std::same_as<Sensitivity>;
63-
{ rule.find_matches(s) } -> std::same_as<MatchResults>;
64-
};
48+
template <typename Rule>
49+
concept ScannerRule = requires(Rule rule, std::string s) {
50+
{ Rule::sensitivity } -> std::same_as<Sensitivity>;
51+
{ rule.find_matches(s) } -> std::same_as<MatchResults>;
52+
};
6553

66-
};
54+
}; // namespace OS2DSRules
6755

6856
#endif

0 commit comments

Comments
 (0)