2 .\" Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH U8_TEXTPREP_STR 9F "Sep 18, 2007"
8 u8_textprep_str \- string-based UTF-8 text preparation function
12 #include <sys/types.h>
13 #include <sys/errno.h>
14 #include <sys/sunddi.h>
16 \fBsize_t\fR \fBu8_textprep_str\fR(\fBchar *\fR\fIinarray\fR, \fBsize_t *\fR\fIinlen\fR,
17 \fBchar *\fR\fIoutarray\fR, \fBsize_t *\fR\fIoutlen\fR, \fBint\fR \fIflag\fR,
18 \fBsize_t\fR \fIunicode_version\fR, \fBint *\fR\fIerrno\fR);
24 Solaris DDI specific (Solaris DDI)
32 A pointer to a byte array containing a sequence of UTF-8 character bytes to be
42 As input argument, the number of bytes to be prepared in \fIinarray\fR. As
43 output argument, the number of bytes in \fIinarray\fR still not consumed.
52 A pointer to a byte array where prepared UTF-8 character bytes can be saved.
61 As input argument, the number of available bytes at \fIoutarray\fR where
62 prepared character bytes can be saved. As output argument, after the
63 conversion, the number of bytes still available at \fIoutarray\fR.
72 The possible preparation options constructed by a bitwise-inclusive-OR of the
77 \fB\fBU8_TEXTPREP_IGNORE_NULL\fR\fR
81 Normally \fBu8_textprep_str()\fR stops the preparation if it encounters null
82 byte even if the current \fIinlen\fR is pointing to a value bigger than zero.
84 With this option, null byte does not stop the preparation and the preparation
85 continues until \fIinlen\fR specified amount of \fIinarray\fR bytes are all
86 consumed for preparation or an error happened.
92 \fB\fBU8_TEXTPREP_IGNORE_INVALID\fR\fR
96 Normally \fBu8_textprep_str()\fR stops the preparation if it encounters illegal
97 or incomplete characters with corresponding \fIerrno\fR values.
99 When this option is set, \fBu8_textprep_str()\fR does not stop the preparation
100 and instead treats such characters as no need to do any preparation.
106 \fB\fBU8_TEXTPREP_TOUPPER\fR\fR
110 Map lowercase characters to uppercase characters if applicable.
116 \fB\fBU8_TEXTPREP_TOLOWER\fR\fR
120 Map uppercase characters to lowercase characters if applicable.
126 \fB\fBU8_TEXTPREP_NFD\fR\fR
130 Apply Unicode Normalization Form D.
136 \fB\fBU8_TEXTPREP_NFC\fR\fR
140 Apply Unicode Normalization Form C.
146 \fB\fBU8_TEXTPREP_NFKD\fR\fR
150 Apply Unicode Normalization Form KD.
156 \fB\fBU8_TEXTPREP_NFKC\fR\fR
160 Apply Unicode Normalization Form KC.
163 Only one case folding option is allowed. Only one Unicode Normalization option
166 When a case folding option and a Unicode Normalization option are specified
167 together, UTF-8 text preparation is done by doing case folding first and then
168 Unicode Normalization.
170 If no option is specified, no processing occurs except the simple copying of
171 bytes from input to output.
177 \fB\fIunicode_version\fR\fR
180 The version of Unicode data that should be used during UTF-8 text preparation.
181 The following values are supported:
185 \fB\fBU8_UNICODE_320\fR\fR
189 Use Unicode 3.2.0 data during comparison.
195 \fB\fBU8_UNICODE_500\fR\fR
199 Use Unicode 5.0.0 data during comparison.
205 \fB\fBU8_UNICODE_LATEST\fR\fR
209 Use the latest Unicode version data available which is Unicode 5.0.0 currently.
220 The error value when preparation is not completed or fails. The following
221 values are supported:
228 Text preparation stopped due to lack of space in the output array.
237 Specified option values are conflicting and cannot be supported.
246 Text preparation stopped due to an input byte that does not belong to UTF-8.
255 Text preparation stopped due to an incomplete UTF-8 character at the end of the
265 The specified Unicode version value is not a supported version.
273 The \fBu8_textprep_str()\fR function prepares the sequence of UTF-8 characters
274 in the array specified by \fIinarray\fR into a sequence of corresponding UTF-8
275 characters prepared in the array specified by \fIoutarray\fR. The \fIinarray\fR
276 argument points to a character byte array to the first character in the input
277 array and \fIinlen\fR indicates the number of bytes to the end of the array to
278 be converted. The \fIoutarray\fR argument points to a character byte array to
279 the first available byte in the output array and \fIoutlen\fR indicates the
280 number of the available bytes to the end of the array. Unless \fIflag\fR is
281 \fBU8_TEXTPREP_IGNORE_NULL\fR, \fBu8_textprep_str()\fR normally stops when it
282 encounters a null byte from the input array regardless of the current
286 If \fIflag\fR is \fBU8_TEXTPREP_IGNORE_INVALID\fR and a sequence of input bytes
287 does not form a valid UTF-8 character, preparation stops after the previous
288 successfully prepared character. If \fIflag\fR is
289 \fBU8_TEXTPREP_IGNORE_INVALID\fR and the input array ends with an incomplete
290 UTF-8 character, preparation stops after the previous successfully prepared
291 bytes. If the output array is not large enough to hold the entire prepared
292 text, preparation stops just prior to the input bytes that would cause the
293 output array to overflow. The value pointed to by \fIinlen\fR is decremented to
294 reflect the number of bytes still not prepared in the input array. The value
295 pointed to by \fIoutlen\fR is decremented to reflect the number of bytes still
296 available in the output array.
300 The \fBu8_textprep_str()\fR function updates the values pointed to by
301 \fIinlen\fR and \fIoutlen\fR arguments to reflect the extent of the
302 preparation. When \fBU8_TEXTPREP_IGNORE_INVALID\fR is specified,
303 \fBu8_textprep_str()\fR returns the number of illegal or incomplete characters
304 found during the text preparation. When \fBU8_TEXTPREP_IGNORE_INVALID\fR is not
305 specified and the text preparation is successful, the function returns 0. If
306 the entire string in the input array is prepared, the value pointed to by
307 \fIinlen\fR will be 0. If the text preparation is stopped due to any conditions
308 mentioned above, the value pointed to by \fIinlen\fR will be non-zero and
309 \fIerrno\fR is set to indicate the error. If such and any other error occurs,
310 \fBu8_textprep_str()\fR returns (\fBsize_t\fR)-1 and sets \fIerrno\fR to
315 The \fBu8_textprep_str()\fR function can be called from user or interrupt
319 \fBExample 1 \fRSimple UTF-8 text preparation
323 #include <sys/types.h>
324 #include <sys/errno.h>
325 #include <sys/sunddi.h>
338 * We got a UTF-8 pathname from somewhere.
340 * Calculate the length of input string including the terminating
341 * NULL byte and prepare other arguments.
343 (void) strlcpy(ib, pathname, MAXPATHLEN);
348 * Do toupper case folding, apply Unicode Normalization Form D,
349 * ignore NULL byte, and ignore any illegal/incomplete characters.
351 ret = u8_textprep_str(ib, &il, ob, &ol,
352 (U8_TEXTPREP_IGNORE_NULL|U8_TEXTPREP_IGNORE_INVALID|
353 U8_TEXTPREP_TOUPPER|U8_TEXTPREP_NFD), U8_UNICODE_LATEST, &err);
354 if (ret == (size_t)-1) {
369 See \fBattributes\fR(5) for descriptions of the following attributes:
377 ATTRIBUTE TYPE ATTRIBUTE VALUE
379 Interface Stability Committed
385 \fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C),
386 \fBattributes\fR(5), \fBu8_strcmp\fR(9F), \fBu8_validate\fR(9F),
387 \fBuconv_u16tou32\fR(9F)
390 The Unicode Standard (http://www.unicode.org)