1 /* Copyright 2016 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #include <sys/types.h> 7 8 /* Checks if a string is valid UTF-8. 9 * 10 * Supports 1 to 4 character UTF-8 sequences. Passes tests here: 11 * https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt 12 * 13 * Exceptions: The following unicode non-characters are allowed: 14 * U+FFFE, U+FFFF, U+FDD0 - U+FDEF, U+nFFFE (n = 1 - 10), 15 * U+nFFFD (n = 1 - 10). 16 * 17 * Args: 18 * string[in] - a string. 19 * bad_pos[out] - position of the first bad character. 20 * 21 * Returns: 22 * 1 if it is a vlid utf-8 string. 0 otherwise. 23 * bad_pos contains the strlen() of the string if it is 24 * valid. 25 */ 26 int valid_utf8_string(const char *string, size_t *bad_pos); 27 28 /* Checks if a string is a valid utf-8 string. 29 * 30 * Args: 31 * string[in] - a string. 32 * 33 * Returns: 34 * 1 if it is a valid utf-8 string. 0 otherwise. 35 */ 36 int is_utf8_string(const char *string); 37