X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Futf-8.c;h=6b2ac969e1046d0f8be70daa30daa521fde189eb;hb=2b0819c4a9209784f762ec154ce4721038522a8a;hp=07243b786dc47beec48f23a6141428a52e3e0ae4;hpb=b99299219fdb684b1318ecbea146a1b4e0868e2e;p=openldap diff --git a/libraries/libldap/utf-8.c b/libraries/libldap/utf-8.c index 07243b786d..6b2ac969e1 100644 --- a/libraries/libldap/utf-8.c +++ b/libraries/libldap/utf-8.c @@ -25,13 +25,13 @@ #include #include +#include "ldap_utf8.h" + #include "ldap-int.h" #include "ldap_defaults.h" -#undef ISASCII -#define ISASCII(uc) ((uc) < 0x100) -#undef UCS4_INVALID -#define UCS4_INVALID 0x80000000U +#undef LDAP_IS_ASCII +#define LDAP_IS_ASCII(uc) ((uc) < 0x80) /* * Basic UTF-8 routines @@ -109,7 +109,7 @@ int ldap_utf8_charlen( const char * p ) } /* conv UTF-8 to UCS-4, useful for comparisons */ -ldap_ucs4_t ldap_utf8_to_ucs4( const char * p ) +ldap_ucs4_t ldap_x_utf8_to_ucs4( const char * p ) { const unsigned char *c = p; ldap_ucs4_t ch; @@ -119,13 +119,13 @@ ldap_ucs4_t ldap_utf8_to_ucs4( const char * p ) len = LDAP_UTF8_CHARLEN(p); - if( len == 0 ) return UCS4_INVALID; + if( len == 0 ) return LDAP_UCS4_INVALID; ch = c[0] & mask[len]; for(i=1; i < len; i++) { if ((c[i] & 0xc0) != 0x80) { - return UCS4_INVALID; + return LDAP_UCS4_INVALID; } ch <<= 6; @@ -136,7 +136,7 @@ ldap_ucs4_t ldap_utf8_to_ucs4( const char * p ) } /* conv UCS-4 to UTF-8, not used */ -int ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf ) +int ldap_x_ucs4_to_utf8( ldap_ucs4_t c, char *buf ) { int len=0; unsigned char* p = buf; @@ -163,7 +163,7 @@ int ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf ) p[len++] = 0x80 | ( (c >> 6) & 0x3f ); p[len++] = 0x80 | ( c & 0x3f ); - } else if( c < 0x400000 ) { + } else if( c < 0x4000000 ) { p[len++] = 0xf8 | ( c >> 24 ); p[len++] = 0x80 | ( (c >> 18) & 0x3f ); p[len++] = 0x80 | ( (c >> 12) & 0x3f ); @@ -266,20 +266,20 @@ int ldap_utf8_copy( char* dst, const char *src ) /* * UTF-8 ctype routines - * Only deals with characters < 0x100 (ie: US-ASCII) + * Only deals with characters < 0x80 (ie: US-ASCII) */ int ldap_utf8_isascii( const char * p ) { unsigned c = * (const unsigned char *) p; - return ISASCII(c); + return LDAP_IS_ASCII(c); } int ldap_utf8_isdigit( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return c >= '0' && c <= '9'; } @@ -288,7 +288,7 @@ int ldap_utf8_isxdigit( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return ( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'F' ) @@ -299,7 +299,7 @@ int ldap_utf8_isspace( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; switch(c) { case ' ': @@ -323,7 +323,7 @@ int ldap_utf8_isalpha( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ); @@ -333,7 +333,7 @@ int ldap_utf8_isalnum( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return ( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'Z' ) @@ -344,7 +344,7 @@ int ldap_utf8_islower( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return ( c >= 'a' && c <= 'z' ); } @@ -353,7 +353,7 @@ int ldap_utf8_isupper( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!ISASCII(c)) return 0; + if(!LDAP_IS_ASCII(c)) return 0; return ( c >= 'A' && c <= 'Z' ); } @@ -368,7 +368,7 @@ int ldap_utf8_isupper( const char * p ) char * (ldap_utf8_strchr)( const char *str, const char *chr ) { for( ; *str != '\0'; LDAP_UTF8_INCR(str) ) { - if( ldap_utf8_to_ucs4( str ) == ldap_utf8_to_ucs4( chr ) ) { + if( ldap_x_utf8_to_ucs4( str ) == ldap_x_utf8_to_ucs4( chr ) ) { return (char *) str; } } @@ -384,7 +384,7 @@ ber_len_t (ldap_utf8_strcspn)( const char *str, const char *set ) for( cstr = str; *cstr != '\0'; LDAP_UTF8_INCR(cstr) ) { for( cset = set; *cset != '\0'; LDAP_UTF8_INCR(cset) ) { - if( ldap_utf8_to_ucs4( cstr ) == ldap_utf8_to_ucs4( cset ) ) { + if( ldap_x_utf8_to_ucs4( cstr ) == ldap_x_utf8_to_ucs4( cset ) ) { return cstr - str; } } @@ -405,7 +405,7 @@ ber_len_t (ldap_utf8_strspn)( const char *str, const char *set ) return cstr - str; } - if( ldap_utf8_to_ucs4( cstr ) == ldap_utf8_to_ucs4( cset ) ) { + if( ldap_x_utf8_to_ucs4( cstr ) == ldap_x_utf8_to_ucs4( cset ) ) { break; } } @@ -421,7 +421,7 @@ char *(ldap_utf8_strpbrk)( const char *str, const char *set ) const char *cset; for( cset = set; *cset != '\0'; LDAP_UTF8_INCR(cset) ) { - if( ldap_utf8_to_ucs4( str ) == ldap_utf8_to_ucs4( cset ) ) { + if( ldap_x_utf8_to_ucs4( str ) == ldap_x_utf8_to_ucs4( cset ) ) { return (char *) str; } }