1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 //---------------------------------------------------------------------------------
24 //---------------------------------------------------------------------------------
26 void CKeywordSet::clear()
31 void CKeywordSet::addKeywords(const std::string
&keywords
)
33 // chunkify the input string into white-space separated words
34 std::string word
, s
=keywords
;
35 while (AI_SHARE::stringToWordAndTail(s
,word
,s
))
38 _words
.push_back(word
);
40 nlwarning("Too many keywords for keyword set (limit to 32) - ignoring keyword: '%s'",word
.c_str());
44 bool CKeywordSet::stringToMask(std::string s
, CKeywordMask
&result
) const
48 while (AI_SHARE::stringToWordAndTail(s
,word
,s
))
50 //look for the keyword in the word list
52 for (i
=0;i
<_words
.size();++i
)
53 if (NLMISC::nlstricmp(word
,_words
[i
])==0)
60 nlwarning("Unknown keyword: '%s' in mask description: '%s'",word
.c_str(),s
.c_str());
67 bool CKeywordSet::stringToFilter(std::string s
, CKeywordFilter
&result
) const
69 // CKeywordFilter result;
71 CKeywordMask
*mask
=&result
._includeAny
;
73 while (AI_SHARE::stringToWordAndTail(s
,word
,s
))
75 if (word
=="+" || word
=="-")
77 // this is a + or - without ajoining word
78 mask
=(word
[0]=='+')? &result
._includeAll
: &result
._notInclude
;
82 if (word
[0]=='+' || word
[0]=='-')
84 // this is the case of the '+' or '-' immediately followed by the keyword
85 mask
=(word
[0]=='+')? &result
._includeAll
: &result
._notInclude
;
86 // prune the first character from the word so that we can drop through to common code
90 //look for the keyword in the word list
92 for (i
=0;i
<_words
.size();++i
)
93 if (NLMISC::nlstricmp(word
,_words
[i
])==0)
100 nlwarning("Unknown keyword: '%s'",word
.c_str());
104 // reset the type for the next keyword
105 mask
=&result
._includeAny
;
111 std::string
CKeywordSet::maskToString(CKeywordMask mask
) const
114 for (uint i
=0;i
<_words
.size();++i
)
115 if (mask
._mask
&(1<<i
))
116 result
+=_words
[i
]+' ';
120 std::string
CKeywordSet::filterToString(CKeywordFilter filter
) const
123 for (uint i
=0;i
<_words
.size();++i
)
125 if (filter
._includeAll
._mask
&(1<<i
)) result
+=std::string("+")+_words
[i
]+' ';
126 else if (filter
._notInclude
._mask
&(1<<i
)) result
+=std::string("-")+_words
[i
]+' ';
127 if (filter
._notInclude
._mask
&(1<<i
)) result
+=_words
[i
]+' ';
132 std::string
CKeywordSet::toString()
135 for (uint i
=0;i
<_words
.size();++i
)
140 //---------------------------------------------------------------------------------