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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
'\" 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 3C "12 Sep 2007" "SunOS 5.11" "Standard C Library Functions"
.SH NAME
u8_strcmp \- UTF-8 string comparison function
.SH SYNOPSIS
.LP
.nf
#include <sys/u8_textprep.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 \fIversion\fR, \fBint *\fR\fIerrnum\fR);
.fi
.SH PARAMETERS
.sp
.ne 2
.mk
.na
\fB\fIs1\fR, \fIs2\fR\fR
.ad
.RS 13n
.rt
Pointers to null-terminated UTF-8 strings
.RE
.sp
.ne 2
.mk
.na
\fB\fIn\fR\fR
.ad
.RS 13n
.rt
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
.mk
.na
\fB\fIflag\fR\fR
.ad
.RS 13n
.rt
The possible comparison options constructed by a bit-wise-inclusive-OR of the
following values:
.sp
.ne 2
.mk
.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
.mk
.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
.mk
.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
.mk
.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
.mk
.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
.mk
.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
.mk
.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
.mk
.na
\fB\fIversion\fR\fR
.ad
.RS 13n
.rt
The version of Unicode data that should be used during comparison. The
following values are supported:
.sp
.ne 2
.mk
.na
\fB\fBU8_UNICODE_320\fR\fR
.ad
.sp .6
.RS 4n
Use Unicode 3.2.0 data during comparison.
.RE
.sp
.ne 2
.mk
.na
\fB\fBU8_UNICODE_500\fR\fR
.ad
.sp .6
.RS 4n
Use Unicode 5.0.0 data during comparison.
.RE
.sp
.ne 2
.mk
.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
.mk
.na
\fB\fIerrnum\fR\fR
.ad
.RS 13n
.rt
A non-zero value indicates that an error has occurred during comparison. The
following values are supported:
.sp
.ne 2
.mk
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
.rt
The specified option values are conflicting and cannot be supported.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEILSEQ\fR\fR
.ad
.RS 10n
.rt
There was an illegal character at \fIs1\fR, \fIs2\fR, or both.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt
There was an incomplete character at \fIs1\fR, \fIs2\fR, or both.
.RE
.sp
.ne 2
.mk
.na
\fB\fBERANGE\fR\fR
.ad
.RS 10n
.rt
The specified Unicode version value is not supported.
.RE
.RE
.SH DESCRIPTION
.sp
.LP
The \fBu8_stcmp()\fR function internally processes UTF-8 strings pointed to by
\fIs1\fR and \fIs2\fR based on the corresponding version of the Unicode
Standard and other input arguments and compares the result strings in
byte-by-byte, machine ordering.
.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 \fIerrnum\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 EXAMPLES
.LP
\fBExample 1 \fRPerform simple default string comparison.
.sp
.in +2
.nf
#include <sys/u8_textprep.h>
int
docmp_default(const char *u1, const char *u2) {
int result;
int errnum;
result = u8_strcmp(u1, u2, 0, 0, U8_UNICODE_LATEST, &errnum);
if (errnum == EILSEQ)
return (-1);
if (errnum == EINVAL)
return (-2);
if (errnum == EBADF)
return (-3);
if (errnum == 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/u8_textprep.h>
int
docmp_caseinsensitive_u320(const char *u1, const char *u2) {
int result;
int errnum;
result = u8_strcmp(u1, u2, 0, U8_STRCMP_CI_UPPER,
U8_UNICODE_320, &errnum);
if (errnum == EILSEQ)
return (-1);
if (errnum == EINVAL)
return (-2);
if (errnum == EBADF)
return (-3);
if (errnum == ERANGE)
return (-4);
return (result);
}
.fi
.in -2
.LP
\fBExample 3 \fRPerform Unicode Normalization Form D.
.sp
.LP
Perform Unicode Normalization Form D and upper case based case-insensitive
comparison with Unicode 3.2.0 date.
.sp
.in +2
.nf
#include <sys/u8_textprep.h>
int
docmp_nfd_caseinsensitive_u320(const char *u1, const char *u2) {
int result;
int errnum;
result = u8_strcmp(u1, u2, 0,
(U8_STRCMP_NFD|U8_STRCMP_CI_UPPER), U8_UNICODE_320,
&errnum);
if (errnum == EILSEQ)
return (-1);
if (errnum == EINVAL)
return (-2);
if (errnum == EBADF)
return (-3);
if (errnum == 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
tab() box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Interface StabilityCommitted
_
MT-LevelMT-Safe
.TE
.SH SEE ALSO
.sp
.LP
\fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C), \fBattributes\fR(5),
\fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F), \fBu8_validate\fR(9F)
.sp
.LP
The Unicode Standard (http://www.unicode.org)
|