]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/string.c
Sync with HEAD
[openldap] / libraries / libldap / string.c
index 494248531ecade80d5bfc09f19fd1072a4a55288..548eb18a518dd31004e0817ec9d0b927e1b1e32f 100644 (file)
@@ -1,6 +1,21 @@
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+
 /*
- * Copyright 1998-1999 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"
@@ -8,6 +23,7 @@
 #include <ac/stdlib.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/ctype.h>
 
 #include "ldap-int.h"
 
@@ -91,15 +107,71 @@ char *(ldap_pvt_strtok)( char *str, const char *delim, char **pos )
 }
 
 char *
-(ldap_pvt_strdup)( const char *s )
+ldap_pvt_str2upper( char *str )
+{
+       char    *s;
+
+       /* to upper */
+       if ( str ) {
+               for ( s = str; *s; s++ ) {
+                       *s = TOUPPER( (unsigned char) *s );
+               }
+       }
+
+       return( str );
+}
+
+struct berval *
+ldap_pvt_str2upperbv( char *str, struct berval *bv )
+{
+       char    *s = NULL;
+
+       assert( bv );
+
+       /* to upper */
+       if ( str ) {
+               for ( s = str; *s; s++ ) {
+                       *s = TOUPPER( (unsigned char) *s );
+               }
+       }
+
+       bv->bv_val = str;
+       bv->bv_len = (ber_len_t)(s - str);
+       
+       return( bv );
+}
+
+char *
+ldap_pvt_str2lower( char *str )
+{
+       char    *s;
+
+       /* to lower */
+       if ( str ) {
+               for ( s = str; *s; s++ ) {
+                       *s = TOLOWER( (unsigned char) *s );
+               }
+       }
+
+       return( str );
+}
+
+struct berval *
+ldap_pvt_str2lowerbv( char *str, struct berval *bv )
 {
-       char    *p;
-       size_t  len = strlen( s ) + 1;
+       char    *s = NULL;
 
-       if ( (p = (char *) malloc( len )) == NULL ) {
-               return( NULL );
+       assert( bv );
+
+       /* to lower */
+       if ( str ) {
+               for ( s = str; *s; s++ ) {
+                       *s = TOLOWER( (unsigned char) *s );
+               }
        }
 
-       memcpy( p, s, len );
-       return( p );
+       bv->bv_val = str;
+       bv->bv_len = (ber_len_t)(s - str);
+
+       return( bv );
 }