aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-01-10 20:06:44 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-02-05 16:00:54 +0000
commitdc42b41b6238cb44c1098009e68d7d63095cbef3 (patch)
tree19612f8a63c25f66baf8eacad28931f2d302765f
parentfcft: adapt to API changes in fcft-3.x (diff)
char32: inline wcs*() wrappers
-rw-r--r--char32.c108
-rw-r--r--char32.h90
2 files changed, 70 insertions, 128 deletions
diff --git a/char32.c b/char32.c
index 6e7ce0c0..6d902906 100644
--- a/char32.c
+++ b/char32.c
@@ -33,24 +33,12 @@ _Static_assert(
#error "wchar_t does not use UTF-32"
#endif
-size_t
-c32len(const char32_t *s)
-{
- return wcslen((const wchar_t *)s);
-}
-
UNITTEST
{
xassert(c32len(U"") == 0);
xassert(c32len(U"foobar") == 6);
}
-int
-c32cmp(const char32_t *s1, const char32_t *s2)
-{
- return wcscmp((const wchar_t *)s1, (const wchar_t *)s2);
-}
-
UNITTEST
{
xassert(c32cmp(U"foobar", U"foobar") == 0);
@@ -60,12 +48,6 @@ UNITTEST
xassert(c32cmp(U"b", U"a") > 0);
}
-char32_t *
-c32ncpy(char32_t *dst, const char32_t *src, size_t n)
-{
- return (char32_t *)wcsncpy((wchar_t *)dst, (const wchar_t *)src, n);
-}
-
UNITTEST
{
char32_t copy[16];
@@ -83,12 +65,6 @@ UNITTEST
xassert(memcmp(&copy[6], zeroes, sizeof(zeroes)) == 0);
}
-char32_t *
-c32cpy(char32_t *dst, const char32_t *src)
-{
- return (char32_t *)wcscpy((wchar_t *)dst, (const wchar_t *)src);
-}
-
UNITTEST
{
char32_t copy[16];
@@ -110,18 +86,6 @@ UNITTEST
xassert(memcmp(&copy[7], fives, sizeof(fives)) == 0);
}
-char32_t *
-c32chr(const char32_t *s, char32_t c)
-{
- return (char32_t *)wcschr((const wchar_t *)s, c);
-}
-
-int
-c32casecmp(const char32_t *s1, const char32_t *s2)
-{
- return wcscasecmp((const wchar_t *)s1, (const wchar_t *)s2);
-}
-
UNITTEST
{
xassert(c32casecmp(U"foobar", U"FOOBAR") == 0);
@@ -131,12 +95,6 @@ UNITTEST
xassert(c32casecmp(U"B", U"a") > 0);
}
-int
-c32ncasecmp(const char32_t *s1, const char32_t *s2, size_t n)
-{
- return wcsncasecmp((const wchar_t *)s1, (const wchar_t *)s2, n);
-}
-
UNITTEST
{
xassert(c32ncasecmp(U"foo", U"FOObar", 3) == 0);
@@ -146,12 +104,6 @@ UNITTEST
xassert(c32ncasecmp(U"BB", U"a", 1) > 0);
}
-char32_t *
-c32ncat(char32_t *dst, const char32_t *src, size_t n)
-{
- return (char32_t *)wcsncat((wchar_t *)dst, (const wchar_t *)src, n);
-}
-
UNITTEST
{
char32_t dst[32] = U"foobar";
@@ -161,12 +113,6 @@ UNITTEST
xassert(c32cmp(dst, U"foobar12345678") == 0);
}
-char32_t *
-c32cat(char32_t *dst, const char32_t *src)
-{
- return (char32_t *)wcscat((wchar_t *)dst, (const wchar_t *)src);
-}
-
UNITTEST
{
char32_t dst[32] = U"foobar";
@@ -176,12 +122,6 @@ UNITTEST
xassert(c32cmp(dst, U"foobar12345678") == 0);
}
-char32_t *
-c32dup(const char32_t *s)
-{
- return (char32_t *)wcsdup((const wchar_t *)s);
-}
-
UNITTEST
{
char32_t *c = c32dup(U"foobar");
@@ -273,12 +213,6 @@ UNITTEST
xassert(c32[1] == 0x55555555);
}
-size_t
-mbstoc32(char32_t *dst, const char *src, size_t len)
-{
- return mbsntoc32(dst, src, strlen(src) + 1, len);
-}
-
UNITTEST
{
const char input[] = "foobarzoo";
@@ -461,45 +395,3 @@ UNITTEST
xassert(ac32tombs(NULL) == NULL);
setlocale(LC_CTYPE, "C");
}
-
-char32_t
-toc32lower(char32_t c)
-{
- return (char32_t)towlower((wint_t)c);
-}
-
-char32_t
-toc32upper(char32_t c)
-{
- return (char32_t)towupper((wint_t)c);
-}
-
-bool
-isc32space(char32_t c32)
-{
- return iswspace((wint_t)c32);
-}
-
-bool
-isc32print(char32_t c32)
-{
- return iswprint((wint_t)c32);
-}
-
-bool
-isc32graph(char32_t c32)
-{
- return iswgraph((wint_t)c32);
-}
-
-int
-c32width(char32_t c)
-{
- return wcwidth((wchar_t)c);
-}
-
-int
-c32swidth(const char32_t *s, size_t n)
-{
- return wcswidth((const wchar_t *)s, n);
-}
diff --git a/char32.h b/char32.h
index 0ce783e7..6324c9a0 100644
--- a/char32.h
+++ b/char32.h
@@ -4,32 +4,82 @@
#include <uchar.h>
#include <stddef.h>
#include <stdarg.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
-size_t c32len(const char32_t *s);
-int c32cmp(const char32_t *s1, const char32_t *s2);
+static inline size_t c32len(const char32_t *s) {
+ return wcslen((const wchar_t *)s);
+}
-char32_t *c32ncpy(char32_t *dst, const char32_t *src, size_t n);
-char32_t *c32cpy(char32_t *dst, const char32_t *src);
-char32_t *c32ncat(char32_t *dst, const char32_t *src, size_t n);
-char32_t *c32cat(char32_t *dst, const char32_t *src);
-char32_t *c32dup(const char32_t *s);
+static inline int c32cmp(const char32_t *s1, const char32_t *s2) {
+ return wcscmp((const wchar_t *)s1, (const wchar_t *)s2);
+}
-char32_t *c32chr(const char32_t *s, char32_t c);
+static inline char32_t *c32ncpy(char32_t *dst, const char32_t *src, size_t n) {
+ return (char32_t *)wcsncpy((wchar_t *)dst, (const wchar_t *)src, n);
+}
-int c32casecmp(const char32_t *s1, const char32_t *s2);
-int c32ncasecmp(const char32_t *s1, const char32_t *s2, size_t n);
+static inline char32_t *c32cpy(char32_t *dst, const char32_t *src) {
+ return (char32_t *)wcscpy((wchar_t *)dst, (const wchar_t *)src);
+}
+
+static inline char32_t *c32ncat(char32_t *dst, const char32_t *src, size_t n) {
+ return (char32_t *)wcsncat((wchar_t *)dst, (const wchar_t *)src, n);
+}
+
+static inline char32_t *c32cat(char32_t *dst, const char32_t *src) {
+ return (char32_t *)wcscat((wchar_t *)dst, (const wchar_t *)src);
+}
+
+static inline char32_t *c32dup(const char32_t *s) {
+ return (char32_t *)wcsdup((const wchar_t *)s);
+}
+
+static inline char32_t *c32chr(const char32_t *s, char32_t c) {
+ return (char32_t *)wcschr((const wchar_t *)s, c);
+}
+
+static inline int c32casecmp(const char32_t *s1, const char32_t *s2) {
+ return wcscasecmp((const wchar_t *)s1, (const wchar_t *)s2);
+}
+
+static inline int c32ncasecmp(const char32_t *s1, const char32_t *s2, size_t n) {
+ return wcsncasecmp((const wchar_t *)s1, (const wchar_t *)s2, n);
+}
+
+static inline char32_t toc32lower(char32_t c) {
+ return (char32_t)towlower((wint_t)c);
+}
+
+static inline char32_t toc32upper(char32_t c) {
+ return (char32_t)towupper((wint_t)c);
+}
+
+static inline bool isc32space(char32_t c32) {
+ return iswspace((wint_t)c32);
+}
+
+static inline bool isc32print(char32_t c32) {
+ return iswprint((wint_t)c32);
+}
+
+static inline bool isc32graph(char32_t c32) {
+ return iswgraph((wint_t)c32);
+}
+
+static inline int c32width(char32_t c) {
+ return wcwidth((wchar_t)c);
+}
+
+static inline int c32swidth(const char32_t *s, size_t n) {
+ return wcswidth((const wchar_t *)s, n);
+}
size_t mbsntoc32(char32_t *dst, const char *src, size_t nms, size_t len);
-size_t mbstoc32(char32_t *dst, const char *src, size_t len);
char32_t *ambstoc32(const char *src);
char *ac32tombs(const char32_t *src);
-char32_t toc32lower(char32_t c);
-char32_t toc32upper(char32_t c);
-
-bool isc32space(char32_t c32);
-bool isc32print(char32_t c32);
-bool isc32graph(char32_t c32);
-
-int c32width(char32_t c);
-int c32swidth(const char32_t *s, size_t n);
+static inline size_t mbstoc32(char32_t *dst, const char *src, size_t len) {
+ return mbsntoc32(dst, src, strlen(src) + 1, len);
+}