[asterisk-dev] [Code Review] 3989: utils: Create ast_strsep function that ignores separators inside quotes.

Mark Michelson reviewboard at asterisk.org
Fri Sep 12 13:50:21 CDT 2014


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


In general, have a look at coding guidelines violations. In particular, I noticed a few binary operators (e.g. + and +=) did not have spaces surrounding them.


branches/12/include/asterisk/strings.h
<https://reviewboard.asterisk.org/r/3989/#comment23771>

    2 things:
    
    1) The comment says to unescape '/' but it should say to unescape '\'
    2) This line, compared to surrounding lines has spacing differences on reviewboard. This is likely because you have used tabs after the = signs instead of spaces.



branches/12/main/utils.c
<https://reviewboard.asterisk.org/r/3989/#comment23772>

    If a string ends with a backslash, then this will push is past the end of the string and likely lead to a segfault.


- Mark Michelson


On Sept. 12, 2014, 6:12 a.m., George Joseph wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/3989/
> -----------------------------------------------------------
> 
> (Updated Sept. 12, 2014, 6:12 a.m.)
> 
> 
> Review request for Asterisk Developers and rmudgett.
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> I'm going to need this for my imminent manager and config
> enhancements but I thought I'd post this separately.
> 
> /*!
>   \brief Act like strsep but ignore separators inside quotes.
>   \param s Pointer to address of the the string to be processed.
>   Will be modified and can't be constant.
>   \param sep A single character delimiter.
>   \param flags controls whitespace and quote stripping.
>   \return The next token or NULL if done.
> 
>   This function acts like strsep with three exceptions...
>   The separator is a single character instead of a string.
>   Separators inside quotes are treated literally instead of like separators.
>   You can elect to have leading and trailing whitespace and quotes
>   stripped from the result.
> 
>   Like strsep, ast_strsep maintains no internal state and you can call it
>   recursively using different separators on the same storage.
> 
>   Also like strsep, for consistent results, consecutive separators are not
>   collapsed so you may get an empty string as a valid result.
> 
>   Examples:
>   \code
> 	char *mystr = ast_strdupa("abc=def,ghi='zzz=yyy,456',jkl");
> 	char *token, *token2, *token3;
> 
> 	while((token = ast_strsep(&mystr, ',', AST_SEP_STRIP))) {
> 		// 1st token will be aaa=def
> 		// 2nd token will be ghi='zzz=yyy,456'
> 		while((token2 = ast_strsep(&token, '=', AST_SEP_STRIP))) {
> 			// 1st token2 will be ghi
> 			// 2nd token2 will be zzz=yyy,456
> 			while((token3 = ast_strsep(&token2, ',', AST_SEP_STRIP))) {
> 				// 1st token3 will be zzz=yyy
> 				// 2nd token3 will be 456
> 				// and so on
> 			}
> 		}
> 		// 3rd token will be jkl
> 	}
> 
>   \endcode
>  */
> char *ast_strsep(char **s, const char sep, enum ast_strsep_flags flags);
> 
> 
> Diffs
> -----
> 
>   branches/12/tests/test_strings.c 422963 
>   branches/12/main/utils.c 422963 
>   branches/12/include/asterisk/strings.h 422963 
> 
> Diff: https://reviewboard.asterisk.org/r/3989/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> George Joseph
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20140912/ca67bcc3/attachment-0001.html>


More information about the asterisk-dev mailing list