3 * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
12 * ldap_pvt_uc.h - Header for Unicode functions.
13 * These are meant to be used by the OpenLDAP distribution only.
16 #ifndef _LDAP_PVT_UC_H
17 #define _LDAP_PVT_UC_H 1
19 #include <ldap_cdefs.h>
20 #include <lber.h> /* get ber_slen_t */
23 #include "../libraries/liblunicode/ucdata/ucdata.h"
25 #include "../libraries/liblunicode/ucdata.h"
34 typedef ber_int_t ldap_ucs4_t;
35 #define LDAP_UCS4_INVALID (0x80000000U)
37 typedef short ldap_ucs2_t;
39 /* UCDATA uses UCS-2 passed in an unsigned long */
40 typedef unsigned long ldap_unicode_t;
42 /* conversion routines */
43 LDAP_F( ldap_ucs4_t ) ldap_utf8_to_ucs4( const char * p );
44 LDAP_F( int ) ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
46 #define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p))
47 #define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf))
49 /* returns the number of bytes in the UTF-8 string */
50 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
51 /* returns the number of UTF-8 characters in the string */
52 LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
53 /* returns the length (in bytes) of the UTF-8 character */
54 LDAP_F (int) ldap_utf8_offset( const char * );
55 /* returns the length (in bytes) indicated by the UTF-8 character */
56 LDAP_F (int) ldap_utf8_charlen( const char * );
57 /* copies a UTF-8 character and returning number of bytes copied */
58 LDAP_F (int) ldap_utf8_copy( char *, const char *);
60 /* returns pointer of next UTF-8 character in string */
61 LDAP_F (char*) ldap_utf8_next( const char * );
62 /* returns pointer of previous UTF-8 character in string */
63 LDAP_F (char*) ldap_utf8_prev( const char * );
65 /* primitive ctype routines -- not aware of non-ascii characters */
66 LDAP_F (int) ldap_utf8_isascii( const char * );
67 LDAP_F (int) ldap_utf8_isalpha( const char * );
68 LDAP_F (int) ldap_utf8_isalnum( const char * );
69 LDAP_F (int) ldap_utf8_isdigit( const char * );
70 LDAP_F (int) ldap_utf8_isxdigit( const char * );
71 LDAP_F (int) ldap_utf8_isspace( const char * );
73 /* span characters not in set, return bytes spanned */
74 LDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
75 /* span characters in set, return bytes spanned */
76 LDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
77 /* return first occurance of character in string */
78 LDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
79 /* return first character of set in string */
80 LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
81 /* reentrant tokenizer */
82 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
85 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x80 )
86 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
87 ? 1 : ldap_utf8_charlen((p)) )
88 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
89 ? 1 : ldap_utf8_offset((p)) )
91 #define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \
92 ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
94 #define LDAP_UTF8_NEXT(p) ( LDAP_UTF8_ISASCII(p) \
95 ? (char *)(p)+1 : ldap_utf8_next((p)) )
97 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
100 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
101 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
104 /* these probably should be renamed */
105 LDAP_LUNICODE_F(int) ucstrncmp(
106 const ldap_unicode_t *,
107 const ldap_unicode_t *,
110 LDAP_LUNICODE_F(int) ucstrncasecmp(
111 const ldap_unicode_t *,
112 const ldap_unicode_t *,
115 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrnchr(
116 const ldap_unicode_t *,
120 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrncasechr(
121 const ldap_unicode_t *,
125 LDAP_LUNICODE_F(void) ucstr2upper(
129 #define UTF8_CASEFOLD 1
130 #define UTF8_NOCASEFOLD 0
132 LDAP_LUNICODE_F(char *) UTF8normalize(