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 9F "Sep 18, 2007"
8 u8_validate \- validate UTF-8 characters and calculate the byte length
12 #include <sys/types.h>
13 #include <sys/errno.h>
14 #include <sys/sunddi.h>
16 \fBint\fR u8_validate(\fBchar *\fR\fIu8str\fR, \fBsize_t\fR \fIn\fR, \fBchar **\fR\fIlist\fR, \fBint\fR \fIflag\fR,
17 \fBint *\fR\fIerrno\fR);
23 Solaris DDI specific (Solaris DDI)
31 The UTF-8 string to be validated.
40 The maximum number of bytes in \fIu8str\fR that can be examined and validated.
49 A list of null-terminated character strings in UTF-8 that must be additionally
50 checked against as invalid characters. The last string in \fIlist\fR must be
51 null to indicate there is no further string.
60 Possible validation options constructed by a bitwise-inclusive-OR of the
65 \fB\fBU8_VALIDATE_ENTIRE\fR\fR
69 By default, \fBu8_validate()\fR looks at the first character or up to \fIn\fR
70 bytes, whichever is smaller in terms of the number of bytes to be consumed, and
71 returns with the result.
73 When this option is used, \fBu8_validate()\fR will check up to \fIn\fR bytes
74 from \fIu8str\fR and possibly more than a character before returning the
81 \fB\fBU8_VALIDATE_CHECK_ADDITIONAL\fR\fR
85 By default, \fBu8_validate()\fR does not use list supplied.
87 When this option is supplied with a list of character strings,
88 \fBu8_validate()\fR additionally validates \fIu8str\fR against the character
89 strings supplied with \fIlist\fR and returns EBADF in \fIerrno\fR if
90 \fIu8str\fR has any one of the character strings in \fIlist\fR.
96 \fB\fBU8_VALIDATE_UCS2_RANGE\fR\fR
100 By default, \fBu8_validate()\fR uses the entire Unicode coding space of U+0000
103 When this option is specified, the valid Unicode coding space is smaller to
115 An error occurred during validation. The following values are supported:
122 Validation failed because list-specified characters were found in the string
123 pointed to by \fIu8str\fR.
132 Validation failed because an illegal byte was found in the string pointed to by
142 Validation failed because an incomplete byte was found in the string pointed to
152 Validation failed because character bytes were encountered that are outside the
153 range of the Unicode coding space.
161 The \fBu8_validate()\fR function validates \fIu8str\fR in UTF-8 and determines
162 the number of bytes constituting the character(s) pointed to by \fIu8str\fR.
166 If \fIu8str\fR is a null pointer, \fBu8_validate()\fR returns 0. Otherwise,
167 \fBu8_validate()\fR returns either the number of bytes that constitute the
168 characters if the next \fIn\fR or fewer bytes form valid characters, or -1 if
169 there is an validation failure, in which case it may set \fIerrno\fR to
173 \fBExample 1 \fRDetermine the length of the first UTF-8 character.
177 #include <sys/types.h>
178 #include <sys/errno.h>
179 #include <sys/sunddi.h>
186 len = u8_validate(u8, 4, (char **)NULL, 0, &errno);
191 return (MYFS4_ERR_INVAL);
193 return (MYFS4_ERR_BADNAME);
195 return (MYFS4_ERR_BADCHAR);
204 \fBExample 2 \fRCheck if there are any invalid characters in the entire string.
208 #include <sys/types.h>
209 #include <sys/errno.h>
210 #include <sys/sunddi.h>
219 len = u8_validate(u8, n, (char **)NULL, U8_VALIDATE_ENTIRE, &errno);
224 return (MYFS4_ERR_INVAL);
226 return (MYFS4_ERR_BADNAME);
228 return (MYFS4_ERR_BADCHAR);
237 \fBExample 3 \fRCheck if there is any invalid character, including prohibited
238 characters, in the entire string.
242 #include <sys/types.h>
243 #include <sys/errno.h>
244 #include <sys/sunddi.h>
249 char *prohibited[4] = {
250 ".", "..", "\e\e", NULL
256 len = u8_validate(u8, n, prohibited,
257 (U8_VALIDATE_ENTIRE|U8_VALIDATE_CHECK_ADDITIONAL), &errno);
262 return (MYFS4_ERR_INVAL);
264 return (MYFS4_ERR_BADNAME);
266 return (MYFS4_ERR_BADCHAR);
277 See \fBattributes\fR(5) for descriptions of the following attributes:
285 ATTRIBUTE TYPE ATTRIBUTE VALUE
287 Interface Stability Committed
293 \fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C),
294 \fBattributes\fR(5), \fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F),
295 \fBuconv_u16tou32\fR(9F)
298 The Unicode Standard (http://www.unicode.org)