]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_uc.h
Added dnPretty2/dnNormalize2 using preallocated destination berval
[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  * These should be named ldap_pvt_....()
16  */
17
18 #ifndef _LDAP_PVT_UC_H
19 #define _LDAP_PVT_UC_H 1
20
21 #include <ldap_cdefs.h>
22 #include <lber.h>                               /* get ber_slen_t */
23
24 #ifdef _MSC_VER
25 #include "../libraries/liblunicode/ucdata/ucdata.h"
26 #else
27 #include "../libraries/liblunicode/ucdata.h"
28 #endif
29
30 LDAP_BEGIN_DECL
31
32 /*
33  * UTF-8 (in utf-8.c)
34  */
35
36 typedef short ldap_ucs2_t;
37
38 /* UCDATA uses UCS-2 passed in an unsigned long */
39 typedef unsigned long ldap_unicode_t;
40 #define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p))
41 #define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf))
42
43 /* returns the number of bytes in the UTF-8 string */
44 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
45 /* returns the number of UTF-8 characters in the string */
46 LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
47 /* returns the length (in bytes) of the UTF-8 character */
48 LDAP_F (int) ldap_utf8_offset( const char * );
49 /* returns the length (in bytes) indicated by the UTF-8 character */
50 LDAP_F (int) ldap_utf8_charlen( const char * );
51 /* copies a UTF-8 character and returning number of bytes copied */
52 LDAP_F (int) ldap_utf8_copy( char *, const char *);
53
54 /* returns pointer of next UTF-8 character in string */
55 LDAP_F (char*) ldap_utf8_next( const char * );
56 /* returns pointer of previous UTF-8 character in string */
57 LDAP_F (char*) ldap_utf8_prev( const char * );
58
59 /* primitive ctype routines -- not aware of non-ascii characters */
60 LDAP_F (int) ldap_utf8_isascii( const char * );
61 LDAP_F (int) ldap_utf8_isalpha( const char * );
62 LDAP_F (int) ldap_utf8_isalnum( const char * );
63 LDAP_F (int) ldap_utf8_isdigit( const char * );
64 LDAP_F (int) ldap_utf8_isxdigit( const char * );
65 LDAP_F (int) ldap_utf8_isspace( const char * );
66
67 /* span characters not in set, return bytes spanned */
68 LDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
69 /* span characters in set, return bytes spanned */
70 LDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
71 /* return first occurance of character in string */
72 LDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
73 /* return first character of set in string */
74 LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
75 /* reentrant tokenizer */
76 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
77
78 /* Optimizations */
79 LDAP_V (const char) ldap_utf8_lentab[128];
80
81 #define LDAP_UTF8_ISASCII(p) ( *(unsigned char *)(p) ^ 0x80 )
82 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
83         ? 1 : ldap_utf8_lentab[*(unsigned char *)(p) ^ 0x80] )
84 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
85         ? 1 : ldap_utf8_offset((p)) )
86
87 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
88         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
89
90 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
91         ? (char *)(p)+1 : ldap_utf8_next((p)) )
92
93 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
94
95 /* For symmetry */
96 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
97 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
98
99
100 /* these probably should be renamed */
101 LDAP_LUNICODE_F(int) ucstrncmp(
102         const ldap_unicode_t *,
103         const ldap_unicode_t *,
104         ber_len_t );
105
106 LDAP_LUNICODE_F(int) ucstrncasecmp(
107         const ldap_unicode_t *,
108         const ldap_unicode_t *,
109         ber_len_t );
110
111 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrnchr(
112         const ldap_unicode_t *,
113         ber_len_t,
114         ldap_unicode_t );
115
116 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrncasechr(
117         const ldap_unicode_t *,
118         ber_len_t,
119         ldap_unicode_t );
120
121 LDAP_LUNICODE_F(void) ucstr2upper(
122         ldap_unicode_t *,
123         ber_len_t );
124
125 #define UTF8_CASEFOLD 1
126 #define UTF8_NOCASEFOLD 0
127
128 LDAP_LUNICODE_F(char *) UTF8normalize(
129         struct berval *,
130         char );
131
132 LDAP_LUNICODE_F(int) UTF8normcmp(
133         const char *,
134         const char *,
135         char );
136
137 LDAP_END_DECL
138
139 #endif
140