[asterisk-dev] [Code Review] STRREPLACE function - find and replace substrings of a superstring

jrose reviewboard at asterisk.org
Tue May 17 15:13:48 CDT 2011



> On 2011-05-17 11:52:00, Tilghman Lesher wrote:
> > 1. The reason why we generally operate on variable names instead of variable values are the various exceptions.  What happens if the input string contains commas?  Or quotation marks?  How do you ensure that the input string does not interfere with argument parsing?  When dealing with input coming from the opposite end of a VOIP connection, you have a great number of issues with ensuring the input doesn't mess with the way the function works.
> > 2. You need to look up what the Echo application actually does, because I don't think it's doing what you think it's doing.  The NoOp (or Verbose) applications are more appropriate.

Alrighty, I've addressed these.  And explained my use of echo.


- jrose


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1219/#review3562
-----------------------------------------------------------


On 2011-05-17 10:40:28, jrose wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1219/
> -----------------------------------------------------------
> 
> (Updated 2011-05-17 10:40:28)
> 
> 
> 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.
> 
> 
> 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.
> 
> 
> Thanks,
> 
> jrose
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20110517/708ecd92/attachment-0001.htm>


More information about the asterisk-dev mailing list