2009-04-23 Mike Burgess <wizardsguild@earthlink.net>

* libc/string/strcasecmp.c: Optimized rewrite.
        * libc/string/strncasecmp.c: Fix description.
        * libc/string/strlwr.c: Avoid passing signed char to tolower.
        * libc/string/strupr.c: Avoid passing signed char to tolower.
This commit is contained in:
Jeff Johnston 2009-04-23 18:11:22 +00:00
parent bbb9d4fde3
commit 5921804481
5 changed files with 33 additions and 29 deletions

View File

@ -1,3 +1,10 @@
2009-04-23 Mike Burgess <wizardsguild@earthlink.net>
* libc/string/strcasecmp.c: Optimized rewrite.
* libc/string/strncasecmp.c: Fix description.
* libc/string/strlwr.c: Avoid passing signed char to tolower.
* libc/string/strupr.c: Avoid passing signed char to tolower.
2009-04-23 Paul Brook <paul@codesourcery.com> 2009-04-23 Paul Brook <paul@codesourcery.com>
Kazu Hirata <kazu@codesourcery.com> Kazu Hirata <kazu@codesourcery.com>

View File

@ -22,7 +22,7 @@ DESCRIPTION
RETURNS RETURNS
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
both are converted to uppercase), <<strcasecmp>> returns a both are converted to lowercase), <<strcasecmp>> returns a
number greater than zero. If the two strings match, number greater than zero. If the two strings match,
<<strcasecmp>> returns zero. If <<*<[a]>>> sorts <<strcasecmp>> returns zero. If <<*<[a]>>> sorts
lexicographically before <<*<[b]>>>, <<strcasecmp>> returns a lexicographically before <<*<[b]>>>, <<strcasecmp>> returns a
@ -46,11 +46,15 @@ _DEFUN (strcasecmp, (s1, s2),
_CONST char *s1 _AND _CONST char *s1 _AND
_CONST char *s2) _CONST char *s2)
{ {
while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) _CONST unsigned char *ucs1 = (_CONST unsigned char *) s1;
_CONST unsigned char *ucs2 = (_CONST unsigned char *) s2;
int d = 0;
for ( ; ; )
{ {
s1++; _CONST int c1 = tolower(*ucs1++);
s2++; _CONST int c2 = tolower(*ucs2++);
if (((d = c1 - c2) != 0) || (c2 == '\0'))
break;
} }
return d;
return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
} }

View File

@ -34,17 +34,13 @@ QUICKREF
#include <ctype.h> #include <ctype.h>
char * char *
strlwr (a) _DEFUN (strlwr, (s),
char *a; char *s)
{ {
char *ret = a; unsigned char *ucs = (unsigned char *) s;
for ( ; *ucs != '\0'; ucs++)
while (*a != '\0')
{ {
if (isupper (*a)) *ucs = tolower(*ucs);
*a = tolower (*a);
++a;
} }
return s;
return ret;
} }

View File

@ -24,7 +24,7 @@ DESCRIPTION
RETURNS RETURNS
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
both are converted to uppercase), <<strncasecmp>> returns a both are converted to lowercase), <<strncasecmp>> returns a
number greater than zero. If the two strings are equivalent, number greater than zero. If the two strings are equivalent,
<<strncasecmp>> returns zero. If <<*<[a]>>> sorts <<strncasecmp>> returns zero. If <<*<[a]>>> sorts
lexicographically before <<*<[b]>>>, <<strncasecmp>> returns a lexicographically before <<*<[b]>>>, <<strncasecmp>> returns a

View File

@ -27,23 +27,20 @@ PORTABILITY
<<strupr>> requires no supporting OS subroutines. <<strupr>> requires no supporting OS subroutines.
QUICKREF QUICKREF
strupr */ strupr
*/
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
char * char *
strupr (a) _DEFUN (strupr, (s),
char *a; char *s)
{ {
char *ret = a; unsigned char *ucs = (unsigned char *) s;
for ( ; *ucs != '\0'; ucs++)
while (*a != '\0')
{ {
if (islower (*a)) *ucs = toupper(*ucs);
*a = toupper (*a);
++a;
} }
return s;
return ret;
} }