]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_uc.h
Some minor bugs for dntest ""
[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 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x80 )
80 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
81         ? 1 : ldap_utf8_charlen((p)) )
82 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
83         ? 1 : ldap_utf8_offset((p)) )
84
85 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
86         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
87
88 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
89         ? (char *)(p)+1 : ldap_utf8_next((p)) )
90
91 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
92
93 /* For symmetry */
94 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
95 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
96
97
98 /* these probably should be renamed */
99 LDAP_LUNICODE_F(int) ucstrncmp(
100         const ldap_unicode_t *,
101         const ldap_unicode_t *,
102         ber_len_t );
103
104 LDAP_LUNICODE_F(int) ucstrncasecmp(
105         const ldap_unicode_t *,
106         const ldap_unicode_t *,
107         ber_len_t );
108
109 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrnchr(
110         const ldap_unicode_t *,
111         ber_len_t,
112         ldap_unicode_t );
113
114 LDAP_LUNICODE_F(ldap_unicode_t *) ucstrncasechr(
115         const ldap_unicode_t *,
116         ber_len_t,
117         ldap_unicode_t );
118
119 LDAP_LUNICODE_F(void) ucstr2upper(
120         ldap_unicode_t *,
121         ber_len_t );
122
123 #define UTF8_CASEFOLD 1
124 #define UTF8_NOCASEFOLD 0
125
126 LDAP_LUNICODE_F(char *) UTF8normalize(
127         struct berval *,
128         char );
129
130 LDAP_LUNICODE_F(int) UTF8normcmp(
131         const char *,
132         const char *,
133         char );
134
135 LDAP_END_DECL
136
137 #endif
138