#include <ac/string.h>
#include <ac/time.h>
+#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
}
/* 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;
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;
}
/* 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;
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 );
/*
* 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';
}
{
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' )
{
unsigned c = * (const unsigned char *) p;
- if(!ISASCII(c)) return 0;
+ if(!LDAP_IS_ASCII(c)) return 0;
switch(c) {
case ' ':
{
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' );
{
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' )
{
unsigned c = * (const unsigned char *) p;
- if(!ISASCII(c)) return 0;
+ if(!LDAP_IS_ASCII(c)) return 0;
return ( c >= 'a' && c <= 'z' );
}
{
unsigned c = * (const unsigned char *) p;
- if(!ISASCII(c)) return 0;
+ if(!LDAP_IS_ASCII(c)) return 0;
return ( c >= 'A' && c <= 'Z' );
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}