X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrspn.c;h=a546e94f45ce9cd6c0e74e5b828b3472eb314788;hb=3309ec3ad8a5db735eaa2de7f5dc6a331d8e7319;hp=6b0e586b79f661152d774d7ccbb1c28888649628;hpb=e5456e3c2697c4e17fc9aa3439f2e305517b4d96;p=pdclib.old diff --git a/functions/string/strspn.c b/functions/string/strspn.c index 6b0e586..a546e94 100644 --- a/functions/string/strspn.c +++ b/functions/string/strspn.c @@ -1,29 +1,49 @@ -// ---------------------------------------------------------------------------- -// $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 */ }; +/* strspn( const char *, const char * ) -/* PDPC code - unreviewed + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +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 ( s1[len] == *p ) + { + break; + } + ++p; + } + if ( ! *p ) { - if (*p1 == *p2) break; - p2++; + return len; } - if (*p2 == '\0') return ((size_t)(p1 - s1)); - p1++; + ++len; } - return ((size_t)(p1 - s1)); + return len; } -*/ + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( strspn( abcde, "abc" ) == 3 ); + TESTCASE( strspn( abcde, "b" ) == 0 ); + TESTCASE( strspn( abcde, abcde ) == 5 ); + return TEST_RESULTS; +} +#endif