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