Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    ree3f6f6 rb49d872  
    13601360}
    13611361
    1362 /** Split string by delimiters.
    1363  *
    1364  * @param s             String to be tokenized. May not be NULL.
    1365  * @param delim         String with the delimiters.
    1366  * @param next          Variable which will receive the pointer to the
    1367  *                      continuation of the string following the first
    1368  *                      occurrence of any of the delimiter characters.
    1369  *                      May be NULL.
    1370  * @return              Pointer to the prefix of @a s before the first
    1371  *                      delimiter character. NULL if no such prefix
    1372  *                      exists.
    1373  */
    1374 char *str_tok(char *s, const char *delim, char **next)
     1362char *strtok(char *s, const char *delim)
     1363{
     1364        static char *next;
     1365
     1366        return strtok_r(s, delim, &next);
     1367}
     1368
     1369char *strtok_r(char *s, const char *delim, char **next)
    13751370{
    13761371        char *start, *end;
    13771372
    1378         if (!s)
    1379                 return NULL;
    1380        
    1381         size_t len = str_size(s);
    1382         size_t cur;
    1383         size_t tmp;
    1384         wchar_t ch;
     1373        if (s == NULL)
     1374                s = *next;
    13851375
    13861376        /* Skip over leading delimiters. */
    1387         for (tmp = cur = 0;
    1388             (ch = str_decode(s, &tmp, len)) && str_chr(delim, ch); /**/)
    1389                 cur = tmp;
    1390         start = &s[cur];
     1377        while (*s && (str_chr(delim, *s) != NULL)) ++s;
     1378        start = s;
    13911379
    13921380        /* Skip over token characters. */
    1393         for (tmp = cur;
    1394             (ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch); /**/)
    1395                 cur = tmp;
    1396         end = &s[cur];
    1397         if (next)
    1398                 *next = (ch ? &s[tmp] : &s[cur]);
    1399 
    1400         if (start == end)
     1381        while (*s && (str_chr(delim, *s) == NULL)) ++s;
     1382        end = s;
     1383        *next = (*s ? s + 1 : s);
     1384
     1385        if (start == end) {
    14011386                return NULL;    /* No more tokens. */
     1387        }
    14021388
    14031389        /* Overwrite delimiter with NULL terminator. */
Note: See TracChangeset for help on using the changeset viewer.