5 using namespace HCE::exception;
7 void SearchStringParser::setSearchString(std::vector<std::pair<SearchType, std::string> > &sVec,
SearchType searchType, std::string &searchString)
9 if(searchString.length() > 0)
11 sVec.push_back(std::pair<SearchType, std::string>(searchType, searchString));
16 std::vector<std::pair<SearchType, std::string> > SearchStringParser::parseSearchString(
const std::string &searchString)
18 std::vector<std::pair<SearchType, std::string> > ret;
19 SearchType localSearchType = SearchType::ST_SINGLE;
20 std::string localSearchStr;
21 for(
unsigned int i = 0; i < searchString.length(); i++)
23 if(searchString[i] ==
'"')
25 if(localSearchType == SearchType::ST_SINGLE)
27 setSearchString(ret, localSearchType, localSearchStr);
28 localSearchType = SearchType::ST_STRICKT;
30 else if(localSearchType == SearchType::ST_STRICKT)
32 setSearchString(ret, localSearchType, localSearchStr);
33 localSearchType = SearchType::ST_SINGLE;
35 else if(localSearchType == SearchType::ST_NO_STRICKT)
40 else if(searchString[i] ==
'\'')
42 if(localSearchType == SearchType::ST_SINGLE)
44 setSearchString(ret, localSearchType, localSearchStr);
45 localSearchType = SearchType::ST_NO_STRICKT;
47 else if(localSearchType == SearchType::ST_STRICKT)
51 else if(localSearchType == SearchType::ST_NO_STRICKT)
53 setSearchString(ret, localSearchType, localSearchStr);
54 localSearchType = SearchType::ST_SINGLE;
57 else if(searchString[i] ==
' ')
59 if(localSearchType == SearchType::ST_SINGLE)
61 setSearchString(ret, localSearchType, localSearchStr);
65 localSearchStr += searchString[i];
70 localSearchStr += searchString[i];
73 setSearchString(ret, localSearchType, localSearchStr);
77 std::vector<std::vector<std::pair<SearchType, std::string> > >
SearchStringParser::parse(
const std::string &searchString,
const std::string &algorithmSeparator)
79 std::vector<std::vector<std::pair<SearchType, std::string> > > ret;
80 if(!searchString.empty())
83 for(
unsigned int i = 0; i < algorithmStrings.size(); i++)
85 if(algorithmStrings[i].empty())
87 ret.push_back(std::vector<std::pair<SearchType, std::string> >());
92 ret.push_back(parseSearchString(algorithmStrings[i]));
96 ret.push_back(std::vector<std::pair<SearchType, std::string> >());