From: Kurt Zeilenga Date: Sat, 22 Jan 2000 20:55:43 +0000 (+0000) Subject: Add initial (untested) implementations of ldap_utf8_strtok, X-Git-Tag: UCDATA_2_4~17 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4e3c4d8c6d60237ead5a1134c426754b9f632298;p=openldap Add initial (untested) implementations of ldap_utf8_strtok, ldap_utf8_strcspn, ldap_utf8_strtok. --- diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 46425fc5d2..e161a6d52b 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -524,6 +524,10 @@ LIBLDAP_F (int) ldap_utf8_isdigit( const char * ); LIBLDAP_F (int) ldap_utf8_isxdigit( const char * ); LIBLDAP_F (int) ldap_utf8_isspace( const char * ); +LIBLDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set); +LIBLDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set); +LIBLDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last); + LDAP_END_DECL #endif /* _LDAP_INT_H */ diff --git a/libraries/libldap/utf-8.c b/libraries/libldap/utf-8.c index 152bd8efd5..5eb46ce325 100644 --- a/libraries/libldap/utf-8.c +++ b/libraries/libldap/utf-8.c @@ -33,15 +33,15 @@ */ ber_len_t ldap_utf8_bytes( const char * p ) { - ber_len_t bytes; + ber_len_t bytes = 0; - if( p == NULL ) return 0; + if( p == NULL ) return bytes; - for( bytes=0; p[bytes] ; bytes++ ) { + while( p[bytes++] ) { /* EMPTY */ ; } - return ++bytes; + return bytes; } ber_len_t ldap_utf8_chars( const char * p ) @@ -327,3 +327,88 @@ char* ldap_utf8_fgetc( FILE *s, char *buf ) return buf; } + +ber_len_t (ldap_utf8_strcspn)( const char *str, const char *set ) +{ + int len; + const char *cstr; + + for( cstr = str; *cstr != '\0'; cstr += len ) { + const char *cset; + + for( cset = set; ; cset += len ) { + if( ldap_utf8_to_ucs4( cstr ) == ldap_utf8_to_ucs4( cset ) ) { + return cstr - str; + } + + len = ldap_utf8_charlen(cset); + if( !len ) break; + } + + len = ldap_utf8_charlen(cstr); + if( !len ) break; + } + + return cstr - str; +} + +ber_len_t (ldap_utf8_strspn)( const char *str, const char *set ) +{ + int len; + const char *cstr; + + for( cstr = str; *cstr != '\0'; cstr += len ) { + const char *cset; + + for( cset = set; ; cset += len ) { + if( *cset == '\0' ) { + return cstr - str; + } + + if( ldap_utf8_to_ucs4( cstr ) == ldap_utf8_to_ucs4( cset ) ) { + break; + } + + len = ldap_utf8_charlen(cset); + if( !len ) break; + } + + len = ldap_utf8_charlen(cstr); + if( !len ) break; + } + + return cstr - str; +} + +char *(ldap_utf8_strtok)(char *str, const char *sep, char **last) +{ + char *begin; + char *end; + + if( last == NULL ) return NULL; + + begin = str ? str : *last; + + begin += ldap_utf8_strspn( begin, sep ); + + if( *begin == '\0' ) { + *last = NULL; + return NULL; + } + + end = &begin[ ldap_utf8_strcpn( begin, sep ) ]; + + if( *end != '\0' ) { + int len = ldap_utf8_charlen( end ); + *end = '\0'; + + if( len ) { + end += len; + } else { + end = NULL; + } + } + + *last = end; + return begin; +}