From cfa936b48dfb9a8bb850ff0d3600f8860345db4a Mon Sep 17 00:00:00 2001 From: mataes2007 Date: Sat, 19 Nov 2011 19:14:29 +0000 Subject: added Boltun git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@181 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- Boltun/Engine/WordsList.cpp | 169 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 Boltun/Engine/WordsList.cpp (limited to 'Boltun/Engine/WordsList.cpp') diff --git a/Boltun/Engine/WordsList.cpp b/Boltun/Engine/WordsList.cpp new file mode 100644 index 0000000..5e5d0c3 --- /dev/null +++ b/Boltun/Engine/WordsList.cpp @@ -0,0 +1,169 @@ +//*********************************************************** +// Copyright © 2008 Valentin Pavlyuchenko +// +// This file is part of Boltun. +// +// Boltun is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Boltun is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Boltun. If not, see . +// +//*********************************************************** + +#include "WordsList.h" + +using namespace std; + +WordsList::WordsList(const tstring &data/*, bool allowUnstrict*/) +{ + Parse(data/*, allowUnstrict*/); +} + +WordsList::operator tstring() const +{ + tstring res; + //if (unstrict) + // res = _T("~"); + set::const_iterator it = words.begin(); + if (!words.empty()) + while (true) + { + res += *it; + it++; + if (it != words.end()) + res += _T(" "); + else + break; + } + res += isQuestion ? _T("?") : _T("."); + return res; +} + +WordsList& WordsList::operator= (const tstring& s) +{ + Parse(s); + return *this; +}; + +void WordsList::Parse(tstring s/*, bool allowUnstrict*/) +{ + isQuestion = false; + /*if (allowUnstrict && s.length() && s[0] == _T('~')) + { + s = s.substr(1, s.npos); + unstrict = true; + } + else + unstrict = false;*/ + int len = s.length() - 1; + while (len != -1 && _istspace(s[len])) + len--; + if (len < 0) + return; + if (s[len] == '?') + isQuestion = true; + else + if (s[len] != '.') + return; + s.resize(len); + int it = 0; + while (it != len) + { + while (it != len && _istspace(s[it])) + it++; + if (it == len) + break; + int start = it; + while (it != len && !_istspace(s[it])) + it++; + words.insert(s.substr(start, it - start)); + } +} + +bool WordsList::MatchesAll(const vector& s/*, bool& WasStrict*/, float& priority) const +{ + std::set temp; + //WasStrict = true; + for (vector::const_iterator it = s.begin(); it != s.end(); it++) + { +/* if (words.find(*it) == words.end()) + if (unstrict) + { + WasStrict = false; + continue; + } + else + return false; + temp.insert((*it));*/ + if (words.find(*it) != words.end()) + temp.insert((*it)); + } + if (temp.size() != words.size()) + return false; + priority = words.size() * words.size() / (float)s.size(); + return temp.size() == words.size(); +} + +bool WordsList::MatchesAny(const vector& s) const +{ + for (vector::const_iterator it = s.begin(); it != s.end(); it++) + if (words.find(*it) != words.end()) + return true; + return false; +} + +vector WordsList::ConsistsOf(const set& list) const +{ + vector res; + for (set::const_iterator it = words.begin(); it != words.end(); it++) + if (list.find(*it) == list.end()) + res.push_back(*it); + return res; +} + +vector WordsList::DoesntIncludeAny(const set& list) const +{ + vector res; + for (set::const_iterator it = words.begin(); it != words.end(); it++) + if (list.find(*it) != list.end()) + res.push_back(*it); + return res; +} + +bool WordsList::operator<(const WordsList& value) const +{ + return (tstring)*this < (tstring)value; +} + +bool WordsList::operator!=(const WordsList& value) const +{ + return (tstring)*this != (tstring)value; +} + +bool WordsList::operator==(const WordsList& value) const +{ + return (tstring)*this == (tstring)value; +} + +size_t WordsList::Size() const +{ + return words.size(); +} + +bool WordsList::IsQuestion() const +{ + return isQuestion; +} + +bool WordsList::IsEmpty() const +{ + return words.size() == 0; +} \ No newline at end of file -- cgit v1.2.3