summaryrefslogtreecommitdiff
path: root/stopspam.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-03-05 00:56:25 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-03-05 00:56:25 +0200
commit2cc3972afe16ed661615490de5cad37d870ab375 (patch)
tree93bcce1c6b4b99e9a48e76d0ab5a5c46aa747f8d /stopspam.cpp
parent033994e10490492e836f88871bb061cf1bcc084e (diff)
fixed math expression feature
Diffstat (limited to 'stopspam.cpp')
-rwxr-xr-xstopspam.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/stopspam.cpp b/stopspam.cpp
index 0e24879..f99e4c9 100755
--- a/stopspam.cpp
+++ b/stopspam.cpp
@@ -144,8 +144,12 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
bool answered = false;
if(gbMathExpression)
{
- int msg = _ttoi(message.c_str());
- answered = (msg == math_answer);
+ if(boost::algorithm::all(message, boost::is_digit()))
+ {
+ int msg = _ttoi(message.c_str());
+ if(msg)
+ answered = (msg == math_answer);
+ }
}
else if(!gbRegexMatch)
answered = gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str())));
@@ -230,13 +234,17 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
tstring tmp_question = gbQuestion;
std::list<int> args;
std::list<TCHAR> actions;
- std::string arg;
tstring::size_type p1 = gbQuestion.find(_T("X")), p2 = 0;
const tstring expr_chars = _T("X+-/*");
- while(expr_chars.find(gbQuestion[p1]) != tstring::npos)
+ while(p1 < gbQuestion.length() && p1 != tstring::npos && expr_chars.find(gbQuestion[p1]) != tstring::npos)
{
+ std::string arg;
p2 = p1;
- for(p1 = gbQuestion.find(_T("X"), p1); p1 != tstring::npos; ++p1)
+#ifdef UNICODE
+ for(p1 = gbQuestion.find(_T("X"), p1); (p1 < gbQuestion.length()) && (gbQuestion[p1] == L'X'); ++p1)
+#else
+ for(p1 = gbQuestion.find(_T("X"), p1); gbQuestion[p1] == 'X'; ++p1)
+#endif
arg += get_random_num(1);
#ifdef UNICODE
tmp_question.replace(p2, arg.size(), toUTF16(arg));
@@ -244,7 +252,8 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
tmp_question.replace(p2, arg.size(), arg);
#endif
args.push_back(atoi(arg.c_str()));
- actions.push_back(gbQuestion[p1]);
+ if((p1 < gbQuestion.length()) && (p1 != tstring::npos))
+ actions.push_back(gbQuestion[p1]);
++p1;
}
math_answer = args.front();