Changeset View
Changeset View
Standalone View
Standalone View
src/engine/queryparser.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | using namespace Baloo; | 27 | using namespace Baloo; | ||
28 | 28 | | |||
29 | QueryParser::QueryParser() | 29 | QueryParser::QueryParser() | ||
30 | : m_autoExpandSize(3) | 30 | : m_autoExpandSize(3) | ||
31 | { | 31 | { | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | namespace { | | |||
35 | bool containsSpace(const QString& string) { | | |||
36 | for (const QChar& ch : string) { | | |||
37 | if (ch.isSpace()) | | |||
38 | return true; | | |||
39 | } | | |||
40 | | ||||
41 | return false; | | |||
42 | } | | |||
43 | } | | |||
44 | | ||||
45 | EngineQuery QueryParser::parseQuery(const QString& text_, const QString& prefix) | 34 | EngineQuery QueryParser::parseQuery(const QString& text_, const QString& prefix) | ||
46 | { | 35 | { | ||
47 | Q_ASSERT(!text_.isEmpty()); | 36 | Q_ASSERT(!text_.isEmpty()); | ||
48 | 37 | | |||
49 | QString text(text_); | 38 | QString text(text_); | ||
50 | text.replace(QLatin1Char('_'), QLatin1Char(' ')); | 39 | text.replace(QLatin1Char('_'), QLatin1Char(' ')); | ||
51 | 40 | | |||
52 | QVector<EngineQuery> queries; | 41 | QVector<EngineQuery> queries; | ||
Show All 29 Lines | 70 | if (inSingleQuotes) { | |||
82 | queries << EngineQuery(phraseQueries, EngineQuery::Phrase); | 71 | queries << EngineQuery(phraseQueries, EngineQuery::Phrase); | ||
83 | phraseQueries.clear(); | 72 | phraseQueries.clear(); | ||
84 | inSingleQuotes = false; | 73 | inSingleQuotes = false; | ||
85 | } | 74 | } | ||
86 | else { | 75 | else { | ||
87 | inSingleQuotes = true; | 76 | inSingleQuotes = true; | ||
88 | } | 77 | } | ||
89 | } | 78 | } | ||
90 | else if (!containsSpace(delim)) { | 79 | else if (std::none_of(delim.constBegin(), delim.constEnd(), | ||
80 | [](const QChar& ch) { return ch.isSpace(); | ||||
81 | })) { | ||||
91 | if (phraseQueries.isEmpty() && !queries.isEmpty()) { | 82 | if (phraseQueries.isEmpty() && !queries.isEmpty()) { | ||
92 | EngineQuery q = queries.takeLast(); | 83 | EngineQuery q = queries.takeLast(); | ||
93 | q.setOp(EngineQuery::Equal); | 84 | q.setOp(EngineQuery::Equal); | ||
94 | phraseQueries << q; | 85 | phraseQueries << q; | ||
95 | inPhrase = true; | 86 | inPhrase = true; | ||
96 | } | 87 | } | ||
97 | } | 88 | } | ||
98 | else if (inPhrase && !phraseQueries.isEmpty()) { | 89 | else if (inPhrase && !phraseQueries.isEmpty()) { | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |