summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_utf8.h
blob: b4625fbda3b3ba6ff3b7eee5fbc8b4ae5118fafa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <sys/types.h>

/* Checks if a string is valid UTF-8.
 *
 * Supports 1 to 4 character UTF-8 sequences. Passes tests here:
 *    https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
 *
 * Exceptions: The following unicode non-characters are allowed:
 *    U+FFFE, U+FFFF, U+FDD0 - U+FDEF, U+nFFFE (n = 1 - 10),
 *    U+nFFFD (n = 1 - 10).
 *
 * Args:
 *    string[in] - a string.
 *    bad_pos[out] - position of the first bad character.
 *
 * Returns:
 *    1 if it is a vlid utf-8 string. 0 otherwise.
 *    bad_pos contains the strlen() of the string if it is
 *    valid.
 */
int valid_utf8_string(const char *string, size_t *bad_pos);

/* Checks if a string is a valid utf-8 string.
 *
 * Args:
 *    string[in] - a string.
 *
 * Returns:
 *    1 if it is a valid utf-8 string. 0 otherwise.
 */
int is_utf8_string(const char *string);