summaryrefslogtreecommitdiff
path: root/plugins/Boltun/src/Engine
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-07-26 09:20:25 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-07-26 09:20:25 +0000
commit6e53dfca72b932c4bdcd7aa02ca62bf8b2630eac (patch)
tree2e8bb660c908b54914abd562af8aafa4a486c846 /plugins/Boltun/src/Engine
parenta61c8728b379057fe7f0a0d86fe0b037598229dd (diff)
less TCHARs:
- TCHAR is replaced with wchar_t everywhere; - LPGENT replaced with either LPGENW or LPGEN; - fixes for ANSI plugins that improperly used _t functions; - TCHAR *t removed from MAllStrings; - ptszGroup, ptszTitle & ptszTab in OPTIONSDIALOGPAGE replaced with pwsz* git-svn-id: http://svn.miranda-ng.org/main/trunk@17133 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Boltun/src/Engine')
-rw-r--r--plugins/Boltun/src/Engine/Mind.cpp130
-rw-r--r--plugins/Boltun/src/Engine/Mind.h38
-rw-r--r--plugins/Boltun/src/Engine/TalkEngine.cpp160
-rw-r--r--plugins/Boltun/src/Engine/TalkEngine.h44
-rw-r--r--plugins/Boltun/src/Engine/UnrecentChooser.cpp10
-rw-r--r--plugins/Boltun/src/Engine/UnrecentChooser.h16
-rw-r--r--plugins/Boltun/src/Engine/ValueChooser.h2
-rw-r--r--plugins/Boltun/src/Engine/WordsList.cpp48
-rw-r--r--plugins/Boltun/src/Engine/WordsList.h18
9 files changed, 233 insertions, 233 deletions
diff --git a/plugins/Boltun/src/Engine/Mind.cpp b/plugins/Boltun/src/Engine/Mind.cpp
index f9a46df967..120dbc85ef 100644
--- a/plugins/Boltun/src/Engine/Mind.cpp
+++ b/plugins/Boltun/src/Engine/Mind.cpp
@@ -22,8 +22,8 @@
using namespace std;
-typedef vector<tstring> string_vec;
-typedef multimap<tstring, tstring> string_mmap;
+typedef vector<wstring> string_vec;
+typedef multimap<wstring, wstring> string_mmap;
Mind::Mind()
{
@@ -58,51 +58,51 @@ Mind& Mind::operator= (const Mind& mind)
return *this;
}
-inline void format(tstring& s)
+inline void format(wstring& s)
{
int pos = (int)s.length() - 1;
- if (s[pos] == _T('\r'))
+ if (s[pos] == '\r')
s.resize(pos);
}
-void toLowerStr(TCHAR* ch)
+void toLowerStr(wchar_t* ch)
{
CharLower(ch);
}
-vector<tstring> Mind::Parse(tstring s)
+vector<wstring> Mind::Parse(wstring s)
{
int len = (int)s.length() - 1;
- vector <tstring> res;
- while (len != -1 && _istspace(s[len]))
+ vector <wstring> res;
+ while (len != -1 && iswspace(s[len]))
len--;
if (len < 0)
return res;
s.resize(len);
int it = 0;
while (it != len) {
- while (it != len && _istspace(s[it]))
+ while (it != len && iswspace(s[it]))
it++;
if (it == len)
break;
int start = it;
- while (it != len && !_istspace(s[it]))
+ while (it != len && !iswspace(s[it]))
it++;
res.push_back(s.substr(start, it - start));
}
return res;
}
-void Mind::Load(tstring filename)
+void Mind::Load(wstring filename)
{
- basic_ifstream<TCHAR, char_traits<TCHAR> > file;
+ basic_ifstream<wchar_t, char_traits<wchar_t> > file;
locale ulocale(locale(), new MyCodeCvt);
file.imbue(ulocale);
file.open(filename.c_str(), ios_base::in | ios_base::binary);
- tstring s1, st;
- TCHAR *c, *co = NULL;
+ wstring s1, st;
+ wchar_t *c, *co = NULL;
size_t count;
int error = 0;
int line = 1;
@@ -128,10 +128,10 @@ void Mind::Load(tstring filename)
format(st);
count = st.length();
- c = co = new TCHAR[count + 1];
+ c = co = new wchar_t[count + 1];
mir_tstrcpy(c, st.c_str());
size_t pos = 0;
- while (pos < count && _istspace(*c)) {
+ while (pos < count && iswspace(*c)) {
++pos;
++c;
}
@@ -245,9 +245,9 @@ void Mind::Load(tstring filename)
toLowerStr(c);
{
std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
- vector<tstring> strs = Parse(s1);
+ vector<wstring> strs = Parse(s1);
data->raliases.insert(make_pair(s1, strs));
- for (vector<tstring>::const_iterator it = strs.begin(); it != strs.end(); ++it)
+ for (vector<wstring>::const_iterator it = strs.begin(); it != strs.end(); ++it)
data->aliases.insert(make_pair(*it, s1));
}
break;
@@ -281,9 +281,9 @@ void Mind::Load(tstring filename)
}
}
-void Mind::Save(tstring filename) const
+void Mind::Save(wstring filename) const
{
- basic_ofstream<TCHAR, char_traits<TCHAR> > file;
+ basic_ofstream<wchar_t, char_traits<wchar_t> > file;
locale ulocale(locale(), new MyCodeCvt);
file.imbue(ulocale);
@@ -291,61 +291,61 @@ void Mind::Save(tstring filename) const
file.open(filename.c_str(), ios_base::out | ios_base::binary);
if (fileTypeMark)
- file << TCHAR(65279);
+ file << wchar_t(65279);
for (string_mmap::iterator it = data->study.begin(); it != data->study.end(); ++it) {
- file << (*it).first << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ file << (*it).first << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it) {
- file << L" (" << (tstring)(*it).first << L")" << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ for (multimap<WordsList, wstring>::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it) {
+ file << L" (" << (wstring)(*it).first << L")" << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it) {
- file << L" (" << (tstring)(*it).first << L")" << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ for (multimap<WordsList, wstring>::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it) {
+ file << L" (" << (wstring)(*it).first << L")" << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it) {
- file << L" {" << (tstring)(*it).first << L"}" << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ for (multimap<WordsList, wstring>::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it) {
+ file << L" {" << (wstring)(*it).first << L"}" << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it) {
- file << L" {" << (tstring)(*it).first << L"}" << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ for (multimap<WordsList, wstring>::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it) {
+ file << L" {" << (wstring)(*it).first << L"}" << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
for (string_mmap::iterator it = data->widelyUsed.begin(); it != data->widelyUsed.end(); ++it) {
- file << L" [" << (*it).first << L"]" << _T('\r') << endl;
- file << (*it).second << _T('\r') << endl;
+ file << L" [" << (*it).first << L"]" << '\r' << endl;
+ file << (*it).second << '\r' << endl;
}
- for (set<tstring>::iterator it = data->question.begin(); it != data->question.end(); ++it) {
- file << L" <QUESTION>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ for (set<wstring>::iterator it = data->question.begin(); it != data->question.end(); ++it) {
+ file << L" <QUESTION>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
- for (set<tstring>::iterator it = data->special.begin(); it != data->special.end(); ++it) {
- file << L" <IGNORED>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ for (set<wstring>::iterator it = data->special.begin(); it != data->special.end(); ++it) {
+ file << L" <IGNORED>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it) {
- file << L" <ESCAPE>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ file << L" <ESCAPE>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it) {
- file << L" <INITIAL>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ file << L" <INITIAL>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it) {
- file << L" <FAILURE>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ file << L" <FAILURE>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it) {
- file << L" <REPEAT>" << _T('\r') << endl;
- file << (*it) << _T('\r') << endl;
+ file << L" <REPEAT>" << '\r' << endl;
+ file << (*it) << '\r' << endl;
}
- for (map<tstring, vector<tstring>>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) {
- tstring s;
- const vector<tstring>& v = (*it).second;
+ for (map<wstring, vector<wstring>>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) {
+ wstring s;
+ const vector<wstring>& v = (*it).second;
bool first = true;
- for (vector<tstring>::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) {
+ for (vector<wstring>::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) {
if (first) {
first = false;
s = *it1;
@@ -354,17 +354,17 @@ void Mind::Save(tstring filename) const
s += L" " + *it1;
}
}
- file << _T('@') << (*it).first << _T('\r') << endl;
- file << s << _T('\r') << endl;
+ file << '@' << (*it).first << '\r' << endl;
+ file << s << '\r' << endl;
}
}
-void Mind::LoadSmiles(tstring filename)
+void Mind::LoadSmiles(wstring filename)
{
- basic_ifstream<TCHAR, char_traits<TCHAR> > file;
+ basic_ifstream<wchar_t, char_traits<wchar_t> > file;
file.open(filename.c_str());
data->smiles.clear();
- tstring s;
+ wstring s;
unsigned int l = 0;
while (!file.eof()) {
getline(file, s);
@@ -378,14 +378,14 @@ void Mind::LoadSmiles(tstring filename)
void Mind::LoadSmiles(void *smiles, size_t size)
{
data->smiles.clear();
- TCHAR* buf = (TCHAR*)smiles;
+ wchar_t* buf = (wchar_t*)smiles;
unsigned l = 0;
- TCHAR* end = buf + size;
+ wchar_t* end = buf + size;
while (buf != end) {
- TCHAR *lend = buf;
- while (lend != end && *lend != _T('\r'))
+ wchar_t *lend = buf;
+ while (lend != end && *lend != '\r')
lend++;
- tstring s(buf, lend - buf);
+ wstring s(buf, lend - buf);
if ((unsigned)(lend - buf) > l)
l = (int)s.length();
data->smiles.insert(s);
diff --git a/plugins/Boltun/src/Engine/Mind.h b/plugins/Boltun/src/Engine/Mind.h
index d11eb6cd78..2b93c5fdcb 100644
--- a/plugins/Boltun/src/Engine/Mind.h
+++ b/plugins/Boltun/src/Engine/Mind.h
@@ -31,22 +31,22 @@ class Mind;
typedef struct
{
friend class Mind;
- std::vector<std::tstring> initial;
- std::set<std::tstring> question;
- std::set<std::tstring> special;
- std::vector<std::tstring> escape;
- std::vector<std::tstring> failure;
- std::vector<std::tstring> repeats;
+ std::vector<std::wstring> initial;
+ std::set<std::wstring> question;
+ std::set<std::wstring> special;
+ std::vector<std::wstring> escape;
+ std::vector<std::wstring> failure;
+ std::vector<std::wstring> repeats;
unsigned int maxSmileLen;
- std::set<std::tstring> smiles;
- std::multimap<WordsList, std::tstring> keywords;
- std::multimap<WordsList, std::tstring> qkeywords;
- std::multimap<std::tstring, std::tstring> widelyUsed;
- std::multimap<WordsList, std::tstring> specialEscapes;
- std::multimap<WordsList, std::tstring> qspecialEscapes;
- std::multimap<std::tstring, std::tstring> study;
- std::map<std::tstring, std::tstring> aliases;
- std::map<std::tstring, std::vector<std::tstring>> raliases;
+ std::set<std::wstring> smiles;
+ std::multimap<WordsList, std::wstring> keywords;
+ std::multimap<WordsList, std::wstring> qkeywords;
+ std::multimap<std::wstring, std::wstring> widelyUsed;
+ std::multimap<WordsList, std::wstring> specialEscapes;
+ std::multimap<WordsList, std::wstring> qspecialEscapes;
+ std::multimap<std::wstring, std::wstring> study;
+ std::map<std::wstring, std::wstring> aliases;
+ std::map<std::wstring, std::vector<std::wstring>> raliases;
private:
int referenceCount;
} MindData;
@@ -57,7 +57,7 @@ private:
MindData *data;
bool fileTypeMark;
- std::vector<std::tstring> Parse(std::tstring s);
+ std::vector<std::wstring> Parse(std::wstring s);
public:
Mind();
~Mind();
@@ -75,9 +75,9 @@ public:
};
const MindData *GetData() const;
- void Load(std::tstring filename);
- void Save(std::tstring filename) const;
- void LoadSmiles(std::tstring filename);
+ void Load(std::wstring filename);
+ void Save(std::wstring filename) const;
+ void LoadSmiles(std::wstring filename);
void LoadSmiles(void* smiles, size_t size);
};
diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp
index c5cc859bb3..0f53403003 100644
--- a/plugins/Boltun/src/Engine/TalkEngine.cpp
+++ b/plugins/Boltun/src/Engine/TalkEngine.cpp
@@ -33,12 +33,12 @@
//#define EXCLUDE_SPECIAL_WORDS
#ifdef DEBUG_SHOW_VARIANTS
-extern void AddBotMessage(tstring s);
+extern void AddBotMessage(wstring s);
#endif
using namespace std;
-void TalkBot::UpdateStartChar(tstring &str)
+void TalkBot::UpdateStartChar(wstring &str)
{
if (!makeLowercase)
return;
@@ -46,21 +46,21 @@ void TalkBot::UpdateStartChar(tstring &str)
size_t l = str.length();
if (l) {
// Answers starting with ' ' must remain unchanged.
- if (str[0] == _T(' ')) {
+ if (str[0] == ' ') {
str = str.substr(1);
return;
}
- TCHAR *strl = NEWTSTR_ALLOCA(str.c_str()), *stru = NEWTSTR_ALLOCA(str.c_str());
+ wchar_t *strl = NEWWSTR_ALLOCA(str.c_str()), *stru = NEWWSTR_ALLOCA(str.c_str());
CharLower(strl);
CharUpper(stru);
for (size_t i = 0; i < l; i++) {
- TCHAR cl = strl[i];
- TCHAR cu = stru[i];
+ wchar_t cl = strl[i];
+ wchar_t cu = stru[i];
if (i != l - 1) {
// Do not react to BLONDE ANSWERS
- TCHAR ncl = strl[i+1];
- TCHAR ncu = stru[i+1];
+ wchar_t ncl = strl[i+1];
+ wchar_t ncu = stru[i+1];
if (ncl != ncu && str[i+1] == ncu)
break;
}
@@ -84,27 +84,27 @@ TalkBot::~TalkBot()
delete contactDatas;
}
-tstring TalkBot::GetInitMessage(MCONTACT contact)
+wstring TalkBot::GetInitMessage(MCONTACT contact)
{
ContactData* d = contactDatas->GetData(contact);
- tstring s = d->initial.GetString();
+ wstring s = d->initial.GetString();
contactDatas->PutData(contact);
return s;
}
-tstring TalkBot::ReplaceAliases(const tstring &message)
+wstring TalkBot::ReplaceAliases(const wstring &message)
{
- const TCHAR dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—\1";
- tstring sentence = message;
- tstring result;
- map<size_t, tstring> sm;
+ const wchar_t dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—\1";
+ wstring sentence = message;
+ wstring result;
+ map<size_t, wstring> sm;
//Find smiles
for (size_t i = 0; i < sentence.length() - 1; i++) {
unsigned max = (int)(sentence.length() - i);
if (max > mind.GetData()->maxSmileLen)
max = mind.GetData()->maxSmileLen;
for (unsigned j = max; j > 0; j--) {
- tstring item = sentence.substr(i, j);
+ wstring item = sentence.substr(i, j);
if (mind.GetData()->smiles.find(item) != mind.GetData()->smiles.end()) {
sm[i] = item;
sentence.replace(i, j, L"\1");
@@ -116,10 +116,10 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
bool hadQuestionSigns = false;
int it = 0;
while (it != len) {
- while (it != len && _tcschr(dividers, sentence[it])) {
- if (sentence[it] == _T('?'))
+ while (it != len && wcschr(dividers, sentence[it])) {
+ if (sentence[it] == '?')
hadQuestionSigns = true;
- map<size_t, tstring>::iterator smit;
+ map<size_t, wstring>::iterator smit;
if (sentence[it] == '\1') {
smit = sm.find(it);
result.append((*smit).second);
@@ -132,17 +132,17 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
break;
int start = it;
while (true) {
- while (it != len && !_tcschr(dividers, sentence[it]))
+ while (it != len && !wcschr(dividers, sentence[it]))
it++;
- if (it == len || sentence[it] != _T('-'))
+ if (it == len || sentence[it] != '-')
break;
//If we have-a-word-with-minus, we shouldn't split it
- if (_tcschr(dividers, sentence[it + 1]))
+ if (wcschr(dividers, sentence[it + 1]))
break;
it += 2;
}
- tstring str = sentence.substr(start, it - start);
- map<tstring, tstring>::const_iterator al = mind.GetData()->aliases.find(str);
+ wstring str = sentence.substr(start, it - start);
+ map<wstring, wstring>::const_iterator al = mind.GetData()->aliases.find(str);
if (al != mind.GetData()->aliases.end())
result.append((*al).second);
else
@@ -151,9 +151,9 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
return result;
}
-tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap<Level, tstring> &mm)
+wstring TalkBot::AllReplies(const wstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap<Level, wstring> &mm)
{
- tstring res;
+ wstring res;
//Part 1
if (FindExact(contactData, incomingMessage, mind.GetData()->widelyUsed, res)) //widelyUsed
{
@@ -170,7 +170,7 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact
maxValue = LOOKSLIKE;
}
//Part 3
- vector<tstring> sentences;
+ vector<wstring> sentences;
SplitSectences(incomingMessage, sentences);
ValueChooser<> ch(sentences, true); //Using random order of sentences.
while ((res = ch.GetString()) != L"") {
@@ -197,7 +197,7 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact
maxValue = LOOKSLIKE;
}
//Part 6
- vector<tstring> keywords, otherwords;
+ vector<wstring> keywords, otherwords;
bool isQuestion;
SplitAndSortWords(res, keywords, otherwords, isQuestion);
//Part 7, 8
@@ -258,12 +258,12 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact
maxValue = FAIL;
}
}
- return tstring();
+ return wstring();
}
-TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, bool saveChoice)
+TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, wstring incomingMessage, bool saveChoice)
{
- TCHAR* str = new TCHAR[incomingMessage.length() + 1];
+ wchar_t* str = new wchar_t[incomingMessage.length() + 1];
mir_tstrcpy(str, incomingMessage.c_str());
CharLower(str);
incomingMessage = str;
@@ -274,8 +274,8 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage,
MessageInfo *info;
//only 2-3 repeats
if (contactData->repeatCount < 2 || contactData->repeatCount == 2 && (rand() % 2)) {
- const vector<tstring>& v = mind.GetData()->repeats;
- tstring res = v[rand() % v.size()];
+ const vector<wstring>& v = mind.GetData()->repeats;
+ wstring res = v[rand() % v.size()];
#ifdef DEBUG_PREFIXES
info = new MessageInfo(incomingMessage, L"(repeat_norm) " + res);
#else
@@ -294,10 +294,10 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage,
return info;
}
- multimap<Level, tstring> mm;
+ multimap<Level, wstring> mm;
Level maxValue = NOTHING;
- tstring res = AllReplies(incomingMessage, contactData, maxValue, mm);
+ wstring res = AllReplies(incomingMessage, contactData, maxValue, mm);
if (!res.empty()) {
UpdateStartChar(res);
#ifdef DEBUG_PREFIXES
@@ -328,7 +328,7 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage,
}
//Also does Part 12
- tstring final = ChooseResult(contactData, maxValue, mm);
+ wstring final = ChooseResult(contactData, maxValue, mm);
MessageInfo *info = new MessageInfo(incomingMessage, final);
UpdateStartChar(final);
if (saveChoice)
@@ -337,14 +337,14 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage,
return info;
}
-bool TalkBot::FindExact(ContactData *contactData, const tstring &incomingMessage,
- const multimap<tstring, tstring>& map, tstring& res)
+bool TalkBot::FindExact(ContactData *contactData, const wstring &incomingMessage,
+ const multimap<wstring, wstring> &map, wstring &res)
{
int max = (int)map.count(incomingMessage);
if (!max) {
- TCHAR c = incomingMessage[incomingMessage.length() - 1];
- if (c != _T('?') && c != _T('.') && c != _T('!'))
- return FindExact(contactData, incomingMessage + _T('.'), map, res);
+ wchar_t c = incomingMessage[incomingMessage.length() - 1];
+ if (c != '?' && c != '.' && c != '!')
+ return FindExact(contactData, incomingMessage + L'.', map, res);
return false;
}
pair<mm_cit, mm_cit> range = map.equal_range(incomingMessage);
@@ -372,7 +372,7 @@ void TalkBot::RecordAnswer(ContactData *contactData, const TalkBot::MessageInfo&
contactData->lastMessage = info.Question;
}
-bool TalkBot::FindAny(ValueChooser<> &ch, tstring& res)
+bool TalkBot::FindAny(ValueChooser<> &ch, wstring& res)
{
if (!ch.GetContainer().size())
return false;
@@ -380,23 +380,23 @@ bool TalkBot::FindAny(ValueChooser<> &ch, tstring& res)
return true;
}
-void TalkBot::SplitSectences(const tstring &incomingMessage, vector<tstring>& vec)
+void TalkBot::SplitSectences(const wstring &incomingMessage, vector<wstring>& vec)
{
//FIXME: (THINK ABOUT IT:-))these chars not always mark the end of sentence.
- const TCHAR symbols[] = L".?!";
+ const wchar_t symbols[] = L".?!";
int it = 0, len = (int)incomingMessage.length();
while (it != len) {
- while (it != len && _istspace(incomingMessage[it]))
+ while (it != len && iswspace(incomingMessage[it]))
it++;
int start = it;
while (it != len) {
- if (_tcschr(symbols, incomingMessage[it++])) {
+ if (wcschr(symbols, incomingMessage[it++])) {
//Test for a :-! smile
- if (it > 2 && incomingMessage[it - 1] == _T('!')
- && incomingMessage[it - 2] == _T('-')
- && incomingMessage[it - 3] == _T(':'))
+ if (it > 2 && incomingMessage[it - 1] == '!'
+ && incomingMessage[it - 2] == '-'
+ && incomingMessage[it - 3] == ':')
continue;
- while (it != len && _tcschr(symbols, incomingMessage[it]))
+ while (it != len && wcschr(symbols, incomingMessage[it]))
it++;
break;
}
@@ -406,9 +406,9 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector<tstring>& ve
}
#ifdef _DEBUG
-tstring LevelToStr(TalkBot::Level target)
+wstring LevelToStr(TalkBot::Level target)
{
- tstring lev;
+ wstring lev;
switch (target) {
case TalkBot::BEST: lev = L"BEST(0)"; break;
case TalkBot::LOOKSLIKE: lev = L"LOOKSLIKE(1)"; break;
@@ -420,41 +420,41 @@ tstring LevelToStr(TalkBot::Level target)
}
#endif
-tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const multimap<Level, tstring> &mm)
+wstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const multimap<Level, wstring> &mm)
{
#ifdef DEBUG_SHOW_VARIANTS
AddBotMessage(L">>Availabe:");
- for (multimap<Level, tstring>::iterator it = mm.begin(); it != mm.end(); it++)
+ for (multimap<Level, wstring>::iterator it = mm.begin(); it != mm.end(); it++)
AddBotMessage(LevelToStr((*it).first) + L": " + (*it).second);
AddBotMessage(L">>Result:");
#endif
if (maxValue == NOTHING)
return L"";
Level target = maxValue;
- typedef multimap<Level, tstring>::const_iterator lt_cit;
+ typedef multimap<Level, wstring>::const_iterator lt_cit;
pair<lt_cit, lt_cit> range = mm.equal_range(target);
for (lt_cit it = range.first; it != range.second; ++it)
contactData->chooser.AddChoice((*it).second);
#ifdef DEBUG_SHOW_LEVEL
- tstring lev = LevelToStr(target);
+ wstring lev = LevelToStr(target);
return lev + L": " + contactData->chooser.Choose();
#else
return contactData->chooser.Choose();
#endif
}
-void TalkBot::FindByKeywords(ContactData *contactData, const vector<tstring> &keywords, tstring& res/*, tstring& ures*/,
+void TalkBot::FindByKeywords(ContactData *contactData, const vector<wstring> &keywords, wstring& res/*, wstring& ures*/,
bool isQuestion)
{
if (keywords.size() == 0)
return;
- const multimap<WordsList, tstring> &keys = isQuestion ? mind.GetData()->qkeywords :
+ const multimap<WordsList, wstring> &keys = isQuestion ? mind.GetData()->qkeywords :
mind.GetData()->keywords;
- for (multimap<WordsList, tstring>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
+ for (multimap<WordsList, wstring>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
float prio;
if ((*it).first.MatchesAll(keywords/*, strict*/, prio))
#ifdef DEBUG_SHOW_SOLUTION_REASON
- contactData->chooser.AddChoice((tstring)(*it).first + L": - " + (*it).second, prio);
+ contactData->chooser.AddChoice((wstring)(*it).first + L": - " + (*it).second, prio);
#else
contactData->chooser.AddChoice((*it).second, prio);
#endif
@@ -462,16 +462,16 @@ void TalkBot::FindByKeywords(ContactData *contactData, const vector<tstring> &ke
res = contactData->chooser.Choose();
}
-bool TalkBot::FindByOthers(ContactData *contactData, const vector<tstring> &otherwords, tstring& res, bool isQuestion)
+bool TalkBot::FindByOthers(ContactData *contactData, const vector<wstring> &otherwords, wstring& res, bool isQuestion)
{
- //vector<tstring> results;
- const multimap<WordsList, tstring> &specs = isQuestion ? mind.GetData()->qspecialEscapes :
+ //vector<wstring> results;
+ const multimap<WordsList, wstring> &specs = isQuestion ? mind.GetData()->qspecialEscapes :
mind.GetData()->specialEscapes;
- for (multimap<WordsList, tstring>::const_iterator it = specs.begin();
+ for (multimap<WordsList, wstring>::const_iterator it = specs.begin();
it != specs.end(); ++it)
if ((*it).first.MatchesAny(otherwords)) {
#ifdef DEBUG_SHOW_SOLUTION_REASON
- contactData->chooser.AddChoice((tstring)(*it).first + L": - " + (*it).second);
+ contactData->chooser.AddChoice((wstring)(*it).first + L": - " + (*it).second);
#else
contactData->chooser.AddChoice((*it).second);
#endif
@@ -487,20 +487,20 @@ const Mind& TalkBot::GetMind() const
return mind;
}
-void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords,
- vector<tstring>& otherwords, bool& isQuestion)
+void TalkBot::SplitAndSortWords(wstring sentence, vector<wstring>& keywords,
+ vector<wstring>& otherwords, bool& isQuestion)
{
- const TCHAR dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—";
+ const wchar_t dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—";
int len = (int)sentence.length();
- vector<tstring> words;
- map<size_t, tstring> sm;
+ vector<wstring> words;
+ map<size_t, wstring> sm;
//Find smiles
for (size_t i = 0; i < sentence.length() - 1; i++) {
unsigned max = (int)(sentence.length() - i);
if (max > mind.GetData()->maxSmileLen)
max = mind.GetData()->maxSmileLen;
for (unsigned j = max; j > 0; j--) {
- tstring item = sentence.substr(i, j);
+ wstring item = sentence.substr(i, j);
if (mind.GetData()->smiles.find(item)
!= mind.GetData()->smiles.end()) {
sm[i] = item;
@@ -512,11 +512,11 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords,
len = (int)sentence.length();
bool hadQuestionSigns = false;
for (int it = 0; it != len;) {
- while (it != len && _tcschr(dividers, sentence[it])) {
- if (sentence[it] == _T('?'))
+ while (it != len && wcschr(dividers, sentence[it])) {
+ if (sentence[it] == '?')
hadQuestionSigns = true;
- map<size_t, tstring>::iterator smit;
- if (_istspace(sentence[it]) && (smit = sm.find(it)) != sm.end())
+ map<size_t, wstring>::iterator smit;
+ if (iswspace(sentence[it]) && (smit = sm.find(it)) != sm.end())
words.push_back((*smit).second);
it++;
}
@@ -526,20 +526,20 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords,
hadQuestionSigns = false;
int start = it;
while (true) {
- while (it != len && !_tcschr(dividers, sentence[it]))
+ while (it != len && !wcschr(dividers, sentence[it]))
it++;
- if (it == len || sentence[it] != _T('-'))
+ if (it == len || sentence[it] != '-')
break;
// If we have-a-word-with-minus, we shouldn't split it
- if (_tcschr(dividers, sentence[it + 1]))
+ if (wcschr(dividers, sentence[it + 1]))
break;
it += 2;
}
- tstring str = sentence.substr(start, it - start);
+ wstring str = sentence.substr(start, it - start);
words.push_back(str);
}
isQuestion = hadQuestionSigns;
- for (vector<tstring>::iterator it = words.begin(); it != words.end(); ++it) {
+ for (vector<wstring>::iterator it = words.begin(); it != words.end(); ++it) {
if (!isQuestion)
if (mind.GetData()->question.find(*it) != mind.GetData()->question.end())
isQuestion = true;
diff --git a/plugins/Boltun/src/Engine/TalkEngine.h b/plugins/Boltun/src/Engine/TalkEngine.h
index c18f3df1c1..7e0539c9e6 100644
--- a/plugins/Boltun/src/Engine/TalkEngine.h
+++ b/plugins/Boltun/src/Engine/TalkEngine.h
@@ -34,14 +34,14 @@ public:
struct MessageInfo
{
private:
- std::tstring Question;
- MessageInfo(std::tstring q, std::tstring a)
+ std::wstring Question;
+ MessageInfo(std::wstring q, std::wstring a)
:Question(q), Answer(a)
{
}
public:
- std::tstring Answer;
- MessageInfo(std::tstring q)
+ std::wstring Answer;
+ MessageInfo(std::wstring q)
:Question(q)
{
}
@@ -52,17 +52,17 @@ private:
{
BEST, LOOKSLIKE/*, LOOKSLIKE2*/, BAD, FAIL, NOTHING
} Level;
- friend std::tstring LevelToStr(TalkBot::Level target);
+ friend std::wstring LevelToStr(TalkBot::Level target);
struct ContactData
{
ValueChooser<> initial;
- //ValueChooser<std::set<std::tstring> > question;
- //ValueChooser<std::set<std::tstring> > special;
+ //ValueChooser<std::set<std::wstring> > question;
+ //ValueChooser<std::set<std::wstring> > special;
ValueChooser<> escape;
ValueChooser<> failure;
UnRecentChooser chooser;
- std::tstring lastMessage;
+ std::wstring lastMessage;
long long lastMessageTime;
int repeatCount;
inline ContactData(const Mind& mind)
@@ -81,22 +81,22 @@ private:
bool beSilent;
bool makeLowercase;
bool understandAlways;
- void UpdateStartChar(std::tstring &str);
- typedef std::multimap<std::tstring, std::tstring>::const_iterator mm_cit;
- bool FindExact(ContactData *contactData, const std::tstring &incomingMessage, const std::multimap<std::tstring, std::tstring> &map, std::tstring &res);
- bool FindAny(ValueChooser<> &ch, std::tstring &res);
- void FindByKeywords(ContactData *contactData, const std::vector<std::tstring> &keywords, std::tstring &res/*, std::tstring& ures*/, bool isQuestion);
- bool FindByOthers(ContactData *contactData, const std::vector<std::tstring> &otherwords, std::tstring &res, bool isQuestion);
- std::tstring AllReplies(const std::tstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap<Level, std::tstring> &mm);
- std::tstring ReplaceAliases(const std::tstring &message);
- std::tstring ChooseResult(ContactData *contactData, Level maxValue, const std::multimap<Level, std::tstring> &mm);
+ void UpdateStartChar(std::wstring &str);
+ typedef std::multimap<std::wstring, std::wstring>::const_iterator mm_cit;
+ bool FindExact(ContactData *contactData, const std::wstring &incomingMessage, const std::multimap<std::wstring, std::wstring> &map, std::wstring &res);
+ bool FindAny(ValueChooser<> &ch, std::wstring &res);
+ void FindByKeywords(ContactData *contactData, const std::vector<std::wstring> &keywords, std::wstring &res/*, std::wstring& ures*/, bool isQuestion);
+ bool FindByOthers(ContactData *contactData, const std::vector<std::wstring> &otherwords, std::wstring &res, bool isQuestion);
+ std::wstring AllReplies(const std::wstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap<Level, std::wstring> &mm);
+ std::wstring ReplaceAliases(const std::wstring &message);
+ std::wstring ChooseResult(ContactData *contactData, Level maxValue, const std::multimap<Level, std::wstring> &mm);
void RecordAnswer(ContactData *contactData, const TalkBot::MessageInfo &info);
#ifdef _DEBUG
public:
#endif
- void SplitSectences(const std::tstring &incomingMessage, std::vector<std::tstring> &vec);
- void SplitAndSortWords(std::tstring sentence, std::vector<std::tstring> &keywords,
- std::vector<std::tstring>& otherwords, bool& isQuestion);
+ void SplitSectences(const std::wstring &incomingMessage, std::vector<std::wstring> &vec);
+ void SplitAndSortWords(std::wstring sentence, std::vector<std::wstring> &keywords,
+ std::vector<std::wstring>& otherwords, bool& isQuestion);
public:
TalkBot(const Mind& goodMind);
~TalkBot();
@@ -105,8 +105,8 @@ public:
void SetLowercase(const bool isLowercase);
void SetUnderstandAlways(const bool understandAlways);
//const MindData *GetData();
- std::tstring GetInitMessage(MCONTACT contact);
- MessageInfo* Reply(MCONTACT contact, const std::tstring incomingMessage, bool saveChoice);
+ std::wstring GetInitMessage(MCONTACT contact);
+ MessageInfo* Reply(MCONTACT contact, const std::wstring incomingMessage, bool saveChoice);
void AnswerGiven(MCONTACT contact, const MessageInfo &info);
};
diff --git a/plugins/Boltun/src/Engine/UnrecentChooser.cpp b/plugins/Boltun/src/Engine/UnrecentChooser.cpp
index b0b5e1460e..761adf10c4 100644
--- a/plugins/Boltun/src/Engine/UnrecentChooser.cpp
+++ b/plugins/Boltun/src/Engine/UnrecentChooser.cpp
@@ -27,7 +27,7 @@ UnRecentChooser::UnRecentChooser()
{
}
-void UnRecentChooser::AddChoice(tstring value, float prio)
+void UnRecentChooser::AddChoice(wstring value, float prio)
{
if (items.count(value) != 0)
{
@@ -49,9 +49,9 @@ void UnRecentChooser::AddChoice(tstring value, float prio)
}
}
-tstring UnRecentChooser::Choose()
+wstring UnRecentChooser::Choose()
{
- tstring res;
+ wstring res;
//Find answer
if (newItemsPrio != -1)
{
@@ -78,12 +78,12 @@ tstring UnRecentChooser::Choose()
return res;
}
-void UnRecentChooser::SaveChoice(tstring choice)
+void UnRecentChooser::SaveChoice(wstring choice)
{
//Add answer
if (items.find(choice) != items.end())
{
- for (vector<tstring>::iterator it = itemsList.begin(); it != itemsList.end(); ++it)
+ for (vector<wstring>::iterator it = itemsList.begin(); it != itemsList.end(); ++it)
if (*it == choice)
{
itemsList.erase(it);
diff --git a/plugins/Boltun/src/Engine/UnrecentChooser.h b/plugins/Boltun/src/Engine/UnrecentChooser.h
index 72245773de..ff82faf628 100644
--- a/plugins/Boltun/src/Engine/UnrecentChooser.h
+++ b/plugins/Boltun/src/Engine/UnrecentChooser.h
@@ -23,20 +23,20 @@
class UnRecentChooser
{
- std::map<std::tstring, size_t> items;
- std::vector<std::tstring> itemsList;
- std::vector<std::tstring> newItems;
+ std::map<std::wstring, size_t> items;
+ std::vector<std::wstring> itemsList;
+ std::vector<std::wstring> newItems;
float newItemsPrio, maxOldPrio;
- std::map<size_t, std::tstring> oldItems;
- std::map<std::tstring, float> oldPrios;
+ std::map<size_t, std::wstring> oldItems;
+ std::map<std::wstring, float> oldPrios;
size_t last;
int minimum;
static const size_t maxItems = 100;
public:
UnRecentChooser();
- void AddChoice(std::tstring value, float prio = 1.0);
- std::tstring Choose();
- void SaveChoice(std::tstring choice);
+ void AddChoice(std::wstring value, float prio = 1.0);
+ std::wstring Choose();
+ void SaveChoice(std::wstring choice);
};
#endif /* UnRecentChooserH */ \ No newline at end of file
diff --git a/plugins/Boltun/src/Engine/ValueChooser.h b/plugins/Boltun/src/Engine/ValueChooser.h
index f82ceecbea..b65db2acea 100644
--- a/plugins/Boltun/src/Engine/ValueChooser.h
+++ b/plugins/Boltun/src/Engine/ValueChooser.h
@@ -21,7 +21,7 @@
#ifndef StringChooserH
#define StringChooserH
-template<class container = std::vector<std::tstring> >
+template<class container = std::vector<std::wstring> >
class ValueChooser
{
private:
diff --git a/plugins/Boltun/src/Engine/WordsList.cpp b/plugins/Boltun/src/Engine/WordsList.cpp
index b111cc3414..1efbdebc20 100644
--- a/plugins/Boltun/src/Engine/WordsList.cpp
+++ b/plugins/Boltun/src/Engine/WordsList.cpp
@@ -22,17 +22,17 @@
using namespace std;
-WordsList::WordsList(const tstring &data/*, bool allowUnstrict*/)
+WordsList::WordsList(const wstring &data/*, bool allowUnstrict*/)
{
Parse(data/*, allowUnstrict*/);
}
-WordsList::operator tstring() const
+WordsList::operator wstring() const
{
- tstring res;
+ wstring res;
//if (unstrict)
// res = L"~";
- set<tstring>::const_iterator it = words.begin();
+ set<wstring>::const_iterator it = words.begin();
if (!words.empty())
while (true)
{
@@ -47,16 +47,16 @@ WordsList::operator tstring() const
return res;
}
-WordsList& WordsList::operator= (const tstring& s)
+WordsList& WordsList::operator= (const wstring& s)
{
Parse(s);
return *this;
};
-void WordsList::Parse(tstring s/*, bool allowUnstrict*/)
+void WordsList::Parse(wstring s/*, bool allowUnstrict*/)
{
isQuestion = false;
- /*if (allowUnstrict && s.length() && s[0] == _T('~'))
+ /*if (allowUnstrict && s.length() && s[0] == '~')
{
s = s.substr(1, s.npos);
unstrict = true;
@@ -64,7 +64,7 @@ void WordsList::Parse(tstring s/*, bool allowUnstrict*/)
else
unstrict = false;*/
int len = (int)s.length() - 1;
- while (len != -1 && _istspace(s[len]))
+ while (len != -1 && iswspace(s[len]))
len--;
if (len < 0)
return;
@@ -77,22 +77,22 @@ void WordsList::Parse(tstring s/*, bool allowUnstrict*/)
int it = 0;
while (it != len)
{
- while (it != len && _istspace(s[it]))
+ while (it != len && iswspace(s[it]))
it++;
if (it == len)
break;
int start = it;
- while (it != len && !_istspace(s[it]))
+ while (it != len && !iswspace(s[it]))
it++;
words.insert(s.substr(start, it - start));
}
}
-bool WordsList::MatchesAll(const vector<tstring>& s/*, bool& WasStrict*/, float& priority) const
+bool WordsList::MatchesAll(const vector<wstring>& s/*, bool& WasStrict*/, float& priority) const
{
- std::set<tstring> temp;
+ std::set<wstring> temp;
//WasStrict = true;
- for (vector<tstring>::const_iterator it = s.begin(); it != s.end(); ++it)
+ for (vector<wstring>::const_iterator it = s.begin(); it != s.end(); ++it)
{
/* if (words.find(*it) == words.end())
if (unstrict)
@@ -112,27 +112,27 @@ bool WordsList::MatchesAll(const vector<tstring>& s/*, bool& WasStrict*/, float&
return temp.size() == words.size();
}
-bool WordsList::MatchesAny(const vector<tstring>& s) const
+bool WordsList::MatchesAny(const vector<wstring>& s) const
{
- for (vector<tstring>::const_iterator it = s.begin(); it != s.end(); ++it)
+ for (vector<wstring>::const_iterator it = s.begin(); it != s.end(); ++it)
if (words.find(*it) != words.end())
return true;
return false;
}
-vector<tstring> WordsList::ConsistsOf(const set<tstring>& list) const
+vector<wstring> WordsList::ConsistsOf(const set<wstring>& list) const
{
- vector<tstring> res;
- for (set<tstring>::const_iterator it = words.begin(); it != words.end(); ++it)
+ vector<wstring> res;
+ for (set<wstring>::const_iterator it = words.begin(); it != words.end(); ++it)
if (list.find(*it) == list.end())
res.push_back(*it);
return res;
}
-vector<tstring> WordsList::DoesntIncludeAny(const set<tstring>& list) const
+vector<wstring> WordsList::DoesntIncludeAny(const set<wstring>& list) const
{
- vector<tstring> res;
- for (set<tstring>::const_iterator it = words.begin(); it != words.end(); ++it)
+ vector<wstring> res;
+ for (set<wstring>::const_iterator it = words.begin(); it != words.end(); ++it)
if (list.find(*it) != list.end())
res.push_back(*it);
return res;
@@ -140,17 +140,17 @@ vector<tstring> WordsList::DoesntIncludeAny(const set<tstring>& list) const
bool WordsList::operator<(const WordsList& value) const
{
- return (tstring)*this < (tstring)value;
+ return (wstring)*this < (wstring)value;
}
bool WordsList::operator!=(const WordsList& value) const
{
- return (tstring)*this != (tstring)value;
+ return (wstring)*this != (wstring)value;
}
bool WordsList::operator==(const WordsList& value) const
{
- return (tstring)*this == (tstring)value;
+ return (wstring)*this == (wstring)value;
}
size_t WordsList::Size() const
diff --git a/plugins/Boltun/src/Engine/WordsList.h b/plugins/Boltun/src/Engine/WordsList.h
index 4cac8cd969..dfda3b6c91 100644
--- a/plugins/Boltun/src/Engine/WordsList.h
+++ b/plugins/Boltun/src/Engine/WordsList.h
@@ -24,21 +24,21 @@
class WordsList
{
WordsList();
- void Parse(std::tstring s/*, bool allowUnstrict = false*/);
+ void Parse(std::wstring s/*, bool allowUnstrict = false*/);
//bool unstrict;
#ifdef _DEBUG
public:
#endif
- std::set<std::tstring> words;
+ std::set<std::wstring> words;
bool isQuestion;
public:
- WordsList(const std::tstring &data/*, bool allowUnstrict = false*/);
- operator std::tstring() const;
- bool MatchesAll(const std::vector<std::tstring>& s/*, bool& WasStrict*/, float& priority) const;
- bool MatchesAny(const std::vector<std::tstring>& s) const;
- std::vector<std::tstring> ConsistsOf(const std::set<std::tstring>& list) const;
- std::vector<std::tstring> DoesntIncludeAny(const std::set<std::tstring>& list) const;
- WordsList& operator= (const std::tstring& s);
+ WordsList(const std::wstring &data/*, bool allowUnstrict = false*/);
+ operator std::wstring() const;
+ bool MatchesAll(const std::vector<std::wstring>& s/*, bool& WasStrict*/, float& priority) const;
+ bool MatchesAny(const std::vector<std::wstring>& s) const;
+ std::vector<std::wstring> ConsistsOf(const std::set<std::wstring>& list) const;
+ std::vector<std::wstring> DoesntIncludeAny(const std::set<std::wstring>& list) const;
+ WordsList& operator= (const std::wstring& s);
bool operator<(const WordsList& value) const;
bool operator==(const WordsList& value) const;
bool operator!=(const WordsList& value) const;