1/* 2 * Copyright 2018-2020 Haiku, Inc. All Right Reserved 3 * Distributed under the terms of MIT license. 4 */ 5#ifndef _UCHAR_H 6#define _UCHAR_H 7 8 9#include <stdint.h> 10#include <wchar.h> 11 12 13#ifdef __cplusplus 14extern "C" { 15#endif 16 17 18typedef uint_least32_t char32_t; 19typedef uint_least16_t char16_t; 20 21 22#define __STD_UTF_32__ 1 23#define __STD_UTF_16__ 1 24 25 26// TODO implement mbrtoc16 27 28 29static __inline size_t 30c16rtomb(char *dest, char32_t wc, mbstate_t *mbState) 31{ 32 wchar_t tmp = (wchar_t)wc; 33 return wcrtomb(dest, tmp, mbState); 34} 35 36 37static __inline size_t 38mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState) 39{ 40 return mbrtowc((wchar_t*)dest, src, srcLength, mbState); 41} 42 43 44static __inline size_t 45c32rtomb(char *dest, char32_t wc, mbstate_t *mbState) 46{ 47 return wcrtomb(dest, (wchar_t)wc, mbState); 48} 49 50 51#ifdef __cplusplus 52} 53#endif 54#endif /* _UCHAR_H */ 55