On 02/13/2011 11:18 PM, Graham Leggett wrote:
> On 13 Feb 2011, at 5:22 PM, Ruediger Pluem wrote:
> 
>>> +    /* skip characters in sep (will terminate at '\0') */
>>> +    while (*str && strchr(sep, *str)) {
>>> +        ++str;
>>> +    }
>>> +
>>> +    if (!*str) {        /* no more tokens */
>>> +        return NULL;
>>> +    }
>>> +
>>> +    token = str;
>>> +
>>> +    /* skip valid token characters to terminate token and
>>> +     * prepare for the next call (will terminate at '\0)
>>> +     * on the way, ignore all quoted strings, and within
>>> +     * quoted strings, escaped characters.
>>> +     */
>>> +    *last = token + 1;
>>
>> What happens if str is supplied as "a, b"?
>> I mean why token + 1 and not token?
> 
> I guess it's because we know *token isn't a separator, so there is no
> point checking if it is one a second time.

*token might not be a separator, but it might be ".

> 
> The same pattern exists in apr_strtok.c:
> 
> https://svn.apache.org/repos/asf/apr/apr/trunk/strings/apr_strtok.c

Maybe, but that doesn't mean that it is correct :-).

IMHO "a, b" would result in the two tokens

a
b"

which would be wrong. The result should be one token:

"a, b"


Regards

RĂ¼diger

Reply via email to