2018-01-13 07:22:51 +03:00
|
|
|
/*
|
2020-05-09 14:11:45 +03:00
|
|
|
* Copyright 2018-2020 Haiku, Inc. All Right Reserved
|
2018-01-13 07:22:51 +03:00
|
|
|
* Distributed under the terms of MIT license.
|
|
|
|
*/
|
|
|
|
#ifndef _UCHAR_H
|
|
|
|
#define _UCHAR_H
|
|
|
|
|
2020-05-09 14:11:45 +03:00
|
|
|
|
2023-04-08 19:22:32 +03:00
|
|
|
#include <stdint.h>
|
2018-01-13 07:22:51 +03:00
|
|
|
#include <wchar.h>
|
|
|
|
|
2020-05-09 14:11:45 +03:00
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-05-09 14:11:45 +03:00
|
|
|
|
|
|
|
typedef uint_least32_t char32_t;
|
|
|
|
typedef uint_least16_t char16_t;
|
|
|
|
|
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
#define __STD_UTF_32__ 1
|
2020-05-09 14:11:45 +03:00
|
|
|
#define __STD_UTF_16__ 1
|
|
|
|
|
|
|
|
|
|
|
|
// TODO implement mbrtoc16
|
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
|
|
|
|
static __inline size_t
|
2020-05-09 14:11:45 +03:00
|
|
|
c16rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
2018-01-13 07:22:51 +03:00
|
|
|
{
|
2020-05-09 14:11:45 +03:00
|
|
|
wchar_t tmp = (wchar_t)wc;
|
|
|
|
return wcrtomb(dest, tmp, mbState);
|
2018-01-13 07:22:51 +03:00
|
|
|
}
|
2020-05-09 14:11:45 +03:00
|
|
|
|
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
static __inline size_t
|
2020-05-09 14:11:45 +03:00
|
|
|
mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
|
2018-01-13 07:22:51 +03:00
|
|
|
{
|
2020-05-09 14:11:45 +03:00
|
|
|
return mbrtowc((wchar_t*)dest, src, srcLength, mbState);
|
2018-01-13 07:22:51 +03:00
|
|
|
}
|
|
|
|
|
2020-05-09 14:11:45 +03:00
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
static __inline size_t
|
|
|
|
c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
|
|
|
{
|
2020-05-09 14:11:45 +03:00
|
|
|
return wcrtomb(dest, (wchar_t)wc, mbState);
|
2018-01-13 07:22:51 +03:00
|
|
|
}
|
2020-05-09 14:11:45 +03:00
|
|
|
|
|
|
|
|
2018-01-13 07:22:51 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _UCHAR_H */
|