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_MIN 0
|
||||||
#define WINT_MAX ((wint_t)-1)
|
#define WINT_MAX ((wint_t)-1)
|
||||||
|
|
||||||
|
#define WCHAR_MIN 0x00000000UL
|
||||||
|
#define WCHAR_MAX 0x7FFFFFFFUL
|
||||||
|
|
||||||
/* Macros of Integer Constant Expressions */
|
/* Macros of Integer Constant Expressions */
|
||||||
#define INT8_C(value) value
|
#define INT8_C(value) value
|
||||||
|
|||||||
+11
-25
@@ -7,7 +7,14 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#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
|
#ifdef __cplusplus
|
||||||
@@ -15,10 +22,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef uint_least32_t char32_t;
|
|
||||||
typedef uint_least16_t char16_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define __STD_UTF_32__ 1
|
#define __STD_UTF_32__ 1
|
||||||
#define __STD_UTF_16__ 1
|
#define __STD_UTF_16__ 1
|
||||||
|
|
||||||
@@ -26,26 +29,9 @@ typedef uint_least16_t char16_t;
|
|||||||
// TODO implement mbrtoc16
|
// TODO implement mbrtoc16
|
||||||
|
|
||||||
|
|
||||||
static __inline size_t
|
size_t c16rtomb(char *dest, char32_t wc, mbstate_t *mbState);
|
||||||
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);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
+4
-24
@@ -12,34 +12,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <_mbstate_t.h>
|
||||||
/* stddef.h is not supposed to define wint_t, but gcc 2.95.3's one does.
|
#include <_wint_t.h>
|
||||||
* 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;
|
|
||||||
|
|
||||||
|
|
||||||
#define WEOF ((wint_t)(-1))
|
#ifndef WCHAR_MIN
|
||||||
|
|
||||||
#define WCHAR_MIN 0x00000000UL
|
#define WCHAR_MIN 0x00000000UL
|
||||||
#define WCHAR_MAX 0x7FFFFFFFUL
|
#define WCHAR_MAX 0x7FFFFFFFUL
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Haiku is always using UTF32 in wchars, other encodings can be handled
|
* Haiku is always using UTF32 in wchars, other encodings can be handled
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <locale_t.h>
|
#include <locale_t.h>
|
||||||
#include <wchar.h>
|
#include <_wint_t.h>
|
||||||
|
|
||||||
typedef int wctrans_t;
|
typedef int wctrans_t;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <wcsmbs/wchar.h>
|
#include <wcsmbs/wchar.h>
|
||||||
|
|
||||||
# ifdef _WCHAR_H
|
# ifdef _WCHAR_H
|
||||||
typedef unsigned long int wctype_t;
|
|
||||||
|
|
||||||
/* Now define the internal interfaces. */
|
/* Now define the internal interfaces. */
|
||||||
extern int __wcscasecmp (__const wchar_t *__s1, __const wchar_t *__s2)
|
extern int __wcscasecmp (__const wchar_t *__s1, __const wchar_t *__s2)
|
||||||
|
|||||||
@@ -89,25 +89,8 @@ typedef struct
|
|||||||
/* Public type. */
|
/* Public type. */
|
||||||
typedef __mbstate_t mbstate_t;
|
typedef __mbstate_t mbstate_t;
|
||||||
|
|
||||||
#ifndef WCHAR_MIN
|
|
||||||
/* These constants might also be defined in <inttypes.h>. */
|
|
||||||
# define WCHAR_MIN __WCHAR_MIN
|
|
||||||
# define WCHAR_MAX __WCHAR_MAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WEOF
|
|
||||||
# define WEOF (0xffffffffu)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* For XPG4 compliance we have to define the stuff from <wctype.h> here
|
|
||||||
as well. */
|
|
||||||
#if defined __USE_XOPEN && !defined __USE_UNIX98
|
|
||||||
# include <wctype.h>
|
# include <wctype.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This incomplete type is defined in <time.h> but needed here because
|
|
||||||
of `wcsftime'. */
|
|
||||||
struct tm;
|
|
||||||
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
|
|
||||||
MergeObject <$(architecture)>posix_wchar.o :
|
MergeObject <$(architecture)>posix_wchar.o :
|
||||||
btowc.c
|
btowc.c
|
||||||
|
uchar.cpp
|
||||||
mblen.c
|
mblen.c
|
||||||
mbrlen.c
|
mbrlen.c
|
||||||
mbrtowc.cpp
|
mbrtowc.cpp
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#include <uchar.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
|
||||||
|
static mbstate_t c16rtombState;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" size_t
|
||||||
|
c16rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
||||||
|
{
|
||||||
|
if (mbState == NULL)
|
||||||
|
mbState = &c16rtombState;
|
||||||
|
wchar_t tmp = (wchar_t)wc;
|
||||||
|
return wcrtomb(dest, tmp, mbState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static mbstate_t mbrtoc32State;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" size_t
|
||||||
|
mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
|
||||||
|
{
|
||||||
|
if (mbState == NULL)
|
||||||
|
mbState = &mbrtoc32State;
|
||||||
|
return mbrtowc((wchar_t*)dest, src, srcLength, mbState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static mbstate_t c32rtombState;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" size_t
|
||||||
|
c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
|
||||||
|
{
|
||||||
|
if (mbState == NULL)
|
||||||
|
mbState = &c32rtombState;
|
||||||
|
return wcrtomb(dest, (wchar_t)wc, mbState);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user