'\" 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_VALIDATE 3C "Sep 18, 2007" .SH NAME u8_validate \- validate UTF-8 characters and calculate the byte length .SH SYNOPSIS .LP .nf #include \fBint\fR u8_validate(\fBchar *\fR\fIu8str\fR, \fBsize_t\fR \fIn\fR, \fBchar **\fR\fIlist\fR, \fBint\fR \fIflag\fR, \fBint *\fR\fIerrnum\fR); .fi .SH PARAMETERS .sp .ne 2 .na \fB\fIu8str\fR\fR .ad .RS 10n The UTF-8 string to be validated. .RE .sp .ne 2 .na \fB\fIn\fR\fR .ad .RS 10n The maximum number of bytes in \fIu8str\fR that can be examined and validated. .RE .sp .ne 2 .na \fB\fIlist\fR\fR .ad .RS 10n A list of null-terminated character strings in UTF-8 that must be additionally checked against as invalid characters. The last string in \fIlist\fR must be null to indicate there is no further string. .RE .sp .ne 2 .na \fB\fIflag\fR\fR .ad .RS 10n Possible validation options constructed by a bitwise-inclusive-OR of the following values: .sp .ne 2 .na \fB\fBU8_VALIDATE_ENTIRE\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR looks at the first character or up to \fIn\fR bytes, whichever is smaller in terms of the number of bytes to be consumed, and returns with the result. .sp When this option is used, \fBu8_validate()\fR will check up to \fIn\fR bytes from \fIu8str\fR and possibly more than a character before returning the result. .RE .sp .ne 2 .na \fB\fBU8_VALIDATE_CHECK_ADDITIONAL\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR does not use list supplied. .sp When this option is supplied with a list of character strings, \fBu8_validate()\fR additionally validates \fIu8str\fR against the character strings supplied with \fIlist\fR and returns EBADF in \fIerrnum\fR if \fIu8str\fR has any one of the character strings in \fIlist\fR. .RE .sp .ne 2 .na \fB\fBU8_VALIDATE_UCS2_RANGE\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR uses the entire Unicode coding space of U+0000 to U+10FFFF. .sp When this option is specified, the valid Unicode coding space is smaller to U+0000 to U+FFFF. .RE .RE .sp .ne 2 .na \fB\fIerrnum\fR\fR .ad .RS 10n An error occurred during validation. The following values are supported: .sp .ne 2 .na \fB\fBEBADF\fR\fR .ad .RS 10n Validation failed because list-specified characters were found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .na \fB\fBEILSEQ\fR\fR .ad .RS 10n Validation failed because an illegal byte was found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 10n Validation failed because an incomplete byte was found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .na \fB\fBERANGE\fR\fR .ad .RS 10n Validation failed because character bytes were encountered that are outside the range of the Unicode coding space. .RE .RE .SH DESCRIPTION .sp .LP The \fBu8_validate()\fR function validates \fIu8str\fR in UTF-8 and determines the number of bytes constituting the character(s) pointed to by \fIu8str\fR. .SH RETURN VALUES .sp .LP If \fIu8str\fR is a null pointer, \fBu8_validate()\fR returns 0. Otherwise, \fBu8_validate()\fR returns either the number of bytes that constitute the characters if the next \fIn\fR or fewer bytes form valid characters, or -1 if there is an validation failure, in which case it may set \fIerrnum\fR to indicate the error. .SH EXAMPLES .LP \fBExample 1 \fRDetermine the length of the first UTF-8 character. .sp .in +2 .nf #include char u8[MAXPATHLEN]; int errnum; \&. \&. \&. len = u8_validate(u8, 4, (char **)NULL, 0, &errnum); if (len == -1) { switch (errnum) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .LP \fBExample 2 \fRCheck if there are any invalid characters in the entire string. .sp .in +2 .nf #include char u8[MAXPATHLEN]; int n; int errnum; \&. \&. \&. n = strlen(u8); len = u8_validate(u8, n, (char **)NULL, U8_VALIDATE_ENTIRE, &errnum); if (len == -1) { switch (errnum) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .LP \fBExample 3 \fRCheck if there is any invalid character, including prohibited characters, in the entire string. .sp .in +2 .nf #include char u8[MAXPATHLEN]; int n; int errnum; char *prohibited[4] = { ".", "..", "\e\e", NULL }; \&. \&. \&. n = strlen(u8); len = u8_validate(u8, n, prohibited, (U8_VALIDATE_ENTIRE|U8_VALIDATE_CHECK_ADDITIONAL), &errnum); if (len == -1) { switch (errnum) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe .TE .SH SEE ALSO .sp .LP .BR u8_strcmp (3C), .BR u8_textprep_str (3C), .BR attributes (7), .BR u8_strcmp (9F), .BR u8_textprep_str (9F), .BR u8_validate (9F) .sp .LP The Unicode Standard (http://www.unicode.org)