[haiku-commits] Change in haiku[master]: uchar.h: char16_t must be uint_least16_t

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 9 May 2020 11:17:06 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2623 ;)


Change subject: uchar.h: char16_t must be uint_least16_t
......................................................................

uchar.h: char16_t must be uint_least16_t

We attempted to make it a 32bit char type, but that is actually not allowed
unless we also make uint_least16_t a 32bit type. And even then, we
wouldn't be allowed to store or handle values wider than 16bit.

Comply more closely to the standard. As a result, mbtoc16r is not
implemented. c16rtomb is implemented by casting the char to 32bit, which
isn't really correct either (I think you're supposed to be able to feed
the two halves of a > 16bit codepoint in two separate calls and get a
meaningful result out?)

Related to #15990 but we may want an actual implementation?
---
M headers/posix/uchar.h
1 file changed, 27 insertions(+), 12 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/23/2623/1

diff --git a/headers/posix/uchar.h b/headers/posix/uchar.h
index 72f3ac1..8b090cb 100644
--- a/headers/posix/uchar.h
+++ b/headers/posix/uchar.h
@@ -1,44 +1,59 @@
 /*
- * Copyright 2018 Haiku, Inc. All Right Reserved
+ * Copyright 2018-2020 Haiku, Inc. All Right Reserved
  * Distributed under the terms of MIT license.
  */
 #ifndef _UCHAR_H
 #define _UCHAR_H

+
 #include <wchar.h>

+
 #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 */
+typedef uint_least32_t char32_t;
+typedef uint_least16_t char16_t;
+
+
+#define __STD_UTF_32__ 1
+#define __STD_UTF_16__ 1
+
+
+// TODO implement mbrtoc16
+
+
 static __inline size_t
-c16rtomb(char *dest, char16_t wc, mbstate_t *mbState)
+c16rtomb(char *dest, char32_t wc, mbstate_t *mbState)
 {
-       return wcrtomb(dest, wc, mbState);
+       wchar_t tmp = (wchar_t)wc;
+       return wcrtomb(dest, tmp, mbState);
 }
+
+
 static __inline size_t
-mbrtoc16(char16_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
+mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
 {
-       return mbrtowc(dest, src, srcLength, 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, wc, mbState);
+       return wcrtomb(dest, (wchar_t)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);
+       return mbrtowc((wchar_t*)dest, src, srcLength, mbState);
 }

+
 #ifdef __cplusplus
 }
 #endif

--
To view, visit https://review.haiku-os.org/c/haiku/+/2623
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: If8198675c27dd2aa412bc44d12d3df4e31d3e8c7
Gerrit-Change-Number: 2623
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: uchar.h: char16_t must be uint_least16_t - Gerrit