]> pd.if.org Git - pdclib/blobdiff - functions/string/strspn.c
Added search functions.
[pdclib] / functions / string / strspn.c
diff --git a/functions/string/strspn.c b/functions/string/strspn.c
new file mode 100644 (file)
index 0000000..d58ec9e
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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 <string.h>
+
+size_t strspn( const char * s1, const char * s2 )
+{
+    size_t len = 0;
+    const char * p;
+    while ( s1[ len ] )
+    {
+        p = s2;
+        while ( *p )
+        {
+            if ( s1[len] == *p )
+            {
+                break;
+            }
+            ++p;
+        }
+        if ( ! *p )
+        {
+            return len;
+        }
+        ++len;
+    }
+    return len;
+}