mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
Merged revisions 336789 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/10 ........ r336789 | tilghman | 2011-09-19 16:41:16 -0500 (Mon, 19 Sep 2011) | 2 lines Ensure substring will not be found in the previous match. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@336790 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -923,7 +923,8 @@ static int strreplace(struct ast_channel *chan, const char *cmd, char *data, str
|
||||
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 @@ static int strreplace(struct ast_channel *chan, const char *cmd, char *data, str
|
||||
|
||||
/* 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, len, "%s", args.replace_string);
|
||||
}
|
||||
ast_str_append(buf, 0, "%s", p);
|
||||
ast_str_append(buf, len, "%s", p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1762,6 +1763,7 @@ AST_TEST_DEFINE(test_STRREPLACE)
|
||||
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 */
|
||||
|
Reference in New Issue
Block a user