]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/utf-8.c
Sync with 2.x
[openldap] / libraries / libldap / utf-8.c
index 5f6a8c587212866b099d6c0c72e30439879d52c6..9ff563a27d2d8c2ae4ebcfa21976205ce094e89b 100644 (file)
@@ -29,9 +29,7 @@
 #include "ldap_defaults.h"
 
 #undef ISASCII
-#define ISASCII(uc)    ((uc) < 0x100)
-#undef UCS4_INVALID
-#define UCS4_INVALID   0x80000000U
+#define ISASCII(uc)    ((uc) < 0x80)
 
 /*
  * Basic UTF-8 routines
@@ -119,13 +117,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;
@@ -163,7 +161,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 );
@@ -202,7 +200,7 @@ char* ldap_utf8_next( const char * p )
        }
 
        for( i=1; i<6; i++ ) {
-               if ( u[i] & 0xc0 != 0x80 ) {
+               if ( ( u[i] & 0xc0 ) != 0x80 ) {
                        return (char *) &p[i];
                }
        }
@@ -225,7 +223,7 @@ char* ldap_utf8_prev( const char * p )
        const unsigned char *u = p;
 
        for( i=-1; i>-6 ; i-- ) {
-               if ( u[i] & 0xc0 != 0x80 ) {
+               if ( ( u[i] & 0xc0 ) != 0x80 ) {
                        return (char *) &p[i];
                }
        }
@@ -255,7 +253,7 @@ int ldap_utf8_copy( char* dst, const char *src )
        }
 
        for( i=1; i<6; i++ ) {
-               if ( u[i] & 0xc0 != 0x80 ) {
+               if ( ( u[i] & 0xc0 ) != 0x80 ) {
                        return i; 
                }
                dst[i] = src[i];
@@ -266,7 +264,7 @@ 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 )
@@ -400,7 +398,6 @@ ber_len_t (ldap_utf8_strspn)( const char *str, const char *set )
        const char *cset;
 
        for( cstr = str; *cstr != '\0'; LDAP_UTF8_INCR(cstr) ) {
-
                for( cset = set; ; LDAP_UTF8_INCR(cset) ) {
                        if( *cset == '\0' ) {
                                return cstr - str;