]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_uc.h
Added UTF8normalize() that does Unicode canonical normalization and
[openldap] / include / ldap_pvt_uc.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
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.
10  */
11 /*
12  * ldap_pvt_uc.h - Header for Unicode functions.
13  * These are meant to be used by the OpenLDAP distribution only.
14  */
15
16 #ifndef _LDAP_PVT_UC_H
17 #define _LDAP_PVT_UC_H 1
18
19 #include <ldap_cdefs.h>
20 #include <lber.h>                               /* get ber_slen_t */
21
22 #ifdef _MSC_VER
23 #include "../libraries/liblunicode/ucdata/ucdata.h"
24 #else
25 #include "../libraries/liblunicode/ucdata.h"
26 #endif
27
28 LDAP_BEGIN_DECL
29
30 /*  
31  * UTF-8 (in utf-8.c)
32  */
33
34 typedef ber_int_t ldap_ucs4_t;
35 #define LDAP_UCS4_INVALID (0x80000000U)
36
37 typedef short ldap_ucs2_t;
38
39 /* UCDATA uses UCS-2 passed in an unsigned long */
40 typedef unsigned long ldap_unicode_t;
41
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 );
45
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))
48
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 *);
59
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 * );
64
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 * );
72
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);
83
84 /* Optimizations */
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)) )
90
91 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
92         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
93
94 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
95         ? (char *)(p)+1 : ldap_utf8_next((p)) )
96
97 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
98
99 /* For symmetry */
100 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
101 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
102
103
104 /* these probably should be renamed */
105 LDAP_LUNICODE_F(int) ucstrncmp(
106         const ldap_unicode_t *,
107         const ldap_unicode_t *,
108         ber_len_t );
109
110 LDAP_LUNICODE_F(int) ucstrncasecmp(
111         const ldap_unicode_t *,
112         const ldap_unicode_t *,
113         ber_len_t );
114
115 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrnchr(
116         const ldap_unicode_t *,
117         ber_len_t,
118         ldap_unicode_t );
119
120 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrncasechr(
121         const ldap_unicode_t *,
122         ber_len_t,
123         ldap_unicode_t );
124
125 LDAP_LUNICODE_F(void) ucstr2upper(
126         ldap_unicode_t *,
127         ber_len_t );
128
129 LDAP_LUNICODE_F(char *) UTF8normalize(
130         const char *,
131         char casefold );
132
133 LDAP_END_DECL
134
135 #endif
136