[Freeswitch-trunk] [commit] r6254 - freeswitch/trunk/src

Freeswitch SVN anthm at freeswitch.org
Wed Nov 14 09:18:25 EST 2007


Author: anthm
Date: Wed Nov 14 09:18:24 2007
New Revision: 6254

Modified:
   freeswitch/trunk/src/switch_regex.c

Log:
add opts to regex

Modified: freeswitch/trunk/src/switch_regex.c
==============================================================================
--- freeswitch/trunk/src/switch_regex.c	(original)
+++ freeswitch/trunk/src/switch_regex.c	Wed Nov 14 09:18:24 2007
@@ -61,20 +61,40 @@
 	int erroffset = 0;
 	pcre *re = NULL;
 	int match_count = 0;
+	char *tmp = NULL;
+	uint32_t flags = 0;
 
 	if (!(field && expression)) {
 		return 0;
 	}
 
+	if (*expression == '/' && *(expression + (strlen(expression) - 1)) == '/') {
+		char *opts = NULL;
+		tmp = strdup(expression + 1);
+		assert(tmp);
+		if ((opts = strrchr(tmp, '/'))) {
+			*opts++ = '\0';
+		}
+		expression = tmp;
+		if (opts) {
+			if (strchr(opts, 'i')) {
+				flags |= PCRE_CASELESS;
+			}
+			if (strchr(opts, 's')) {
+				flags |= PCRE_DOTALL;
+			}
+		}
+	}
+
 	re = pcre_compile(expression,	/* the pattern */
-					  0,		/* default options */
+					  flags,		/* default options */
 					  &error,	/* for error message */
 					  &erroffset,	/* for error offset */
 					  NULL);	/* use default character tables */
 	if (error) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
 		switch_regex_safe_free(re);
-		return 0;
+		goto end;
 	}
 
 	match_count = pcre_exec(re,	/* result of pcre_compile() */
@@ -93,6 +113,8 @@
 
 	*new_re = (switch_regex_t *) re;
 
+ end:
+	switch_safe_free(tmp);
 	return match_count;
 }
 



More information about the Freeswitch-trunk mailing list