]> git.saurik.com Git - bison.git/blame - lib/strspn.c
* doc/bison.texinfo (Debugging): Split into...
[bison.git] / lib / strspn.c
CommitLineData
53b74c0c
AD
1/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
2
3 NOTE: The canonical source of this file is maintained with the GNU
4 C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License
8 as published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with this program; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place -
19 Suite 330, Boston, MA 02111-1307, USA. */
20
21#if HAVE_CONFIG_H
22# include <config.h>
23#endif
24
25#if defined _LIBC || HAVE_STRING_H
26# include <string.h>
27#else
28# include <strings.h>
29# ifndef strchr
30# define strchr index
31# endif
32#endif
33
34#undef strspn
35
36/* Return the length of the maximum initial segment
37 of S which contains only characters in ACCEPT. */
38size_t
39strspn (s, accept)
40 const char *s;
41 const char *accept;
42{
43 const char *p;
44 const char *a;
45 size_t count = 0;
46
47 for (p = s; *p != '\0'; ++p)
48 {
49 for (a = accept; *a != '\0'; ++a)
50 if (*p == *a)
51 break;
52 if (*a == '\0')
53 return count;
54 else
55 ++count;
56 }
57
58 return count;
59}