highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
HighlightingAlgorithmSimple.cpp
Go to the documentation of this file.
1 
13 #include <Poco/UTF8String.h>
14 
16 
20 void HighlightingAlgorithmSimple::process(const std::vector<std::pair<SearchType, std::string> > &searchStrings, const Poco::SharedPtr<std::string> contentPtr,
21  ContentsStorageBase::WordPosPtrType wordMapPtr, std::map<unsigned int, WordPos> &wordOffsetMap)
22 {
23  if(contentPtr.isNull() || contentPtr->empty())
24  {
25  return;
26  }
27  unsigned int fakePosition = 0;
28 // cppcheck-suppress variableScope
29  size_t findPos = 0;
30  const std::string lowerCaseContent = Poco::UTF8::toLower(*contentPtr);
31  WordPos localWpos;
32  for(unsigned int i = 0; i < searchStrings.size(); i++)
33  {
34  findPos = 0;
35  const std::string lowerCaseSearchString = Poco::UTF8::toLower(searchStrings[i].second);
36  while((findPos = lowerCaseContent.find(lowerCaseSearchString, findPos)) != std::string::npos)
37  {
38  fakePosition = static_cast<unsigned int>(findPos);
39  auto it = wordOffsetMap.find(fakePosition);
40  if(it != wordOffsetMap.end())
41  {
42  if(((*it).second.endOffset - (*it).second.beginOffset) < lowerCaseSearchString.length())
43  {
44  (*it).second.endOffset = ((*it).second.beginOffset + lowerCaseSearchString.length());
45  }
46  }
47  else
48  {
49  localWpos.beginOffset = fakePosition;
50  localWpos.endOffset = fakePosition + lowerCaseSearchString.length();
51  localWpos.position = fakePosition;
52  localWpos.segmentId++;
53  wordOffsetMap.insert(std::pair<unsigned int, WordPos>(fakePosition, localWpos));
54  }
55  findPos++;
56  if(wordOffsetMap.size() == maxNumber)
57  {
58  break;
59  }
60  }
61  if(wordOffsetMap.size() == maxNumber)
62  {
63  break;
64  }
65  }
66 }