2018-05-07 17:02:21 -04:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2017-09-09 06:47:40 -04:00
|
|
|
/*
|
|
|
|
* charset conversion utils
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Rob Clark
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CHARSET_H_
|
|
|
|
#define __CHARSET_H_
|
|
|
|
|
2017-10-18 18:13:06 +02:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2017-10-09 21:09:05 +02:00
|
|
|
#define MAX_UTF8_PER_UTF16 3
|
2017-09-09 06:47:40 -04:00
|
|
|
|
|
|
|
/**
|
2018-08-31 21:31:26 +02:00
|
|
|
* u16_strlen - count non-zero words
|
2017-09-09 06:47:40 -04:00
|
|
|
*
|
2018-08-31 21:31:26 +02:00
|
|
|
* This function matches wsclen() if the -fshort-wchar compiler flag is set.
|
|
|
|
* In the EFI context we explicitly need a function handling u16 strings.
|
2017-09-09 06:47:40 -04:00
|
|
|
*
|
2018-08-31 21:31:26 +02:00
|
|
|
* @in: null terminated u16 string
|
|
|
|
* ReturnValue: number of non-zero words.
|
|
|
|
* This is not the number of utf-16 letters!
|
2017-09-09 06:47:40 -04:00
|
|
|
*/
|
2018-08-31 21:31:26 +02:00
|
|
|
size_t u16_strlen(const u16 *in);
|
2017-09-09 06:47:40 -04:00
|
|
|
|
|
|
|
/**
|
2018-08-31 21:31:26 +02:00
|
|
|
* u16_strlen - count non-zero words
|
2017-09-09 06:47:40 -04:00
|
|
|
*
|
2018-08-31 21:31:26 +02:00
|
|
|
* This function matches wscnlen_s() if the -fshort-wchar compiler flag is set.
|
|
|
|
* In the EFI context we explicitly need a function handling u16 strings.
|
2017-09-09 06:47:40 -04:00
|
|
|
*
|
2018-08-31 21:31:26 +02:00
|
|
|
* @in: null terminated u16 string
|
|
|
|
* @count: maximum number of words to count
|
|
|
|
* ReturnValue: number of non-zero words.
|
|
|
|
* This is not the number of utf-16 letters!
|
2017-09-09 06:47:40 -04:00
|
|
|
*/
|
2018-08-31 21:31:26 +02:00
|
|
|
size_t u16_strnlen(const u16 *in, size_t count);
|
2017-09-09 06:47:40 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* utf16_strcpy() - UTF16 equivalent of strcpy()
|
|
|
|
*/
|
|
|
|
uint16_t *utf16_strcpy(uint16_t *dest, const uint16_t *src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* utf16_strdup() - UTF16 equivalent of strdup()
|
|
|
|
*/
|
|
|
|
uint16_t *utf16_strdup(const uint16_t *s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* utf16_to_utf8() - Convert an utf16 string to utf8
|
|
|
|
*
|
|
|
|
* Converts 'size' characters of the utf16 string 'src' to utf8
|
|
|
|
* written to the 'dest' buffer.
|
|
|
|
*
|
2017-10-09 21:09:05 +02:00
|
|
|
* NOTE that a single utf16 character can generate up to 3 utf8
|
2017-09-09 06:47:40 -04:00
|
|
|
* characters. See MAX_UTF8_PER_UTF16.
|
|
|
|
*
|
|
|
|
* @dest the destination buffer to write the utf8 characters
|
|
|
|
* @src the source utf16 string
|
|
|
|
* @size the number of utf16 characters to convert
|
|
|
|
* @return the pointer to the first unwritten byte in 'dest'
|
|
|
|
*/
|
|
|
|
uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size);
|
|
|
|
|
2017-10-18 18:13:06 +02:00
|
|
|
/**
|
|
|
|
* utf8_to_utf16() - Convert an utf8 string to utf16
|
|
|
|
*
|
|
|
|
* Converts up to 'size' characters of the utf16 string 'src' to utf8
|
|
|
|
* written to the 'dest' buffer. Stops at 0x00.
|
|
|
|
*
|
|
|
|
* @dest the destination buffer to write the utf8 characters
|
|
|
|
* @src the source utf16 string
|
|
|
|
* @size maximum number of utf16 characters to convert
|
|
|
|
* @return the pointer to the first unwritten byte in 'dest'
|
|
|
|
*/
|
|
|
|
uint16_t *utf8_to_utf16(uint16_t *dest, const uint8_t *src, size_t size);
|
|
|
|
|
2017-09-09 06:47:40 -04:00
|
|
|
#endif /* __CHARSET_H_ */
|