| 7 | using namespace albert; |
| 8 | |
| 9 | QStringList preprocessQuery(QString s, const MatchConfig &config) |
| 10 | { |
| 11 | if (config.ignore_diacritics) |
| 12 | { |
| 13 | static const QRegularExpression re( |
| 14 | "([" |
| 15 | R"(\x{0300}-\x{036f})" // diacritical marks |
| 16 | "\u00AD" // Soft hyphen |
| 17 | "])"); |
| 18 | s = s.normalized(QString::NormalizationForm_D).remove(re); |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | // Remove soft hyphens |
| 23 | s.remove(QChar(0x00AD)); |
| 24 | } |
| 25 | |
| 26 | if (config.ignore_case) |
| 27 | s = s.toLower(); |
| 28 | |
| 29 | QTextBoundaryFinder finder(QTextBoundaryFinder::Word, s); |
| 30 | QStringList tokens; |
| 31 | qsizetype begin = 0; |
| 32 | for (qsizetype end = finder.toNextBoundary(); |
| 33 | end != -1; |
| 34 | end = finder.toNextBoundary()) |
| 35 | { |
| 36 | if (begin != end) |
| 37 | { |
| 38 | // Only add non-space tokens |
| 39 | // Assumes that the tokes that either are all spaces or non-spaces |
| 40 | if(!s[begin].isSpace()) |
| 41 | tokens << s.mid(begin, end - begin); |
| 42 | begin = end; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if (config.ignore_word_order) |
| 47 | tokens.sort(); |
| 48 | |
| 49 | return tokens; |
| 50 | } |
| 51 | |
| 52 | QStringList preprocessLegacy(QString s) |
| 53 | { |
no outgoing calls