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