Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/ldap/include/ldap_pvt_uc.h
4394 views
1
/* $OpenLDAP$ */
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
*
4
* Copyright 1998-2024 The OpenLDAP Foundation.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted only as authorized by the OpenLDAP
9
* Public License.
10
*
11
* A copy of this license is available in file LICENSE in the
12
* top-level directory of the distribution or, alternatively, at
13
* <http://www.OpenLDAP.org/license.html>.
14
*/
15
16
/*
17
* ldap_pvt_uc.h - Header for Unicode functions.
18
* These are meant to be used by the OpenLDAP distribution only.
19
* These should be named ldap_pvt_....()
20
*/
21
22
#ifndef _LDAP_PVT_UC_H
23
#define _LDAP_PVT_UC_H 1
24
25
#include <lber.h> /* get ber_slen_t */
26
27
#include <ac/bytes.h>
28
29
LDAP_BEGIN_DECL
30
31
/*
32
* UTF-8 (in utf-8.c)
33
*/
34
35
/* UCDATA uses UCS-2 passed in a 4 byte unsigned int */
36
typedef ac_uint4 ldap_unicode_t;
37
38
/* Convert a string with csize octets per character to UTF-8 */
39
LDAP_F( int ) ldap_ucs_to_utf8s LDAP_P((
40
struct berval *ucs, int csize, struct berval *utf8s ));
41
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
52
/* returns the length (in bytes) indicated by the UTF-8 character
53
* also checks that shortest possible encoding was used
54
*/
55
LDAP_F (int) ldap_utf8_charlen2( const char * );
56
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 occurrence 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
LDAP_V (const char) ldap_utf8_lentab[128];
86
LDAP_V (const char) ldap_utf8_mintab[32];
87
88
#define LDAP_UTF8_ISASCII(p) ( !(*(const unsigned char *)(p) & 0x80 ) )
89
#define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
90
? 1 : ldap_utf8_lentab[*(const unsigned char *)(p) ^ 0x80] )
91
92
/* This is like CHARLEN but additionally validates to make sure
93
* the char used the shortest possible encoding.
94
* 'l' is used to temporarily hold the result of CHARLEN.
95
*/
96
#define LDAP_UTF8_CHARLEN2(p, l) ( ( ( l = LDAP_UTF8_CHARLEN( p )) < 3 || \
97
( ldap_utf8_mintab[*(const unsigned char *)(p) & 0x1f] & (p)[1] ) ) ? \
98
l : 0 )
99
100
#define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
101
? 1 : ldap_utf8_offset((p)) )
102
103
#define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \
104
? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
105
106
#define LDAP_UTF8_NEXT(p) ( LDAP_UTF8_ISASCII(p) \
107
? (char *)(p)+1 : ldap_utf8_next((p)) )
108
109
#define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
110
111
/* For symmetry */
112
#define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
113
#define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
114
115
116
/* these probably should be renamed */
117
LDAP_LUNICODE_F(int) ucstrncmp(
118
const ldap_unicode_t *,
119
const ldap_unicode_t *,
120
ber_len_t );
121
122
LDAP_LUNICODE_F(int) ucstrncasecmp(
123
const ldap_unicode_t *,
124
const ldap_unicode_t *,
125
ber_len_t );
126
127
LDAP_LUNICODE_F(ldap_unicode_t *) ucstrnchr(
128
const ldap_unicode_t *,
129
ber_len_t,
130
ldap_unicode_t );
131
132
LDAP_LUNICODE_F(ldap_unicode_t *) ucstrncasechr(
133
const ldap_unicode_t *,
134
ber_len_t,
135
ldap_unicode_t );
136
137
LDAP_LUNICODE_F(void) ucstr2upper(
138
ldap_unicode_t *,
139
ber_len_t );
140
141
#define LDAP_UTF8_NOCASEFOLD 0x0U
142
#define LDAP_UTF8_CASEFOLD 0x1U
143
#define LDAP_UTF8_ARG1NFC 0x2U
144
#define LDAP_UTF8_ARG2NFC 0x4U
145
#define LDAP_UTF8_APPROX 0x8U
146
147
LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize(
148
struct berval *,
149
struct berval *,
150
unsigned,
151
void *memctx );
152
153
LDAP_LUNICODE_F(int) UTF8bvnormcmp(
154
struct berval *,
155
struct berval *,
156
unsigned,
157
void *memctx );
158
159
LDAP_END_DECL
160
161
#endif
162
163