summaryrefslogtreecommitdiff
path: root/plugins/Variables/src/parse_regexp.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-13 19:26:02 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-13 19:26:02 +0000
commiteacc63d1fe3c0a5f6b982575867258650f98119b (patch)
treeafe39a5e1764c13293cfd3e8a403a181ea8c3e1f /plugins/Variables/src/parse_regexp.cpp
parent8aebeeca820d48c4a126bc7670b4a558d73ed881 (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@6056 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Variables/src/parse_regexp.cpp')
-rw-r--r--plugins/Variables/src/parse_regexp.cpp83
1 files changed, 26 insertions, 57 deletions
diff --git a/plugins/Variables/src/parse_regexp.cpp b/plugins/Variables/src/parse_regexp.cpp
index d8ea5c31b3..3b8679de6b 100644
--- a/plugins/Variables/src/parse_regexp.cpp
+++ b/plugins/Variables/src/parse_regexp.cpp
@@ -22,38 +22,31 @@
/*
pattern, subject
*/
-static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai)
+{
const char *err;
int erroffset;
- char szVal[34], *arg1, *arg2;
+ char szVal[34];
int offsets[99];
- if (ai->argc != 3) {
+ if (ai->argc != 3)
return NULL;
- }
+
ai->flags = AIF_FALSE;
- arg1 = mir_t2a(ai->targv[1]);
- arg2 = mir_t2a(ai->targv[2]);
+ ptrA arg1( mir_t2a(ai->targv[1]));
+ ptrA arg2( mir_t2a(ai->targv[2]));
pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL);
- if (ppat == NULL) {
- mir_free(arg1);
- mir_free(arg2);
+ if (ppat == NULL)
return NULL;
- }
+
pcre_extra *extra = pcre_study(ppat, 0, &err);
int nmat = pcre_exec(ppat, extra, arg2, (int)strlen(arg2), 0, 0, offsets, 99);
- mir_free(arg1);
- mir_free(arg2);
if (nmat > 0) {
ai->flags &= ~AIF_FALSE;
_ltoa(nmat, szVal, 10);
-
- TCHAR *res = mir_a2t(szVal);
-
- return res;
+ return mir_a2t(szVal);
}
return mir_tstrdup(_T("0"));
@@ -62,71 +55,47 @@ static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) {
/*
pattern, subject, substring no (== PCRE string no (starting at 0))
*/
-static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai)
+{
const char *err, *substring;
- char *res, *arg1, *arg2, *arg3;
int erroffset, number;
int offsets[99];
- TCHAR *tres;
- if (ai->argc != 4) {
+ if (ai->argc != 4)
return NULL;
- }
- arg1 = mir_t2a(ai->targv[1]);
- arg2 = mir_t2a(ai->targv[2]);
- arg3 = mir_t2a(ai->targv[3]);
+ ptrA arg1 = mir_t2a(ai->targv[1]);
+ ptrA arg2 = mir_t2a(ai->targv[2]);
+ ptrA arg3 = mir_t2a(ai->targv[3]);
number = atoi(arg3);
- if (number < 0) {
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
+ if (number < 0)
return NULL;
- }
+
ai->flags = AIF_FALSE;
pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL);
- if (ppat == NULL) {
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
+ if (ppat == NULL)
return NULL;
- }
+
pcre_extra *extra = pcre_study(ppat, 0, &err);
int nmat = pcre_exec(ppat, extra, arg2, (int)strlen(arg2), 0, 0, offsets, 99);
- if (nmat >= 0) {
+ if (nmat >= 0)
ai->flags &= ~AIF_FALSE;
- }
- if (pcre_get_substring(arg2, offsets, nmat, number, &substring) < 0) {
+
+ if (pcre_get_substring(arg2, offsets, nmat, number, &substring) < 0)
ai->flags |= AIF_FALSE;
- }
else {
- res = mir_strdup(substring);
+ TCHAR *tres = mir_a2t(substring);
pcre_free_substring(substring);
-
-
- tres = mir_a2t(res);
-
- mir_free(res);
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
-
return tres;
}
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
return mir_tstrdup(_T(""));
}
-int registerRegExpTokens() {
-
+int registerRegExpTokens()
+{
registerIntToken(_T(REGEXPCHECK), parseRegExpCheck, TRF_FUNCTION, LPGEN("Regular Expressions")"\t(x,y)\t"LPGEN("(ANSI input only) the number of substring matches found in y with pattern x"));
registerIntToken(_T(REGEXPSUBSTR), parseRegExpSubstr, TRF_FUNCTION, LPGEN("Regular Expressions")"\t(x,y,z)\t"LPGEN("(ANSI input only) substring match number z found in subject y with pattern x"));
-
-
return 0;
} \ No newline at end of file