aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-08-15 00:42:38 -0700
committerMichael Forney <mforney@mforney.org>2021-08-15 00:42:38 -0700
commit1554ecc9334373257b7b3a72971cf25a1179ec16 (patch)
treebeedf06d915f23d7e362a0cc935605508a10c861
parent8755378092c00fbae007abbd3f5cb83df0f50ac2 (diff)
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.
-rw-r--r--utf.c11
-rw-r--r--utf.h6
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 <uchar.h>
+#include <stddef.h>
+#include <stdint.h>
#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 *);