make next_arg() more readable & efficient

This commit is contained in:
Oswald Buddenhagen 2013-09-25 18:53:18 +02:00
parent 3ceb553102
commit c0bf867669

View File

@ -458,33 +458,37 @@ imap_refcounted_done_box( imap_store_t *ctx ATTR_UNUSED, struct imap_cmd *cmd, i
} }
static char * static char *
next_arg( char **s ) next_arg( char **ps )
{ {
char *ret; char *ret, *s;
if (!s || !*s) assert( ps );
s = *ps;
if (!s)
return 0; return 0;
while (isspace( (unsigned char) **s )) while (isspace( (unsigned char)*s ))
(*s)++; s++;
if (!**s) { if (!*s) {
*s = 0; *ps = 0;
return 0; return 0;
} }
if (**s == '"') { if (*s == '"') {
++*s; ++s;
ret = *s; ret = s;
*s = strchr( *s, '"' ); s = strchr( s, '"' );
} else { } else {
ret = *s; ret = s;
while (**s && !isspace( (unsigned char) **s )) while (*s && !isspace( (unsigned char)*s ))
(*s)++; s++;
} }
if (*s) { if (s) {
if (**s) if (*s)
*(*s)++ = 0; *s++ = 0;
if (!**s) if (!*s)
*s = 0; s = 0;
} }
*ps = s;
return ret; return ret;
} }