]> pd.if.org Git - pdclib/commitdiff
Added search functions.
authorsolar <unknown>
Sun, 9 Jan 2005 13:49:21 +0000 (13:49 +0000)
committersolar <unknown>
Sun, 9 Jan 2005 13:49:21 +0000 (13:49 +0000)
functions/string/strpbrk.c [new file with mode: 0644]
functions/string/strrchr.c [new file with mode: 0644]
functions/string/strspn.c [new file with mode: 0644]
functions/string/strstr.c [new file with mode: 0644]

diff --git a/functions/string/strpbrk.c b/functions/string/strpbrk.c
new file mode 100644 (file)
index 0000000..8926cc8
--- /dev/null
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* strpbrk( 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>
+
+char * strpbrk( const char * s1, const char * s2 )
+{
+    const char * p1 = s1;
+    const char * p2;
+    while ( *p1 )
+    {
+        p2 = s2;
+        while ( *p2 )
+        {
+            if ( *p1 == *p2++ )
+            {
+                return (char *) p1;
+            }
+        }
+        ++p1;
+    }
+    return NULL;
+}
diff --git a/functions/string/strrchr.c b/functions/string/strrchr.c
new file mode 100644 (file)
index 0000000..8ad992a
--- /dev/null
@@ -0,0 +1,25 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* strrchr( const char *, int c )
+
+   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>
+
+char * strrchr( const char * s, int c )
+{
+    size_t i = 0;
+    while ( p[i++] );
+    do
+    {
+        if ( p[--i] == (char) c )
+        {
+            return (char *) p + i;
+        }
+    } while ( i );
+    return NULL;
+}
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;
+}
diff --git a/functions/string/strstr.c b/functions/string/strstr.c
new file mode 100644 (file)
index 0000000..fc5950d
--- /dev/null
@@ -0,0 +1,33 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* strstr( 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>
+
+char * strstr( const char * s1, const char * s2 )
+{
+    const char * p1 = s1;
+    const char * p2;
+    while ( *s1 )
+    {
+        p2 = s2;
+        while ( *p2 && ( *p1 == *p2 ) )
+        {
+            ++p1;
+            ++p2;
+        }
+        if ( ! *p2 )
+        {
+            return (char *) s1;
+        }
+        ++s1;
+        p1 = s1;
+    }
+    return NULL;
+}