3 #include <ldap_pvt_uc.h>
7 const ldap_unicode_t *u1,
8 const ldap_unicode_t *u2,
11 for(; 0 < n; ++u1, ++u2, --n ) {
13 return *u1 < *u2 ? -1 : +1;
23 const ldap_unicode_t *u1,
24 const ldap_unicode_t *u2,
27 for(; 0 < n; ++u1, ++u2, --n ) {
28 ldap_unicode_t uu1 = uctoupper( *u1 );
29 ldap_unicode_t uu2 = uctoupper( *u2 );
32 return uu1 < uu2 ? -1 : +1;
41 ldap_unicode_t * ucstrnchr(
42 const ldap_unicode_t *u,
46 for(; 0 < n; ++u, --n ) {
48 return (ldap_unicode_t *) u;
55 ldap_unicode_t * ucstrncasechr(
56 const ldap_unicode_t *u,
61 for(; 0 < n; ++u, --n ) {
62 if( uctoupper( *u ) == c ) {
63 return (ldap_unicode_t *) u;
74 for(; 0 < n; ++u, --n ) {
83 int i, j, len, clen, outpos, ucsoutlen, outsize, last;
85 unsigned long *ucs, *p, *ucsout;
87 static unsigned char mask[] = {
88 0, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
97 out = (char *) malloc( 1 );
103 out = (char *) malloc( outsize );
110 /* finish off everything up to character before first non-ascii */
111 if ( LDAP_UTF8_ISASCII( s ) ) {
112 for ( i = 1; (i < len) && LDAP_UTF8_ISASCII(s + i); i++ ) {
113 out[outpos++] = casefold ? TOUPPER( s[i-1] ) : s[i-1];
116 out[outpos++] = casefold ? TOUPPER( s[len - 1] ) : s[len - 1];
124 p = ucs = (long *) malloc( len * sizeof(*ucs) );
130 /* convert character before first non-ascii to ucs-4 */
132 *p = casefold ? TOUPPER( s[i - 1] ) : s[i - 1];
136 /* s[i] is now first non-ascii character */
138 /* s[i] is non-ascii */
139 /* convert everything up to next ascii to ucs-4 */
141 clen = LDAP_UTF8_CHARLEN( s + i );
151 *p = s[i] & mask[clen];
153 for( j = 1; j < clen; j++ ) {
154 if ( (s[i] & 0xc0) != 0x80 ) {
164 *p = uctoupper( *p );
168 /* normalize ucs of length p - ucs */
169 uccanondecomp( ucs, p - ucs, &ucsout, &ucsoutlen );
170 ucsoutlen = uccanoncomp( ucsout, ucsoutlen );
171 /* convert ucs to utf-8 and store in out */
172 for ( j = 0; j < ucsoutlen; j++ ) {
173 /* allocate more space if not enough room for
174 6 bytes and terminator */
175 if ( outsize - outpos < 7 ) {
176 outsize = ucsoutlen - j + outpos + 6;
177 out = (char *) realloc( out, outsize );
183 outpos += ldap_ucs4_to_utf8( ucsout[j], &out[outpos] );
193 /* finish off everything up to char before next non-ascii */
194 for ( i++; (i < len) && LDAP_UTF8_ISASCII(s + i); i++ ) {
195 out[outpos++] = casefold ? TOUPPER( s[i-1] ) : s[i-1];
198 out[outpos++] = casefold ? TOUPPER( s[len - 1] ) : s[len - 1];
202 /* convert character before next non-ascii to ucs-4 */
203 *ucs = casefold ? TOUPPER( s[i - 1] ) : s[i - 1];