]> git.sur5r.net Git - openldap/commitdiff
Add initial (untested) implementations of ldap_utf8_strtok,
authorKurt Zeilenga <kurt@openldap.org>
Sat, 22 Jan 2000 20:55:43 +0000 (20:55 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sat, 22 Jan 2000 20:55:43 +0000 (20:55 +0000)
ldap_utf8_strcspn, ldap_utf8_strtok.

libraries/libldap/ldap-int.h
libraries/libldap/utf-8.c

index 46425fc5d2e1fdea2e657ecb60824b14ec591d40..e161a6d52b53a9a405900a7ddca7dc2fa44a76de 100644 (file)
@@ -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 */
index 152bd8efd5a24c0e9eac32126cb317d8bed96057..5eb46ce325fb75ac2feae9750259293a7b8ad42c 100644 (file)
  */
 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;
+}