xref: /OK3568_Linux_fs/u-boot/include/charset.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  charset conversion utils
3  *
4  *  Copyright (c) 2017 Rob Clark
5  *
6  *  SPDX-License-Identifier:     GPL-2.0+
7  */
8 
9 #ifndef __CHARSET_H_
10 #define __CHARSET_H_
11 
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 
15 #define MAX_UTF8_PER_UTF16 4
16 
17 /**
18  * utf16_strlen() - Get the length of an utf16 string
19  *
20  * Returns the number of 16 bit characters in an utf16 string, not
21  * including the terminating NULL character.
22  *
23  * @in     the string to measure
24  * @return the string length
25  */
26 size_t utf16_strlen(const uint16_t *in);
27 
28 /**
29  * utf16_strnlen() - Get the length of a fixed-size utf16 string.
30  *
31  * Returns the number of 16 bit characters in an utf16 string,
32  * not including the terminating NULL character, but at most
33  * 'count' number of characters.  In doing this, utf16_strnlen()
34  * looks at only the first 'count' characters.
35  *
36  * @in     the string to measure
37  * @count  the maximum number of characters to count
38  * @return the string length, up to a maximum of 'count'
39  */
40 size_t utf16_strnlen(const uint16_t *in, size_t count);
41 
42 /**
43  * utf16_strcpy() - UTF16 equivalent of strcpy()
44  */
45 uint16_t *utf16_strcpy(uint16_t *dest, const uint16_t *src);
46 
47 /**
48  * utf16_strdup() - UTF16 equivalent of strdup()
49  */
50 uint16_t *utf16_strdup(const uint16_t *s);
51 
52 /**
53  * utf16_to_utf8() - Convert an utf16 string to utf8
54  *
55  * Converts 'size' characters of the utf16 string 'src' to utf8
56  * written to the 'dest' buffer.
57  *
58  * NOTE that a single utf16 character can generate up to 4 utf8
59  * characters.  See MAX_UTF8_PER_UTF16.
60  *
61  * @dest   the destination buffer to write the utf8 characters
62  * @src    the source utf16 string
63  * @size   the number of utf16 characters to convert
64  * @return the pointer to the first unwritten byte in 'dest'
65  */
66 uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size);
67 
68 #endif /* __CHARSET_H_ */
69