Skip to content

Commit 5cb8c5a

Browse files
API: Changes to MatchConfig
- Avoid recurring default separator regex instatiation - Change field order
1 parent 980ed43 commit 5cb8c5a

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

include/albert/matchconfig.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,45 @@
88
namespace albert
99
{
1010

11+
// Doxygen does not like raw strings
12+
// QRegularExpression(R"([\s\\\/\-\[\](){}#!?<>"'=+*.:,;_]+)");
13+
const QRegularExpression default_separator_regex("([\\s\\\\/\\-\\[\\](){}#!?<>\"'=+*.:,;_]+)");
14+
1115
///
1216
/// Configuration for string matching.
1317
///
18+
/// Initialize with designated initializers to avoid hard to find bugs on future changes.
19+
///
1420
/// \sa \ref Matcher, \ref IndexQueryHandler
1521
///
1622
class ALBERT_EXPORT MatchConfig
1723
{
1824
public:
25+
1926
///
20-
/// The separator regex used to split the compared strings.
27+
/// Match strings error tolerant.
2128
///
22-
QRegularExpression separator_regex =
23-
// QRegularExpression(R"([\s\\\/\-\[\](){}#!?<>"'=+*.:,;_]+)");
24-
// make doxygen happy
25-
QRegularExpression("([\\s\\\\/\\-\\[\\](){}#!?<>\"'=+*.:,;_]+)");
29+
bool fuzzy = false;
2630

2731
///
2832
/// Match strings case insensitive.
2933
///
3034
bool ignore_case = true;
3135

3236
///
33-
/// Match strings normalized.
37+
/// Match strings independent of their order.
3438
///
35-
bool ignore_diacritics = true;
39+
bool ignore_word_order = true;
3640

3741
///
38-
/// Match strings independent of their order.
42+
/// Match strings normalized.
3943
///
40-
bool ignore_word_order = true;
44+
bool ignore_diacritics = true;
4145

4246
///
43-
/// Match strings error tolerant.
47+
/// The separator regex used to split the compared strings.
4448
///
45-
bool fuzzy = false;
49+
QRegularExpression separator_regex = default_separator_regex;
4650

4751
///
4852
/// The error tolerance.
@@ -52,4 +56,4 @@ class ALBERT_EXPORT MatchConfig
5256
static const uint error_tolerance_divisor = 4;
5357
};
5458

55-
}
59+
} // namespace albert

test/test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ void AlbertTests::matcher_fuzzy()
240240
{
241241
QString abc{"abcdefghijklmnopqrstuvwxyz"};
242242

243-
MatchConfig c = {.separator_regex = QRegularExpression("[ ]+"), .fuzzy = true};
243+
MatchConfig c = {
244+
.fuzzy = true,
245+
.separator_regex = QRegularExpression("[ ]+")
246+
};
244247

245248
QVERIFY(Matcher("abcd", c).match(abc));
246249
QVERIFY(Matcher("abc_", c).match(abc));
@@ -366,8 +369,8 @@ void AlbertTests::index_fuzzy()
366369
QStringList abc{"abcdefghijklmnopqrstuvwxyz"};
367370

368371
MatchConfig c = {
369-
.separator_regex = QRegularExpression("[ ]+"),
370-
.fuzzy = true
372+
.fuzzy = true,
373+
.separator_regex = QRegularExpression("[ ]+")
371374
};
372375

373376
QVERIFY(indexMatch(abc, "abcd", c).size() == 1);

0 commit comments

Comments
 (0)