[asterisk-commits] tilghman: branch 10 r336789 - /branches/10/funcs/func_strings.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Sep 19 16:41:18 CDT 2011
Author: tilghman
Date: Mon Sep 19 16:41:16 2011
New Revision: 336789
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=336789
Log:
Ensure substring will not be found in the previous match.
Modified:
branches/10/funcs/func_strings.c
Modified: branches/10/funcs/func_strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/funcs/func_strings.c?view=diff&rev=336789&r1=336788&r2=336789
==============================================================================
--- branches/10/funcs/func_strings.c (original)
+++ branches/10/funcs/func_strings.c Mon Sep 19 16:41:16 2011
@@ -923,7 +923,8 @@
for (x = 0; x < max_matches; x++) {
if ((p = strstr(p, args.find_string))) {
starts[count_len++] = p;
- *p++ = '\0';
+ *p = '\0';
+ p += find_size;
} else {
break;
}
@@ -933,12 +934,12 @@
/* here we rebuild the string with the replaced words by using fancy ast_string_append on the buffer */
for (x = 0; x < count_len; x++) {
- ast_str_append(buf, 0, "%s", p);
+ ast_str_append(buf, len, "%s", p);
p = starts[x];
p += find_size;
- ast_str_append(buf, 0, "%s", args.replace_string);
- }
- ast_str_append(buf, 0, "%s", p);
+ ast_str_append(buf, len, "%s", args.replace_string);
+ }
+ ast_str_append(buf, len, "%s", p);
return 0;
}
@@ -1762,6 +1763,7 @@
const char *test_strings[][5] = {
{"Weasels have eaten my telephone system", "have eaten my", "are eating our", "", "Weasels are eating our telephone system"}, /*Test normal conditions */
{"Did you know twenty plus two is twenty-two?", "twenty", "thirty", NULL, "Did you know thirty plus two is thirty-two?"}, /* Test no third comma */
+ {"foofoofoofoofoofoofoo", "foofoo", "bar", NULL, "barbarbarfoo"}, /* Found string within previous match */
{"My pet dog once ate a dog who sat on a dog while eating a corndog.", "dog", "cat", "3", "My pet cat once ate a cat who sat on a cat while eating a corndog."},
{"One and one and one is three", "and", "plus", "1", "One plus one and one is three"}, /* Test <max-replacements> = 1*/
{"", "fhqwagads", "spelunker", NULL, ""}, /* Empty primary string */
More information about the asterisk-commits
mailing list