1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
'\" te
.\" Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH U8_STRCMP 9F "Sep 18, 2007"
.SH NAME
u8_strcmp \- UTF-8 string comparison function
.SH SYNOPSIS
.LP
.nf
#include <sys/sunddi.h>
\fBint\fR \fBu8_strcmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR,
\fBint\fR \fIflag\fR, \fBsize_t\fR \fIunicode_version\fR, \fBint *\fR\fIerrno\fR);
.fi
.SH INTERFACE LEVEL
.sp
.LP
Solaris DDI specific (Solaris DDI)
.SH PARAMETERS
.sp
.ne 2
.na
\fB\fIs1\fR, \fIs2\fR\fR
.ad
.RS 20n
Pointers to null-terminated UTF-8 strings
.RE
.sp
.ne 2
.na
\fB\fIn\fR\fR
.ad
.RS 20n
The maximum number of bytes to be compared. If 0, the comparison is performed
until either or both of the strings are examined to the string terminating null
byte.
.RE
.sp
.ne 2
.na
\fB\fIflag\fR\fR
.ad
.RS 20n
The possible comparison options constructed by a bit-wise-inclusive-OR of the
following values:
.sp
.ne 2
.na
\fB\fBU8_STRCMP_CS\fR\fR
.ad
.sp .6
.RS 4n
Perform case-sensitive string comparison. This is the default.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_CI_UPPER\fR\fR
.ad
.sp .6
.RS 4n
Perform case-insensitive string comparison based on Unicode upper case
converted results of \fIs1\fR and \fIs2\fR.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_CI_LOWER\fR\fR
.ad
.sp .6
.RS 4n
Perform case-insensitive string comparison based on Unicode lower case
converted results of \fIs1\fR and \fIs2\fR.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_NFD\fR\fR
.ad
.sp .6
.RS 4n
Perform string comparison after \fIs1\fR and \fIs2\fR have been normalized by
using Unicode Normalization Form D.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_NFC\fR\fR
.ad
.sp .6
.RS 4n
Perform string comparison after \fIs1\fR and \fIs2\fR have been normalized by
using Unicode Normalization Form C.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_NFKD\fR\fR
.ad
.sp .6
.RS 4n
Perform string comparison after \fIs1\fR and \fIs2\fR have been normalized by
using Unicode Normalization Form KD.
.RE
.sp
.ne 2
.na
\fB\fBU8_STRCMP_NFKC\fR\fR
.ad
.sp .6
.RS 4n
Perform string comparison after \fIs1\fR and \fIs2\fR have been normalized by
using Unicode Normalization Form KC.
.RE
Only one case-sensitive or case-insensitive option is allowed. Only one Unicode
Normalization option is allowed.
.RE
.sp
.ne 2
.na
\fB\fIunicode_version\fR\fR
.ad
.RS 20n
The version of Unicode data that should be used during comparison. The
following values are supported:
.sp
.ne 2
.na
\fB\fBU8_UNICODE_320\fR\fR
.ad
.sp .6
.RS 4n
Use Unicode 3.2.0 data during comparison.
.RE
.sp
.ne 2
.na
\fB\fBU8_UNICODE_500\fR\fR
.ad
.sp .6
.RS 4n
Use Unicode 5.0.0 data during comparison.
.RE
.sp
.ne 2
.na
\fB\fBU8_UNICODE_LATEST\fR\fR
.ad
.sp .6
.RS 4n
Use the latest Unicode version data available, which is Unicode 5.0.0.
.RE
.RE
.sp
.ne 2
.na
\fB\fIerrno\fR\fR
.ad
.RS 20n
A non-zero value indicates that an error has occurred during comparison. The
following values are supported:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
The specified option values are conflicting and cannot be supported.
.RE
.sp
.ne 2
.na
\fB\fBEILSEQ\fR\fR
.ad
.RS 10n
There was an illegal character at \fIs1\fR, \fIs2\fR, or both.
.RE
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
There was an incomplete character at \fIs1\fR, \fIs2\fR, or both.
.RE
.sp
.ne 2
.na
\fB\fBERANGE\fR\fR
.ad
.RS 10n
The specified Unicode version value is not supported.
.RE
.RE
.SH DESCRIPTION
.sp
.LP
After proper pre-processing, the \fBu8_strcmp()\fR function compares two UTF-8
strings byte-by-byte, according to the machine ordering defined by the
corresponding version of the Unicode Standard.
.sp
.LP
When multiple comparison options are specified, Unicode Normalization is
performed after case-sensitive or case-insensitive processing is performed.
.SH RETURN VALUES
.sp
.LP
The \fBu8_strcmp()\fR function returns an integer greater than, equal to, or
less than 0 if the string pointed to by \fIs1\fR is greater than, equal to, or
less than the string pointed to by \fIs2\fR, respectively.
.sp
.LP
When \fBu8_strcmp()\fR detects an illegal or incomplete character, such
character causes the function to set \fIerrno\fR to indicate the error.
Afterward, the comparison is still performed on the resultant strings and a
value based on byte-by-byte comparison is always returned.
.SH CONTEXT
.sp
.LP
The \fBu8_strcmp()\fR function can be called from user or interrupt context.
.SH EXAMPLES
.LP
\fBExample 1 \fRPerform simple default string comparison.
.sp
.in +2
.nf
#include <sys/sunddi.h>
int
docmp_default(const char *u1, const char *u2) {
int result;
int ;
result = u8_strcmp(u1, u2, 0, 0, U8_UNICODE_LATEST, &errno);
if (errno == EILSEQ)
return (-1);
if (errno == EINVAL)
return (-2);
if (errno == EBADF)
return (-3);
if (errno == ERANGE)
return (-4);
.fi
.in -2
.LP
\fBExample 2 \fRPerform upper case based case-insensitive comparison with
Unicode 3.2.0 date.
.sp
.in +2
.nf
#include <sys/sunddi.h>
int
docmp_caseinsensitive_u320(const char *u1, const char *u2) {
int result;
int errno;
result = u8_strcmp(u1, u2, 0, U8_STRCMP_CI_UPPER,
U8_UNICODE_320, &errno);
if (errno == EILSEQ)
return (-1);
if (errno == EINVAL)
return (-2);
if (errno == EBADF)
return (-3);
if (errno == ERANGE)
return (-4);
return (result);
}
.fi
.in -2
.LP
\fBExample 3 \fRPerform Unicode Normalization Form D.
.sp
.LP
Perform Unicode Normalization Form D and uppercase-based case-insensitive
comparison with Unicode 3.2.0 date.
.sp
.in +2
.nf
#include <sys/sunddi.h>
int
docmp_nfd_caseinsensitive_u320(const char *u1, const char *u2) {
int result;
int errno;
result = u8_strcmp(u1, u2, 0,
(U8_STRCMP_NFD|U8_STRCMP_CI_UPPER), U8_UNICODE_320,
&errno);
if (errno == EILSEQ)
return (-1);
if (errno == EINVAL)
return (-2);
if (errno == EBADF)
return (-3);
if (errno == ERANGE)
return (-4);
return (result);
}
.fi
.in -2
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
Interface Stability Committed
.TE
.SH SEE ALSO
.sp
.LP
\fBu8_validate\fR(3C), \fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C),
\fBattributes\fR(5), \fBu8_textprep_str\fR(9F), \fBu8_validate\fR(9F),
\fBuconv_u16tou32\fR(9F)
.sp
.LP
The Unicode Standard (http://www.unicode.org)
|