1 /* splitstring.c -- split a const string into fields.
2 Copyright (C) 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Written by James Youngman.
20 /* config.h must be included first. */
27 /* gnulib headers would go here. */
30 #include "splitstring.h"
33 field_length (const char *str, const char *separators)
35 /* if there are no separators, the whole input is one field. */
38 const char *end = strpbrk (str, separators);
47 splitstring(const char *s, const char *separators, bool first,
48 size_t *pos, size_t *len)
57 *pos += *len; /* advance to the next field. */
59 ++*pos; /* skip the separator */
61 return false; /* we reached the end. */
63 *len = field_length (&s[*pos], separators);