| 16 | |
| 17 | template <typename LowTokensIter, typename F> |
| 18 | void SearchStringTokensIntersectionRanges(std::string const & s, LowTokensIter itLowBeg, LowTokensIter itLowEnd, F && f) |
| 19 | { |
| 20 | // split input query by tokens and prefix |
| 21 | search::Delimiters delimsTest; |
| 22 | size_t pos = 0; |
| 23 | |
| 24 | strings::UniString const str = strings::MakeUniString(s); |
| 25 | size_t const strLen = str.size(); |
| 26 | while (pos < strLen) |
| 27 | { |
| 28 | // skip delimeters |
| 29 | while (pos < strLen && delimsTest(str[pos])) |
| 30 | ++pos; |
| 31 | |
| 32 | size_t const beg = pos; |
| 33 | |
| 34 | // find token |
| 35 | while (pos < strLen && !delimsTest(str[pos])) |
| 36 | ++pos; |
| 37 | |
| 38 | strings::UniString subStr; |
| 39 | subStr.assign(str.begin() + beg, str.begin() + pos); |
| 40 | size_t maxCount = 0; |
| 41 | std::pair<uint16_t, uint16_t> result(0, 0); |
| 42 | |
| 43 | for (auto itLow = itLowBeg; itLow != itLowEnd; ++itLow) |
| 44 | { |
| 45 | size_t const cnt = strings::CountNormLowerSymbols(subStr, *itLow); |
| 46 | |
| 47 | if (cnt > maxCount) |
| 48 | { |
| 49 | maxCount = cnt; |
| 50 | result.first = beg; |
| 51 | result.second = cnt; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (result.second != 0) |
| 56 | f(result); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Adds to |res| the ranges that match the query tokens and, therefore, should be highlighted. |
| 61 | // The query is passed in |tokens| and |prefix|. |
no test coverage detected