X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/f3a542e864d3ae7ab34005ca968373a32249785e..e2a18bd0eda077f0920274fd114240bc786f03b1:/str.c diff --git a/str.c b/str.c index b6e4813..0defaa7 100644 --- a/str.c +++ b/str.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: str.c,v 1.2 1999/05/26 20:52:57 mdw Exp $ + * $Id: str.c,v 1.3 1999/12/22 15:41:14 mdw Exp $ * * Functions for hacking with strings * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: str.c,v $ + * Revision 1.3 1999/12/22 15:41:14 mdw + * Skip past trailing whitespace in str_getword. + * * Revision 1.2 1999/05/26 20:52:57 mdw * Add new `rest' argument for `str_split'. * @@ -71,8 +74,12 @@ char *str_getword(char **pp) for (q = p; *q; q++) { if (isspace((unsigned char)*q)) { - *q = 0; - *pp = q + 1; + *q++ = 0; + while (*q && isspace((unsigned char)*q)) + q++; + if (!*q) + q = 0; + *pp = q; return (p); } } @@ -111,24 +118,12 @@ size_t str_split(char *p, char *v[], size_t c, char **rest) c--; n++; } - while (c) { *v++ = 0; c--; } - - if (rest) { - if (!p) - *rest = 0; - else { - while (isspace((unsigned char)*p)) - p++; - if (*p) - *rest = p; - else - *rest = 0; - } - } + if (rest) + *rest = p; return (n); }