From 6e53dfca72b932c4bdcd7aa02ca62bf8b2630eac Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 26 Jul 2016 09:20:25 +0000 Subject: 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 --- plugins/Boltun/src/Engine/Mind.cpp | 130 ++++++++++----------- plugins/Boltun/src/Engine/Mind.h | 38 +++--- plugins/Boltun/src/Engine/TalkEngine.cpp | 160 +++++++++++++------------- plugins/Boltun/src/Engine/TalkEngine.h | 44 +++---- plugins/Boltun/src/Engine/UnrecentChooser.cpp | 10 +- plugins/Boltun/src/Engine/UnrecentChooser.h | 16 +-- plugins/Boltun/src/Engine/ValueChooser.h | 2 +- plugins/Boltun/src/Engine/WordsList.cpp | 48 ++++---- plugins/Boltun/src/Engine/WordsList.h | 18 +-- 9 files changed, 233 insertions(+), 233 deletions(-) (limited to 'plugins/Boltun/src/Engine') 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 string_vec; -typedef multimap string_mmap; +typedef vector string_vec; +typedef multimap 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 Mind::Parse(tstring s) +vector Mind::Parse(wstring s) { int len = (int)s.length() - 1; - vector res; - while (len != -1 && _istspace(s[len])) + vector 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 > file; + basic_ifstream > 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 strs = Parse(s1); + vector strs = Parse(s1); data->raliases.insert(make_pair(s1, strs)); - for (vector::const_iterator it = strs.begin(); it != strs.end(); ++it) + for (vector::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 > file; + basic_ofstream > 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::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::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::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::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::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::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::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::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::iterator it = data->question.begin(); it != data->question.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + for (set::iterator it = data->question.begin(); it != data->question.end(); ++it) { + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } - for (set::iterator it = data->special.begin(); it != data->special.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + for (set::iterator it = data->special.begin(); it != data->special.end(); ++it) { + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it) { - file << L" " << _T('\r') << endl; - file << (*it) << _T('\r') << endl; + file << L" " << '\r' << endl; + file << (*it) << '\r' << endl; } - for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) { - tstring s; - const vector& v = (*it).second; + for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) { + wstring s; + const vector& v = (*it).second; bool first = true; - for (vector::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) { + for (vector::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 > file; + basic_ifstream > 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 initial; - std::set question; - std::set special; - std::vector escape; - std::vector failure; - std::vector repeats; + std::vector initial; + std::set question; + std::set special; + std::vector escape; + std::vector failure; + std::vector repeats; unsigned int maxSmileLen; - std::set smiles; - std::multimap keywords; - std::multimap qkeywords; - std::multimap widelyUsed; - std::multimap specialEscapes; - std::multimap qspecialEscapes; - std::multimap study; - std::map aliases; - std::map> raliases; + std::set smiles; + std::multimap keywords; + std::multimap qkeywords; + std::multimap widelyUsed; + std::multimap specialEscapes; + std::multimap qspecialEscapes; + std::multimap study; + std::map aliases; + std::map> raliases; private: int referenceCount; } MindData; @@ -57,7 +57,7 @@ private: MindData *data; bool fileTypeMark; - std::vector Parse(std::tstring s); + std::vector 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 sm; + const wchar_t dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—\1"; + wstring sentence = message; + wstring result; + map 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::iterator smit; + map::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::const_iterator al = mind.GetData()->aliases.find(str); + wstring str = sentence.substr(start, it - start); + map::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 &mm) +wstring TalkBot::AllReplies(const wstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap &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 sentences; + vector 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 keywords, otherwords; + vector 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& v = mind.GetData()->repeats; - tstring res = v[rand() % v.size()]; + const vector& 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 mm; + multimap 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& map, tstring& res) +bool TalkBot::FindExact(ContactData *contactData, const wstring &incomingMessage, + const multimap &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 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& vec) +void TalkBot::SplitSectences(const wstring &incomingMessage, vector& 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& 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 &mm) +wstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const multimap &mm) { #ifdef DEBUG_SHOW_VARIANTS AddBotMessage(L">>Availabe:"); - for (multimap::iterator it = mm.begin(); it != mm.end(); it++) + for (multimap::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::const_iterator lt_cit; + typedef multimap::const_iterator lt_cit; pair 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 &keywords, tstring& res/*, tstring& ures*/, +void TalkBot::FindByKeywords(ContactData *contactData, const vector &keywords, wstring& res/*, wstring& ures*/, bool isQuestion) { if (keywords.size() == 0) return; - const multimap &keys = isQuestion ? mind.GetData()->qkeywords : + const multimap &keys = isQuestion ? mind.GetData()->qkeywords : mind.GetData()->keywords; - for (multimap::const_iterator it = keys.begin(); it != keys.end(); ++it) { + for (multimap::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 &ke res = contactData->chooser.Choose(); } -bool TalkBot::FindByOthers(ContactData *contactData, const vector &otherwords, tstring& res, bool isQuestion) +bool TalkBot::FindByOthers(ContactData *contactData, const vector &otherwords, wstring& res, bool isQuestion) { - //vector results; - const multimap &specs = isQuestion ? mind.GetData()->qspecialEscapes : + //vector results; + const multimap &specs = isQuestion ? mind.GetData()->qspecialEscapes : mind.GetData()->specialEscapes; - for (multimap::const_iterator it = specs.begin(); + for (multimap::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& keywords, - vector& otherwords, bool& isQuestion) +void TalkBot::SplitAndSortWords(wstring sentence, vector& keywords, + vector& otherwords, bool& isQuestion) { - const TCHAR dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—"; + const wchar_t dividers[] = L" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—"; int len = (int)sentence.length(); - vector words; - map sm; + vector words; + map 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& 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::iterator smit; - if (_istspace(sentence[it]) && (smit = sm.find(it)) != sm.end()) + map::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& 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::iterator it = words.begin(); it != words.end(); ++it) { + for (vector::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 > question; - //ValueChooser > special; + //ValueChooser > question; + //ValueChooser > 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::const_iterator mm_cit; - bool FindExact(ContactData *contactData, const std::tstring &incomingMessage, const std::multimap &map, std::tstring &res); - bool FindAny(ValueChooser<> &ch, std::tstring &res); - void FindByKeywords(ContactData *contactData, const std::vector &keywords, std::tstring &res/*, std::tstring& ures*/, bool isQuestion); - bool FindByOthers(ContactData *contactData, const std::vector &otherwords, std::tstring &res, bool isQuestion); - std::tstring AllReplies(const std::tstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap &mm); - std::tstring ReplaceAliases(const std::tstring &message); - std::tstring ChooseResult(ContactData *contactData, Level maxValue, const std::multimap &mm); + void UpdateStartChar(std::wstring &str); + typedef std::multimap::const_iterator mm_cit; + bool FindExact(ContactData *contactData, const std::wstring &incomingMessage, const std::multimap &map, std::wstring &res); + bool FindAny(ValueChooser<> &ch, std::wstring &res); + void FindByKeywords(ContactData *contactData, const std::vector &keywords, std::wstring &res/*, std::wstring& ures*/, bool isQuestion); + bool FindByOthers(ContactData *contactData, const std::vector &otherwords, std::wstring &res, bool isQuestion); + std::wstring AllReplies(const std::wstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap &mm); + std::wstring ReplaceAliases(const std::wstring &message); + std::wstring ChooseResult(ContactData *contactData, Level maxValue, const std::multimap &mm); void RecordAnswer(ContactData *contactData, const TalkBot::MessageInfo &info); #ifdef _DEBUG public: #endif - void SplitSectences(const std::tstring &incomingMessage, std::vector &vec); - void SplitAndSortWords(std::tstring sentence, std::vector &keywords, - std::vector& otherwords, bool& isQuestion); + void SplitSectences(const std::wstring &incomingMessage, std::vector &vec); + void SplitAndSortWords(std::wstring sentence, std::vector &keywords, + std::vector& 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::iterator it = itemsList.begin(); it != itemsList.end(); ++it) + for (vector::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 items; - std::vector itemsList; - std::vector newItems; + std::map items; + std::vector itemsList; + std::vector newItems; float newItemsPrio, maxOldPrio; - std::map oldItems; - std::map oldPrios; + std::map oldItems; + std::map 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 > +template > 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::const_iterator it = words.begin(); + set::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& s/*, bool& WasStrict*/, float& priority) const +bool WordsList::MatchesAll(const vector& s/*, bool& WasStrict*/, float& priority) const { - std::set temp; + std::set temp; //WasStrict = true; - for (vector::const_iterator it = s.begin(); it != s.end(); ++it) + for (vector::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& s/*, bool& WasStrict*/, float& return temp.size() == words.size(); } -bool WordsList::MatchesAny(const vector& s) const +bool WordsList::MatchesAny(const vector& s) const { - for (vector::const_iterator it = s.begin(); it != s.end(); ++it) + 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 WordsList::ConsistsOf(const set& list) const { - vector res; - for (set::const_iterator it = words.begin(); it != words.end(); ++it) + 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 WordsList::DoesntIncludeAny(const set& list) const { - vector res; - for (set::const_iterator it = words.begin(); it != words.end(); ++it) + 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; @@ -140,17 +140,17 @@ vector WordsList::DoesntIncludeAny(const set& 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 words; + std::set words; bool isQuestion; public: - WordsList(const std::tstring &data/*, bool allowUnstrict = false*/); - operator std::tstring() const; - bool MatchesAll(const std::vector& s/*, bool& WasStrict*/, float& priority) const; - bool MatchesAny(const std::vector& s) const; - std::vector ConsistsOf(const std::set& list) const; - std::vector DoesntIncludeAny(const std::set& 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& s/*, bool& WasStrict*/, float& priority) const; + bool MatchesAny(const std::vector& s) const; + std::vector ConsistsOf(const std::set& list) const; + std::vector DoesntIncludeAny(const std::set& 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; -- cgit v1.2.3