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_VALIDATE 3C "Sep 18, 2007"
8 u8_validate \- validate UTF-8 characters and calculate the byte length
12 #include <sys/u8_textprep.h>
14 \fBint\fR u8_validate(\fBchar *\fR\fIu8str\fR, \fBsize_t\fR \fIn\fR, \fBchar **\fR\fIlist\fR, \fBint\fR \fIflag\fR,
15 \fBint *\fR\fIerrnum\fR);
25 The UTF-8 string to be validated.
34 The maximum number of bytes in \fIu8str\fR that can be examined and validated.
43 A list of null-terminated character strings in UTF-8 that must be additionally
44 checked against as invalid characters. The last string in \fIlist\fR must be
45 null to indicate there is no further string.
54 Possible validation options constructed by a bitwise-inclusive-OR of the
59 \fB\fBU8_VALIDATE_ENTIRE\fR\fR
63 By default, \fBu8_validate()\fR looks at the first character or up to \fIn\fR
64 bytes, whichever is smaller in terms of the number of bytes to be consumed, and
65 returns with the result.
67 When this option is used, \fBu8_validate()\fR will check up to \fIn\fR bytes
68 from \fIu8str\fR and possibly more than a character before returning the
75 \fB\fBU8_VALIDATE_CHECK_ADDITIONAL\fR\fR
79 By default, \fBu8_validate()\fR does not use list supplied.
81 When this option is supplied with a list of character strings,
82 \fBu8_validate()\fR additionally validates \fIu8str\fR against the character
83 strings supplied with \fIlist\fR and returns EBADF in \fIerrnum\fR if
84 \fIu8str\fR has any one of the character strings in \fIlist\fR.
90 \fB\fBU8_VALIDATE_UCS2_RANGE\fR\fR
94 By default, \fBu8_validate()\fR uses the entire Unicode coding space of U+0000
97 When this option is specified, the valid Unicode coding space is smaller to
109 An error occurred during validation. The following values are supported:
116 Validation failed because list-specified characters were found in the string
117 pointed to by \fIu8str\fR.
126 Validation failed because an illegal byte was found in the string pointed to by
136 Validation failed because an incomplete byte was found in the string pointed to
146 Validation failed because character bytes were encountered that are outside the
147 range of the Unicode coding space.
155 The \fBu8_validate()\fR function validates \fIu8str\fR in UTF-8 and determines
156 the number of bytes constituting the character(s) pointed to by \fIu8str\fR.
160 If \fIu8str\fR is a null pointer, \fBu8_validate()\fR returns 0. Otherwise,
161 \fBu8_validate()\fR returns either the number of bytes that constitute the
162 characters if the next \fIn\fR or fewer bytes form valid characters, or -1 if
163 there is an validation failure, in which case it may set \fIerrnum\fR to
167 \fBExample 1 \fRDetermine the length of the first UTF-8 character.
171 #include <sys/u8_textprep.h>
178 len = u8_validate(u8, 4, (char **)NULL, 0, &errnum);
183 return (MYFS4_ERR_INVAL);
185 return (MYFS4_ERR_BADNAME);
187 return (MYFS4_ERR_BADCHAR);
196 \fBExample 2 \fRCheck if there are any invalid characters in the entire string.
200 #include <sys/u8_textprep.h>
209 len = u8_validate(u8, n, (char **)NULL, U8_VALIDATE_ENTIRE, &errnum);
214 return (MYFS4_ERR_INVAL);
216 return (MYFS4_ERR_BADNAME);
218 return (MYFS4_ERR_BADCHAR);
227 \fBExample 3 \fRCheck if there is any invalid character, including prohibited
228 characters, in the entire string.
232 #include <sys/u8_textprep.h>
237 char *prohibited[4] = {
238 ".", "..", "\e\e", NULL
244 len = u8_validate(u8, n, prohibited,
245 (U8_VALIDATE_ENTIRE|U8_VALIDATE_CHECK_ADDITIONAL), &errnum);
250 return (MYFS4_ERR_INVAL);
252 return (MYFS4_ERR_BADNAME);
254 return (MYFS4_ERR_BADCHAR);
265 See \fBattributes\fR(5) for descriptions of the following attributes:
273 ATTRIBUTE TYPE ATTRIBUTE VALUE
275 Interface Stability Committed
283 \fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBattributes\fR(5),
284 \fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F), \fBu8_validate\fR(9F)
287 The Unicode Standard (http://www.unicode.org)