From cedb0e11796a9d66dae7adacfe44eb0f60fb107c Mon Sep 17 00:00:00 2001 From: Leorize Date: Sat, 13 Jan 2018 11:22:51 +0700 Subject: [PATCH] uchar: Introduce C11 uchar.h Currently this implementation only supports UTF-32 --- headers/posix/uchar.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 headers/posix/uchar.h diff --git a/headers/posix/uchar.h b/headers/posix/uchar.h new file mode 100644 index 0000000000..72f3ac18cd --- /dev/null +++ b/headers/posix/uchar.h @@ -0,0 +1,45 @@ +/* + * Copyright 2018 Haiku, Inc. All Right Reserved + * Distributed under the terms of MIT license. + */ +#ifndef _UCHAR_H +#define _UCHAR_H + +#include + +#ifdef __cplusplus +extern "C" { +#else +typedef wchar_t char32_t; /* our wchar_t is utf32 */ +typedef wchar_t char16_t; +#endif + +#define __STD_UTF_32__ 1 + +/* We don't define __STD_UTF_16__, so the format of char16_t is unspecified */ +static __inline size_t +c16rtomb(char *dest, char16_t wc, mbstate_t *mbState) +{ + return wcrtomb(dest, wc, mbState); +} +static __inline size_t +mbrtoc16(char16_t *dest, const char *src, size_t srcLength, mbstate_t *mbState) +{ + return mbrtowc(dest, src, srcLength, mbState); +} + +static __inline size_t +c32rtomb(char *dest, char32_t wc, mbstate_t *mbState) +{ + return wcrtomb(dest, wc, mbState); +} +static __inline size_t +mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState) +{ + return mbrtowc(dest, src, srcLength, mbState); +} + +#ifdef __cplusplus +} +#endif +#endif /* _UCHAR_H */