[asterisk-dev] [Code Review] STRREPLACE function - find and replace substrings of a superstring
David Vossel
reviewboard at asterisk.org
Fri May 20 10:59:41 CDT 2011
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1219/#review3585
-----------------------------------------------------------
Ship it!
nice!
- David
On 2011-05-17 15:13:51, jrose wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1219/
> -----------------------------------------------------------
>
> (Updated 2011-05-17 15:13:51)
>
>
> Review request for Asterisk Developers, Russell Bryant and David Vossel.
>
>
> Summary
> -------
>
> Adds a string replace function to func_strings.c as well as a test for said function.
> This is a bit different from the requested patch, but should work to accomplish the same ends.
>
> It doesn't use a variable name as one of the variables (unlike the user-submitted patch), so if you want to search from a variable, you have to specify it as one instead. I personally feel this is more flexible since this way you can get the searched on string in all kinds of ways.
>
> I did discover that spaces in dialplan mess with stuff like this though. Just something to be aware of, if it'd be a good thing to add to documentation, let me know.
>
> EDIT:
>
> The above is no longer true, and now it uses a variable name for the input string just like the reporter's patch.
>
>
> This addresses bug 18023.
> https://issues.asterisk.org/view.php?id=18023
>
>
> Diffs
> -----
>
> /trunk/funcs/func_strings.c 319115
>
> Diff: https://reviewboard.asterisk.org/r/1219/diff
>
>
> Testing
> -------
>
> As you'll see, there is an included test with a number of comment-described test scenarios.
>
> Also, this is the dialplan I used for manual testing:
>
> ;strreplace test
>
> exten => 3201,1,Answer()
> exten => 3201,n,Echo(${STRREPLACE(,"dog","cat")})
>
> exten => 3200,1,Answer()
> exten => 3200,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", "cat", 4)})
>
> exten => 3202,1,Answer()
> exten => 3202,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", "cat", 2)})
>
> exten => 3203,1,Answer()
> exten => 3203,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", "cat", 10)})
>
> exten => 3204,1,Answer()
> exten => 3204,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", "elephant", 4)})
>
> exten => 3205,1,Answer()
> exten => 3205,n,Echo(${STRREPLACE("I once knew a elephant who owned a pet elephant who had a pet elephant which ate an elephant and cooked a corn elephant.", "elephant", "cat", 4)})
>
> exten => 3206,1,Answer()
> exten => 3206,n,Echo(${STRREPLACE("", "", "")});
>
> exten => 3207,1,Answer()
> exten => 3207,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", "cat")})
>
> exten => 3208,1,Answer()
> exten => 3208,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.", "dog", ,4)})
>
> exten => 3209,1,Answer()
> exten => 3209,n,Echo(${STRREPLACE("I once knew a dog who owned a pet dog who had a pet dog which ate a dog and cooked a corn dog.",, "cat", 4)})
>
> exten => 3210,1,Answer()
> exten => 3210,n,Set( Cheese= BlahblHDFJK)
>
> exten => 3211,1,Answer()
> exten => 3211,n,Set(teststring="do re mi fa sa la ti do do mi fa re fa sal la ti do do do"
> exten => 3211,n,Set(Chowder=${STRREPLACE(${teststring},"do","dodo")})
> exten => 3211,n,Echo(Chowder = ${Chowder})
>
> exten => 3212,1,Answer()
> exten => 3212,n,Echo(${STRREPLACE("elephants have eaten my phone system.","elephants","Weasels")})
>
> exten => 3213,1,Answer()
> exten => 3213,n,Echo(${STRREPLACE("Wizards did it! They killed everyone!")})
>
> exten => 3214,1,Answer()
> exten => 3214,n,Echo(${STRREPLACE("This string needs something removed."," removed")})
>
>
> So you'll see I tested it somewhat extensively.
>
> EDIT: Yeah, I've revised some of these to make sure the functionality stayed the same and I got rid of the echos, which... I knew what they were doing, I just didn't really care that much and I liked hearing the line stall rather than hanging up... so I got in the habit of using Echo. Weird, I know.
>
> Added a new test case to the test suite for escape characters. They seem to work alright.
>
>
> Thanks,
>
> jrose
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20110520/fea79d81/attachment-0001.htm>
More information about the asterisk-dev
mailing list