From 48be1aeb7dbd36bc7c51d49eeb72d0703de32f88 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Mon, 9 Jun 2003 20:27:14 +0000 Subject: [PATCH] - Moved strspn and strcspn to the string library. svn path=/trunk/; revision=4878 --- reactos/lib/crtdll/makefile | 4 +--- reactos/lib/msvcrt/Makefile | 4 +--- reactos/lib/msvcrt/string/strcspn.c | 19 ------------------- reactos/lib/msvcrt/string/strspn.c | 16 ---------------- reactos/lib/ntdll/makefile | 5 ++--- reactos/lib/ntdll/string/strcspn.c | 20 -------------------- reactos/lib/ntdll/string/strspn.c | 16 ---------------- reactos/lib/string/Makefile | 4 +++- reactos/lib/string/strcspn.c | 26 ++++++++++++++++++++++++++ reactos/lib/string/strspn.c | 25 +++++++++++++++++++++++++ reactos/ntoskrnl/rtl/string.c | 15 --------------- 11 files changed, 58 insertions(+), 96 deletions(-) delete mode 100644 reactos/lib/msvcrt/string/strcspn.c delete mode 100644 reactos/lib/msvcrt/string/strspn.c delete mode 100644 reactos/lib/ntdll/string/strcspn.c delete mode 100644 reactos/lib/ntdll/string/strspn.c create mode 100644 reactos/lib/string/strcspn.c create mode 100644 reactos/lib/string/strspn.c diff --git a/reactos/lib/crtdll/makefile b/reactos/lib/crtdll/makefile index 08ef0cd292a..914196714c9 100644 --- a/reactos/lib/crtdll/makefile +++ b/reactos/lib/crtdll/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.55 2003/05/27 20:01:30 hbirr Exp $ +# $Id: makefile,v 1.56 2003/06/09 20:23:06 hbirr Exp $ PATH_TO_TOP = ../.. @@ -398,7 +398,6 @@ STDLIB_OBJECTS = \ STRING_OBJECTS = \ $(PATH_TO_MSVCRT)/string/memicmp.o \ $(PATH_TO_MSVCRT)/string/strcoll.o \ - $(PATH_TO_MSVCRT)/string/strcspn.o \ $(PATH_TO_MSVCRT)/string/strdup.o \ string/strerror.o \ $(PATH_TO_MSVCRT)/string/stricmp.o \ @@ -407,7 +406,6 @@ STRING_OBJECTS = \ $(PATH_TO_MSVCRT)/string/strpbrk.o \ $(PATH_TO_MSVCRT)/string/strrev.o \ $(PATH_TO_MSVCRT)/string/strset.o \ - $(PATH_TO_MSVCRT)/string/strspn.o \ $(PATH_TO_MSVCRT)/string/strstr.o \ string/strtok.o \ $(PATH_TO_MSVCRT)/string/strupr.o \ diff --git a/reactos/lib/msvcrt/Makefile b/reactos/lib/msvcrt/Makefile index e3a78b952ed..b68b2a34b6f 100644 --- a/reactos/lib/msvcrt/Makefile +++ b/reactos/lib/msvcrt/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.35 2003/05/27 20:07:53 hbirr Exp $ +# $Id: Makefile,v 1.36 2003/06/09 20:23:06 hbirr Exp $ PATH_TO_TOP = ../.. @@ -402,7 +402,6 @@ STDLIB_OBJECTS = \ STRING_OBJECTS = \ string/memicmp.o \ string/strcoll.o \ - string/strcspn.o \ string/strdup.o \ string/strerror.o \ string/stricmp.o \ @@ -412,7 +411,6 @@ STRING_OBJECTS = \ string/strpbrk.o \ string/strrev.o\ string/strset.o \ - string/strspn.o \ string/strstr.o \ string/strtok.o \ string/strupr.o \ diff --git a/reactos/lib/msvcrt/string/strcspn.c b/reactos/lib/msvcrt/string/strcspn.c deleted file mode 100644 index db77bb707b2..00000000000 --- a/reactos/lib/msvcrt/string/strcspn.c +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -size_t strcspn(const char *s1, const char *s2) -{ - const char *p, *spanp; - char c, sc; - - for (p = s1;;) - { - c = *p++; - spanp = s2; - do { - if ((sc = *spanp++) == c) - return p - 1 - s1; - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/reactos/lib/msvcrt/string/strspn.c b/reactos/lib/msvcrt/string/strspn.c deleted file mode 100644 index f01e1bf2d3f..00000000000 --- a/reactos/lib/msvcrt/string/strspn.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -size_t -strspn(const char *s1, const char *s2) -{ - const char *p = s1, *spanp; - char c, sc; - - cont: - c = *p++; - for (spanp = s2; (sc = *spanp++) != 0;) - if (sc == c) - goto cont; - return (p - 1 - s1); -} diff --git a/reactos/lib/ntdll/makefile b/reactos/lib/ntdll/makefile index 810e03fa83d..55adaa62b14 100644 --- a/reactos/lib/ntdll/makefile +++ b/reactos/lib/ntdll/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.85 2003/06/07 11:33:13 ekohl Exp $ +# $Id: makefile,v 1.86 2003/06/09 20:23:06 hbirr Exp $ PATH_TO_TOP = ../.. @@ -55,11 +55,10 @@ STDLIB_OBJECTS = stdlib/abs.o stdlib/atoi.o stdlib/atoi64.o stdlib/atol.o \ STRING_OBJECTS = string/ctype.o \ string/memicmp.o\ - string/strcspn.o \ string/stricmp.o \ string/strlwr.o \ string/strnicmp.o \ - string/strpbrk.o string/strspn.o \ + string/strpbrk.o \ string/strstr.o string/strupr.o string/wstring.o ARCH_OBJECTS = \ diff --git a/reactos/lib/ntdll/string/strcspn.c b/reactos/lib/ntdll/string/strcspn.c deleted file mode 100644 index 7e17b21976a..00000000000 --- a/reactos/lib/ntdll/string/strcspn.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -size_t -strcspn(const char *s1, const char *s2) -{ - const char *p, *spanp; - char c, sc; - - for (p = s1;;) - { - c = *p++; - spanp = s2; - do { - if ((sc = *spanp++) == c) - return p - 1 - s1; - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/reactos/lib/ntdll/string/strspn.c b/reactos/lib/ntdll/string/strspn.c deleted file mode 100644 index 1532db001db..00000000000 --- a/reactos/lib/ntdll/string/strspn.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -size_t -strspn(const char *s1, const char *s2) -{ - const char *p = s1, *spanp; - char c, sc; - - cont: - c = *p++; - for (spanp = s2; (sc = *spanp++) != 0;) - if (sc == c) - goto cont; - return (p - 1 - s1); -} diff --git a/reactos/lib/string/Makefile b/reactos/lib/string/Makefile index 7810cd0fb96..34711bd9581 100644 --- a/reactos/lib/string/Makefile +++ b/reactos/lib/string/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 2003/06/01 19:23:18 hbirr Exp $ +# $Id: Makefile,v 1.4 2003/06/09 20:23:06 hbirr Exp $ PATH_TO_TOP = ../.. @@ -29,12 +29,14 @@ TARGET_OBJECTS = \ strchr.o \ strcmp.o \ strcpy.o \ + strcspn.o \ strlen.o \ strncat.o \ strncmp.o \ strncpy.o \ strnlen.o \ strrchr.o \ + strspn.o \ wcscat.o \ wcschr.o \ wcscmp.o \ diff --git a/reactos/lib/string/strcspn.c b/reactos/lib/string/strcspn.c new file mode 100644 index 00000000000..d8592d08ca8 --- /dev/null +++ b/reactos/lib/string/strcspn.c @@ -0,0 +1,26 @@ +/* + * $Id: strcspn.c,v 1.1 2003/06/09 20:23:06 hbirr Exp $ + */ + +#include + +size_t strcspn(const char *s1, const char *s2) +{ + unsigned long char_map[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + register unsigned char* str = (unsigned char*)s1; + + while (*s2) + { + char_map[*(unsigned char*)s2 / 32] |= (1 << (*(unsigned char*)s2 % 32)); + s2++; + } + + while (*str) + { + if (char_map[*str / 32] & (1 << (*str % 32))) + break; + str++; + } + + return str - (unsigned char*)s1; +} diff --git a/reactos/lib/string/strspn.c b/reactos/lib/string/strspn.c new file mode 100644 index 00000000000..6f4f237f39c --- /dev/null +++ b/reactos/lib/string/strspn.c @@ -0,0 +1,25 @@ +/* + * $Id: strspn.c,v 1.1 2003/06/09 20:23:06 hbirr Exp $ + */ + +#include + +size_t strspn(const char *s1, const char *s2) +{ + unsigned long char_map[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + register unsigned char* str = (unsigned char*)s1; + + while (*s2) + { + char_map[*(unsigned char*)s2 / 32] |= (1 << (*(unsigned char*)s2 % 32)); + s2++; + } + + while (*str) + { + if (!(char_map[*str / 32] & (1 << (*str % 32)))) + break; + str++; + } + return str - (unsigned char*)s1; +} diff --git a/reactos/ntoskrnl/rtl/string.c b/reactos/ntoskrnl/rtl/string.c index 12b36278ec1..cc6af9bc372 100644 --- a/reactos/ntoskrnl/rtl/string.c +++ b/reactos/ntoskrnl/rtl/string.c @@ -117,21 +117,6 @@ char *_strupr(char *x) return x; } -size_t strspn(const char *s1, const char *s2) -{ - const char *p = s1, *spanp; - char c, sc; - - cont: - c = *p++; - for (spanp = s2; (sc = *spanp++) != 0;) - if (sc == c) - goto cont; - - return (p - 1 - s1); -} - - char *strstr(const char *s, const char *find) { char c, sc;