/src/ghostpdl/base/gsstrtok.c
Line | Count | Source |
1 | | /* Licensed to the Apache Software Foundation (ASF) under one or more |
2 | | * contributor license agreements. See the NOTICE file distributed with |
3 | | * this work for additional information regarding copyright ownership. |
4 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
5 | | * (the "License"); you may not use this file except in compliance with |
6 | | * the License. You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | /* From: https://svn.apache.org/repos/asf/apr/apr/trunk/strings/apr_strtok.c */ |
17 | | /* with changes to work in Ghostscript */ |
18 | | |
19 | | #include "string_.h" |
20 | | #include "gsstrtok.h" |
21 | | |
22 | | #define APR_DECLARE(X) static X |
23 | | |
24 | | APR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last) |
25 | 139k | { |
26 | 139k | char *token; |
27 | | |
28 | 139k | if (!str) /* subsequent call */ |
29 | 92.8k | str = *last; /* start where we left off */ |
30 | | |
31 | | /* skip characters in sep (will terminate at '\0') */ |
32 | 139k | while (*str && strchr(sep, *str)) |
33 | 3 | ++str; |
34 | | |
35 | 139k | if (!*str) /* no more tokens */ |
36 | 49 | return NULL; |
37 | | |
38 | 139k | token = str; |
39 | | |
40 | | /* skip valid token characters to terminate token and |
41 | | * prepare for the next call (will terminate at '\0) |
42 | | */ |
43 | 139k | *last = token + 1; |
44 | 1.29M | while (**last && !strchr(sep, **last)) |
45 | 1.15M | ++*last; |
46 | | |
47 | 139k | if (**last) { |
48 | 139k | **last = '\0'; |
49 | 139k | ++*last; |
50 | 139k | } |
51 | | |
52 | 139k | return token; |
53 | 139k | } |
54 | | |
55 | | char * gs_strtok(char *str, const char *sep, char **last) |
56 | 139k | { |
57 | 139k | return apr_strtok(str, sep, last); |
58 | 139k | } |