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