From 1554ecc9334373257b7b3a72971cf25a1179ec16 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 15 Aug 2021 00:42:38 -0700 Subject: utf: Use C99 types for UTF-16/32 character instead of C11 char16_t/char32_t Some operating systems do not support uchar.h, and glibc only defines char16_t/char32_t for GNU C compilers. --- utf.c | 11 ++++++----- utf.h | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/utf.c b/utf.c index a8f5a49..e399e99 100644 --- a/utf.c +++ b/utf.c @@ -1,8 +1,9 @@ -#include +#include +#include #include "utf.h" size_t -utf8enc(char32_t c, char *s) +utf8enc(uint_least32_t c, char *s) { if (c < 0x80) { s[0] = c; @@ -30,11 +31,11 @@ utf8enc(char32_t c, char *s) } size_t -utf8dec(const char *s, size_t n, char32_t *c) +utf8dec(const char *s, size_t n, uint_least32_t *c) { size_t i, l; unsigned char b; - char32_t x; + uint_least32_t x; b = s[0]; if (b < 0x80) { @@ -64,7 +65,7 @@ utf8dec(const char *s, size_t n, char32_t *c) } size_t -utf16enc(char32_t c, char16_t *s) +utf16enc(uint_least32_t c, uint_least16_t *s) { if (c < 0xd800 || c - 0xe000 < 0x2000) { s[0] = c; diff --git a/utf.h b/utf.h index 3f360ad..5851468 100644 --- a/utf.h +++ b/utf.h @@ -1,3 +1,3 @@ -size_t utf8enc(char32_t, char *); -size_t utf8dec(const char *, size_t, char32_t *); -size_t utf16enc(char32_t, char16_t *); +size_t utf8enc(uint_least32_t, char *); +size_t utf8dec(const char *, size_t, uint_least32_t *); +size_t utf16enc(uint_least32_t, uint_least16_t *); -- cgit v1.2.3