Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / string.c
blob949a94a071b25906faf78e9adeff06e5ae94b827
1 /* $OpenLDAP: pkg/ldap/libraries/libldap/string.c,v 1.23.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
17 * Locale-specific 1-byte character versions
18 * See utf-8.c for UTF-8 versions
21 #include "portable.h"
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
25 #include <ac/time.h>
26 #include <ac/ctype.h>
28 #include "ldap-int.h"
31 #if defined ( HAVE_STRSPN )
32 #define int_strspn strspn
33 #else
34 static int int_strspn( const char *str, const char *delim )
36 int pos;
37 const char *p=delim;
39 for( pos=0; (*str) ; pos++,str++) {
40 if (*str!=*p) {
41 for( p=delim; (*p) ; p++ ) {
42 if (*str==*p) {
43 break;
48 if (*p=='\0') {
49 return pos;
52 return pos;
54 #endif
56 #if defined( HAVE_STRPBRK )
57 #define int_strpbrk strpbrk
58 #else
59 static char *(int_strpbrk)( const char *str, const char *accept )
61 const char *p;
63 for( ; (*str) ; str++ ) {
64 for( p=accept; (*p) ; p++) {
65 if (*str==*p) {
66 return str;
71 return NULL;
73 #endif
75 char *(ldap_pvt_strtok)( char *str, const char *delim, char **pos )
77 char *p;
79 if (pos==NULL) {
80 return NULL;
83 if (str==NULL) {
84 if (*pos==NULL) {
85 return NULL;
88 str=*pos;
91 /* skip any initial delimiters */
92 str += int_strspn( str, delim );
93 if (*str == '\0') {
94 return NULL;
97 p = int_strpbrk( str, delim );
98 if (p==NULL) {
99 *pos = NULL;
101 } else {
102 *p ='\0';
103 *pos = p+1;
106 return str;
109 char *
110 ldap_pvt_str2upper( char *str )
112 char *s;
114 /* to upper */
115 if ( str ) {
116 for ( s = str; *s; s++ ) {
117 *s = TOUPPER( (unsigned char) *s );
121 return( str );
124 struct berval *
125 ldap_pvt_str2upperbv( char *str, struct berval *bv )
127 char *s = NULL;
129 assert( bv != NULL );
131 /* to upper */
132 if ( str ) {
133 for ( s = str; *s; s++ ) {
134 *s = TOUPPER( (unsigned char) *s );
138 bv->bv_val = str;
139 bv->bv_len = (ber_len_t)(s - str);
141 return( bv );
144 char *
145 ldap_pvt_str2lower( char *str )
147 char *s;
149 /* to lower */
150 if ( str ) {
151 for ( s = str; *s; s++ ) {
152 *s = TOLOWER( (unsigned char) *s );
156 return( str );
159 struct berval *
160 ldap_pvt_str2lowerbv( char *str, struct berval *bv )
162 char *s = NULL;
164 assert( bv != NULL );
166 /* to lower */
167 if ( str ) {
168 for ( s = str; *s; s++ ) {
169 *s = TOLOWER( (unsigned char) *s );
173 bv->bv_val = str;
174 bv->bv_len = (ber_len_t)(s - str);
176 return( bv );