highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
HighlightingAlgorithmRegexpr.cpp
Go to the documentation of this file.
1 
14 #include <Poco/RegularExpression.h>
15 
16 #include "ErrorStruct.hpp"
18 
19 #include <exception>
20 #include <iostream>
21 
23 
24 void HighlightingAlgorithmRegexpr::process(const std::vector<std::pair<SearchType, std::string> > &searchStrings, const Poco::SharedPtr<std::string> contentPtr,
25  ContentsStorageBase::WordPosPtrType wordMapPtr, std::map<unsigned int, WordPos> &wordOffsetMap)
26 {
27  if(searchStrings.size() > 0 && !contentPtr.isNull() && !contentPtr->empty())
28  {
29  Poco::RegularExpression::Match match;
30  unsigned int segmentId = 0;
31  for(unsigned int i = 0; i < searchStrings.size(); i++)
32  {
33  if(!searchStrings[i].second.empty())
34  {
35  try
36  {
37 // std::string::size_type offset = 0;
38  Poco::RegularExpression rexp(searchStrings[i].second, 0, false);
39 // int matchPos = rexp.match((*contentPtr), offset, match);
40  while(match.offset != std::string::npos)
41  {
42  auto it = wordOffsetMap.find(match.offset);
43  if(it == wordOffsetMap.end())
44  {
45  wordOffsetMap.insert(std::pair<unsigned int, WordPos>(match.offset, WordPos(match.offset, match.offset + match.length, match.offset, segmentId)));
46  }
47  else if(it->second.endOffset < (match.offset + match.length))
48  {
49  it->second.endOffset = (match.offset + match.length);
50  it->second.segmentId = segmentId;
51  }
52  segmentId++;
53 // offset = match.offset + match.length;
54 // matchPos = rexp.match((*contentPtr), offset, match);
55  }
56  }
57  catch(Poco::RegularExpressionException &excp)
58  {
60  }
61  }
62  }
63  }
64 }