SYNOPSIS
#include
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
DESCRIPTION
strspn and
strcspn calculate the initial length of a segment of
s.
strspn calculates the length of the segment which contains only characters in
accept, while
strcspn calculates the length of the segment which contains only characters
not in
reject.
NOTES
This is an
input validation function made in heaven. Want to see if a string contains
bad characters? Use this!
Say you write a CGI in C (a rare event these days, but bear with me), and you want to prevent people from putting in ../'s and the like. Just put a / in the reject parameter, and maybe a ., and call strcspn on the input!
The possibilities are endless, and if the length of reject or accept parameters gets really long (>128 bytes), then just switch functions...(assuming ASCII characters)
Part of the str functions list.