From 20af3fea1502231619a1eb5980571174c47c26d7 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Mon, 16 Apr 2007 22:32:28 +0000 Subject: [PATCH] Move some ascii_foo functions to libcompat --- include/ChangeLog | 5 ++++ include/compat.h | 4 +++ include/util.h | 4 --- util/ChangeLog | 5 ++++ util/compat.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ util/strgutil.c | 70 ----------------------------------------------- 6 files changed, 84 insertions(+), 74 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index 206d43692..ae90e47ec 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2007-04-16 David Shaw + + * util.h (ascii_toupper, ascii_tolower, ascii_strcasecmp, + ascii_strncasecmp): Move functions to compat.h. + 2006-12-11 Werner Koch * mpi.h (mpi_is_neg, mpi_get_nlimbs): Replaced macros by function diff --git a/include/compat.h b/include/compat.h index f971ffaf7..5ed139678 100644 --- a/include/compat.h +++ b/include/compat.h @@ -6,6 +6,10 @@ #define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t') int hextobyte( const char *s ); +int ascii_toupper (int c); +int ascii_tolower (int c); +int ascii_strcasecmp( const char *a, const char *b ); +int ascii_strncasecmp( const char *a, const char *b, size_t n); #ifndef HAVE_STRSEP char *strsep (char **stringp, const char *delim); diff --git a/include/util.h b/include/util.h index 265bb02c2..6269bd562 100644 --- a/include/util.h +++ b/include/util.h @@ -194,10 +194,6 @@ int check_utf8_string( const char *string ); int ascii_isupper (int c); int ascii_islower (int c); -int ascii_toupper (int c); -int ascii_tolower (int c); -int ascii_strcasecmp( const char *a, const char *b ); -int ascii_strncasecmp( const char *a, const char *b, size_t n); int ascii_memcasecmp( const char *a, const char *b, size_t n); #ifndef HAVE_STPCPY diff --git a/util/ChangeLog b/util/ChangeLog index a67547395..f6a916f53 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,8 @@ +2007-04-16 David Shaw + + * strgutil.c (ascii_toupper, ascii_tolower, ascii_strcasecmp, + ascii_strncasecmp): Move functions to compat.c. + 2007-04-16 Werner Koch * secmem.c (init_pool): Avoid assigning a negative value to a diff --git a/util/compat.c b/util/compat.c index aca558aee..cd487e5e2 100644 --- a/util/compat.c +++ b/util/compat.c @@ -1,3 +1,5 @@ +#include + int hextobyte (const char *s) { @@ -22,3 +24,71 @@ hextobyte (const char *s) return -1; return c; } + +int +ascii_toupper (int c) +{ + if (c >= 'a' && c <= 'z') + c &= ~0x20; + return c; +} + +int +ascii_tolower (int c) +{ + if (c >= 'A' && c <= 'Z') + c |= 0x20; + return c; +} + +int +ascii_strcasecmp (const char *a, const char *b) +{ + const unsigned char *p1 = (const unsigned char *)a; + const unsigned char *p2 = (const unsigned char *)b; + unsigned char c1, c2; + + if (p1 == p2) + return 0; + + do + { + c1 = ascii_tolower (*p1); + c2 = ascii_tolower (*p2); + + if (c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + return c1 - c2; +} + +int +ascii_strncasecmp (const char *a, const char *b, size_t n) +{ + const unsigned char *p1 = (const unsigned char *)a; + const unsigned char *p2 = (const unsigned char *)b; + unsigned char c1, c2; + + if (p1 == p2 || !n ) + return 0; + + do + { + c1 = ascii_tolower (*p1); + c2 = ascii_tolower (*p2); + + if ( !--n || c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + return c1 - c2; +} diff --git a/util/strgutil.c b/util/strgutil.c index 95cb0f274..9d2b15994 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -1058,76 +1058,6 @@ ascii_islower (int c) return c >= 'a' && c <= 'z'; } -int -ascii_toupper (int c) -{ - if (c >= 'a' && c <= 'z') - c &= ~0x20; - return c; -} - -int -ascii_tolower (int c) -{ - if (c >= 'A' && c <= 'Z') - c |= 0x20; - return c; -} - - -int -ascii_strcasecmp (const char *a, const char *b) -{ - const unsigned char *p1 = (const unsigned char *)a; - const unsigned char *p2 = (const unsigned char *)b; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = ascii_tolower (*p1); - c2 = ascii_tolower (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - return c1 - c2; -} - -int -ascii_strncasecmp (const char *a, const char *b, size_t n) -{ - const unsigned char *p1 = (const unsigned char *)a; - const unsigned char *p2 = (const unsigned char *)b; - unsigned char c1, c2; - - if (p1 == p2 || !n ) - return 0; - - do - { - c1 = ascii_tolower (*p1); - c2 = ascii_tolower (*p2); - - if ( !--n || c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - return c1 - c2; -} - - int ascii_memcasecmp( const char *a, const char *b, size_t n ) {