diff options
Diffstat (limited to '')
-rw-r--r-- | jnlib/ChangeLog | 5 | ||||
-rw-r--r-- | jnlib/stringhelp.c | 73 | ||||
-rw-r--r-- | jnlib/stringhelp.h | 9 |
3 files changed, 87 insertions, 0 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index b9a1c2bb..93253685 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,8 @@ +2001-07-19 Werner Koch <[email protected]> + + * stringhelp.c (ascii_memistr,ascii_isupper,ascii_islower, + ascii_toupper,ascii_tolower, ascii_strcasecmp, ascii_memcasecmp): New. + 2000-07-26 10:02:51 Werner Koch ([email protected]) * stringhelp.c.: Add stdarg.h diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index f222a627..0d3035e8 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -264,6 +264,79 @@ compare_filenames( const char *a, const char *b ) } +/**************************************************** + ******** locale insensitive ctype functions ******** + ****************************************************/ +/* FIXME: replace them by a table lookup and macros */ +int +ascii_isupper (int c) +{ + return c >= 'A' && c <= 'Z'; +} + +int +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 ) +{ + if (a == b) + return 0; + + for (; *a && *b; a++, b++) { + if (*a != *b && ascii_toupper(*a) != ascii_toupper(*b)) + break; + } + return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); +} + +int +ascii_memcasecmp( const char *a, const char *b, size_t n ) +{ + if (a == b) + return 0; + for ( ; n; n--, a++, b++ ) { + if( *a != *b && ascii_toupper (*a) != ascii_toupper (*b) ) + return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); + } + return 0; +} + +int +ascii_strcmp( const char *a, const char *b ) +{ + if (a == b) + return 0; + + for (; *a && *b; a++, b++) { + if (*a != *b ) + break; + } + return *a == *b? 0 : (*(signed char *)a - *(signed char *)b); +} + + + /********************************************* ********** missing string functions ********* *********************************************/ diff --git a/jnlib/stringhelp.h b/jnlib/stringhelp.h index 5d124e40..17a6ad09 100644 --- a/jnlib/stringhelp.h +++ b/jnlib/stringhelp.h @@ -37,6 +37,15 @@ char *make_dirname(const char *filepath); char *make_filename( const char *first_part, ... ); int compare_filenames( const char *a, const char *b ); +const char *ascii_memistr( const char *buf, size_t buflen, const char *sub ); +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_memcasecmp( const char *a, const char *b, size_t n ); + + #ifndef HAVE_MEMICMP int memicmp( const char *a, const char *b, size_t n ); #endif |