1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * charset conversion utils
5 * Copyright (c) 2017 Rob Clark
11 #include <linux/types.h>
13 #define MAX_UTF8_PER_UTF16 3
16 * u16_strlen - count non-zero words
18 * This function matches wsclen() if the -fshort-wchar compiler flag is set.
19 * In the EFI context we explicitly need a function handling u16 strings.
21 * @in: null terminated u16 string
22 * ReturnValue: number of non-zero words.
23 * This is not the number of utf-16 letters!
25 size_t u16_strlen(const u16 *in);
28 * u16_strlen - count non-zero words
30 * This function matches wscnlen_s() if the -fshort-wchar compiler flag is set.
31 * In the EFI context we explicitly need a function handling u16 strings.
33 * @in: null terminated u16 string
34 * @count: maximum number of words to count
35 * ReturnValue: number of non-zero words.
36 * This is not the number of utf-16 letters!
38 size_t u16_strnlen(const u16 *in, size_t count);
41 * utf16_strcpy() - UTF16 equivalent of strcpy()
43 uint16_t *utf16_strcpy(uint16_t *dest, const uint16_t *src);
46 * utf16_strdup() - UTF16 equivalent of strdup()
48 uint16_t *utf16_strdup(const uint16_t *s);
51 * utf16_to_utf8() - Convert an utf16 string to utf8
53 * Converts 'size' characters of the utf16 string 'src' to utf8
54 * written to the 'dest' buffer.
56 * NOTE that a single utf16 character can generate up to 3 utf8
57 * characters. See MAX_UTF8_PER_UTF16.
59 * @dest the destination buffer to write the utf8 characters
60 * @src the source utf16 string
61 * @size the number of utf16 characters to convert
62 * @return the pointer to the first unwritten byte in 'dest'
64 uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size);
67 * utf8_to_utf16() - Convert an utf8 string to utf16
69 * Converts up to 'size' characters of the utf16 string 'src' to utf8
70 * written to the 'dest' buffer. Stops at 0x00.
72 * @dest the destination buffer to write the utf8 characters
73 * @src the source utf16 string
74 * @size maximum number of utf16 characters to convert
75 * @return the pointer to the first unwritten byte in 'dest'
77 uint16_t *utf8_to_utf16(uint16_t *dest, const uint8_t *src, size_t size);
79 #endif /* __CHARSET_H_ */