MCPcopy Create free account
hub / github.com/comaps/comaps / SearchStringTokensIntersectionRanges

Function SearchStringTokensIntersectionRanges

libs/search/highlighting.hpp:18–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17template <typename LowTokensIter, typename F>
18void 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|.

Callers 2

HighlightResultFunction · 0.85

Calls 5

MakeUniStringFunction · 0.85
CountNormLowerSymbolsFunction · 0.85
sizeMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected