X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fstring.c;h=ee275baec66cee7c47a0806484fb8e1ebde1e1ec;hb=fe86a81e251bda73f04841f765b2a93ac0354396;hp=a251a660cc304127a882c0977deab806fecca6dd;hpb=97a66488324aea1cc8ebcbaea3b022f800085866;p=openldap diff --git a/libraries/libldap/string.c b/libraries/libldap/string.c index a251a660cc..ee275baec6 100644 --- a/libraries/libldap/string.c +++ b/libraries/libldap/string.c @@ -1,26 +1,128 @@ +/* $OpenLDAP$ */ /* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ +/* + * Locale-specific 1-byte character versions + * See utf-8.c for UTF-8 versions + */ + #include "portable.h" -#include +#include #include #include +#include #include "ldap-int.h" + +#if defined ( HAVE_STRSPN ) +#define int_strspn strspn +#else +static int int_strspn( const char *str, const char *delim ) +{ + int pos; + const char *p=delim; + + for( pos=0; (*str) ; pos++,str++) { + if (*str!=*p) { + for( p=delim; (*p) ; p++ ) { + if (*str==*p) { + break; + } + } + } + + if (*p=='\0') { + return pos; + } + } + return pos; +} +#endif + +#if defined( HAVE_STRPBRK ) +#define int_strpbrk strpbrk +#else +static char *(int_strpbrk)( const char *str, const char *accept ) +{ + const char *p; + + for( ; (*str) ; str++ ) { + for( p=accept; (*p) ; p++) { + if (*str==*p) { + return str; + } + } + } + + return NULL; +} +#endif + +char *(ldap_pvt_strtok)( char *str, const char *delim, char **pos ) +{ + char *p; + + if (pos==NULL) { + return NULL; + } + + if (str==NULL) { + if (*pos==NULL) { + return NULL; + } + + str=*pos; + } + + /* skip any initial delimiters */ + str += int_strspn( str, delim ); + if (*str == '\0') { + return NULL; + } + + p = int_strpbrk( str, delim ); + if (p==NULL) { + *pos = NULL; + + } else { + *p ='\0'; + *pos = p+1; + } + + return str; +} + +char * +ldap_pvt_str2upper( char *str ) +{ + char *s; + + /* to upper */ + if ( str ) { + for ( s = str; *s; s++ ) { + *s = TOUPPER( (unsigned char) *s ); + } + } + + return( str ); +} + char * -(ldap_pvt_strdup)( const char *s ) +ldap_pvt_str2lower( char *str ) { - char *p; - int len; - len = strlen( s ) + 1; - if ( (p = (char *) malloc( len )) == NULL ) - return( (char *)0 ); + char *s; - memcpy( p, s, len ); + /* to lower */ + if ( str ) { + for ( s = str; *s; s++ ) { + *s = TOLOWER( (unsigned char) *s ); + } + } - return( p ); + return( str ); }