X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrspn.c;h=55cf29a084aa87f8ae2e5b2f8522b99e2f8a70d7;hp=6b0e586b79f661152d774d7ccbb1c28888649628;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f diff --git a/functions/string/strspn.c b/functions/string/strspn.c index 6b0e586..55cf29a 100644 --- a/functions/string/strspn.c +++ b/functions/string/strspn.c @@ -1,29 +1,32 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* ---------------------------------------------------------------------------- + * $Id$ + * ---------------------------------------------------------------------------- + * Public Domain C Library - http://pdclib.sourceforge.net + * This code is Public Domain. Use, modify, and redistribute at will. + * --------------------------------------------------------------------------*/ -size_t strspn( const char * s1, const char * s2 ) { /* TODO */ }; +#include <__size_t.h> -/* PDPC code - unreviewed +size_t strspn( const char * src_1, const char * src_2 ) { - const char *p1; - const char *p2; - - p1 = s1; - while (*p1 != '\0') + size_t len = 0; + const char * p; + while ( src_1[ len ] != '\0' ) { - p2 = s2; - while (*p2 != '\0') + p = src_2; + while ( *p != '\0' ) { - if (*p1 == *p2) break; - p2++; + if ( *src_1 == *p ) + { + break; + } + ++p; } - if (*p2 == '\0') return ((size_t)(p1 - s1)); - p1++; + if ( *p == '\0' ) + { + return len; + } + ++len; } - return ((size_t)(p1 - s1)); + return len; } -*/