|
|
1.1 ! root 1: /* ! 2: * strspn.c -- ! 3: * ! 4: * Source code for the "strspn" library routine. ! 5: * ! 6: * Copyright 1988 Regents of the University of California ! 7: * Permission to use, copy, modify, and distribute this ! 8: * software and its documentation for any purpose and without ! 9: * fee is hereby granted, provided that the above copyright ! 10: * notice appear in all copies. The University of California ! 11: * makes no representations about the suitability of this ! 12: * software for any purpose. It is provided "as is" without ! 13: * express or implied warranty. ! 14: */ ! 15: ! 16: #ifndef lint ! 17: static char rcsid[] = "$Header: /sprite/src/lib/c/string/RCS/strspn.c,v 1.2 89/03/22 16:07:53 rab Exp $ SPRITE (Berkeley)"; ! 18: #endif /* not lint */ ! 19: ! 20: #include <string.h> ! 21: ! 22: /* ! 23: *---------------------------------------------------------------------- ! 24: * ! 25: * strspn -- ! 26: * ! 27: * Compute the length of the maximum initial segment of "string" ! 28: * whose characters all are in "chars". ! 29: * ! 30: * Results: ! 31: * The return value is the length of the initial segment (0 if the ! 32: * first character isn't in "chars". ! 33: * ! 34: * Side effects: ! 35: * None. ! 36: * ! 37: *---------------------------------------------------------------------- ! 38: */ ! 39: ! 40: int ! 41: strspn(string, chars) ! 42: char *string; /* String to search. */ ! 43: char *chars; /* Characters to look for in string. */ ! 44: { ! 45: register char c, *p, *s; ! 46: ! 47: for (s = string, c = *s; c != 0; s++, c = *s) { ! 48: for (p = chars; *p != 0; p++) { ! 49: if (c == *p) { ! 50: goto next; ! 51: } ! 52: } ! 53: break; ! 54: next: ; ! 55: } ! 56: return s-string; ! 57: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.