uchar/wchar/wctype: reorganize definitions
uchar.h: only define char32_t and char16_t before c++11 found while testing libc++ https://en.cppreference.com/cpp/keyword/char16_t https://en.cppreference.com/cpp/keyword/char32_t add _wint_t.h and _mbstate_t.h Change-Id: Ia5529cc9aa7316e091297f9842c3007a855f813e Reviewed-on: https://review.haiku-os.org/c/haiku/+/11346 Reviewed-by: Adrien Destugues <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: Jérôme Duval <[email protected]> (cherry picked from commit bf1e1da47d6181dbf8122bc52801c08968e1a4ed) Reviewed-on: https://review.haiku-os.org/c/haiku/+/11374 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
064878d320
commit
d653556ecd
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2008-2012 Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef __MBSTATE_T_H
|
||||
#define __MBSTATE_T_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
void* converter;
|
||||
char charset[64];
|
||||
unsigned int count;
|
||||
char data[1024 + 8]; /* 1024 bytes for data, 8 for alignment space */
|
||||
} mbstate_t;
|
||||
|
||||
|
||||
#endif /* __MBSTATE_T_H */
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2008-2012 Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef __WINT_T_H
|
||||
#define __WINT_T_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/* stddef.h is not supposed to define wint_t, but gcc 2.95.3's one does.
|
||||
* In all other cases we will do that. */
|
||||
#ifndef _WINT_T
|
||||
#define _WINT_T
|
||||
|
||||
#ifndef __WINT_TYPE__
|
||||
#define __WINT_TYPE__ unsigned int
|
||||
#endif
|
||||
|
||||
typedef __WINT_TYPE__ wint_t;
|
||||
|
||||
#endif /* _WINT_T */
|
||||
|
||||
#define WEOF ((wint_t)(-1))
|
||||
|
||||
typedef int wctype_t;
|
||||
|
||||
|
||||
#endif /* __WINT_T_H */
|
||||
@@ -138,6 +138,8 @@ typedef uint64_t uintmax_t;
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX ((wint_t)-1)
|
||||
|
||||
#define WCHAR_MIN 0x00000000UL
|
||||
#define WCHAR_MAX 0x7FFFFFFFUL
|
||||
|
||||
/* Macros of Integer Constant Expressions */
|
||||
#define INT8_C(value) value
|
||||
|
||||
+11
-25
@@ -7,7 +7,14 @@
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <wchar.h>
|
||||
#include <wchar_t.h>
|
||||
#include <_mbstate_t.h>
|
||||
|
||||
|
||||
#if !defined(__cplusplus) || __cplusplus < 201103L
|
||||
typedef uint_least32_t char32_t;
|
||||
typedef uint_least16_t char16_t;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -15,10 +22,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef uint_least32_t char32_t;
|
||||
typedef uint_least16_t char16_t;
|
||||
|
||||
|
||||
#define __STD_UTF_32__ 1
|
||||
#define __STD_UTF_16__ 1
|
||||
|
||||
@@ -26,26 +29,9 @@ typedef uint_least16_t char16_t;
|
||||
// TODO implement mbrtoc16
|
||||
|
||||
|
||||
static __inline size_t
|
||||
c16rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
||||
{
|
||||
wchar_t tmp = (wchar_t)wc;
|
||||
return wcrtomb(dest, tmp, mbState);
|
||||
}
|
||||
|
||||
|
||||
static __inline size_t
|
||||
mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
|
||||
{
|
||||
return mbrtowc((wchar_t*)dest, src, srcLength, mbState);
|
||||
}
|
||||
|
||||
|
||||
static __inline size_t
|
||||
c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
||||
{
|
||||
return wcrtomb(dest, (wchar_t)wc, mbState);
|
||||
}
|
||||
size_t c16rtomb(char *dest, char32_t wc, mbstate_t *mbState);
|
||||
size_t mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState);
|
||||
size_t c32rtomb(char *dest, char32_t wc, mbstate_t *mbState);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+4
-24
@@ -12,34 +12,14 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
/* stddef.h is not supposed to define wint_t, but gcc 2.95.3's one does.
|
||||
* In all other cases we will do that. */
|
||||
#ifndef _WINT_T
|
||||
#define _WINT_T
|
||||
|
||||
#ifndef __WINT_TYPE__
|
||||
#define __WINT_TYPE__ unsigned int
|
||||
#endif
|
||||
|
||||
typedef __WINT_TYPE__ wint_t;
|
||||
|
||||
#endif /* _WINT_T */
|
||||
|
||||
typedef int wctype_t;
|
||||
|
||||
typedef struct {
|
||||
void* converter;
|
||||
char charset[64];
|
||||
unsigned int count;
|
||||
char data[1024 + 8]; /* 1024 bytes for data, 8 for alignment space */
|
||||
} mbstate_t;
|
||||
#include <_mbstate_t.h>
|
||||
#include <_wint_t.h>
|
||||
|
||||
|
||||
#define WEOF ((wint_t)(-1))
|
||||
|
||||
#ifndef WCHAR_MIN
|
||||
#define WCHAR_MIN 0x00000000UL
|
||||
#define WCHAR_MAX 0x7FFFFFFFUL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Haiku is always using UTF32 in wchars, other encodings can be handled
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
#include <locale_t.h>
|
||||
#include <wchar.h>
|
||||
#include <_wint_t.h>
|
||||
|
||||
typedef int wctrans_t;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user