X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrspn.c;h=db527e0198aca7bd9f2d40159883061fdab74135;hb=c0169638bd02098717cb23fbbca3bcc4e4caccf0;hp=6b0e586b79f661152d774d7ccbb1c28888649628;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f;p=pdclib diff --git a/functions/string/strspn.c b/functions/string/strspn.c index 6b0e586..db527e0 100644 --- a/functions/string/strspn.c +++ b/functions/string/strspn.c @@ -1,29 +1,37 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* $Id$ */ -size_t strspn( const char * s1, const char * s2 ) { /* TODO */ }; +/* Release $Name$ */ -/* PDPC code - unreviewed +/* strspn( const char *, const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +size_t strspn( const char * s1, const char * s2 ) { - const char *p1; - const char *p2; - - p1 = s1; - while (*p1 != '\0') + size_t len = 0; + const char * p; + while ( s1[ len ] ) { - p2 = s2; - while (*p2 != '\0') + p = s2; + while ( *p ) { - if (*p1 == *p2) break; - p2++; + if ( s1[len] == *p ) + { + break; + } + ++p; } - if (*p2 == '\0') return ((size_t)(p1 - s1)); - p1++; + if ( ! *p ) + { + return len; + } + ++len; } - return ((size_t)(p1 - s1)); + return len; } -*/ + +#warning Test driver missing.