1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251875Speter * contributor license agreements.  See the NOTICE file distributed with
3251875Speter * this work for additional information regarding copyright ownership.
4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251875Speter * (the "License"); you may not use this file except in compliance with
6251875Speter * the License.  You may obtain a copy of the License at
7251875Speter *
8251875Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251875Speter *
10251875Speter * Unless required by applicable law or agreed to in writing, software
11251875Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251875Speter * See the License for the specific language governing permissions and
14251875Speter * limitations under the License.
15251875Speter */
16251875Speter
17251875Speter#ifdef HAVE_STDDEF_H
18251875Speter#include <stddef.h>        /* for NULL */
19251875Speter#endif
20251875Speter
21251875Speter#include "apr.h"
22251875Speter#include "apr_strings.h"
23251875Speter
24251875Speter#define APR_WANT_STRFUNC   /* for strchr() */
25251875Speter#include "apr_want.h"
26251875Speter
27251875SpeterAPR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last)
28251875Speter{
29251875Speter    char *token;
30251875Speter
31251875Speter    if (!str)           /* subsequent call */
32251875Speter        str = *last;    /* start where we left off */
33251875Speter
34251875Speter    /* skip characters in sep (will terminate at '\0') */
35251875Speter    while (*str && strchr(sep, *str))
36251875Speter        ++str;
37251875Speter
38251875Speter    if (!*str)          /* no more tokens */
39251875Speter        return NULL;
40251875Speter
41251875Speter    token = str;
42251875Speter
43251875Speter    /* skip valid token characters to terminate token and
44251875Speter     * prepare for the next call (will terminate at '\0)
45251875Speter     */
46251875Speter    *last = token + 1;
47251875Speter    while (**last && !strchr(sep, **last))
48251875Speter        ++*last;
49251875Speter
50251875Speter    if (**last) {
51251875Speter        **last = '\0';
52251875Speter        ++*last;
53251875Speter    }
54251875Speter
55251875Speter    return token;
56251875Speter}
57