diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-05-14 23:59:05 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-05-14 23:59:05 +0200 |
commit | 1aeb7e2b426e7a94cdd4f83c4337f44c0f5a2ca8 (patch) | |
tree | b80d1751bebed6dd39c34fa0a1b832c714e57292 /include/unicode | |
parent | a624e3343e1183aa0f2d4b05afea50eef348651a (diff) |
Add encoding-generic macros
Diffstat (limited to 'include/unicode')
-rw-r--r-- | include/unicode/prop.h | 2 | ||||
-rw-r--r-- | include/unicode/string.h | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/include/unicode/prop.h b/include/unicode/prop.h index 0fbd479..422fa58 100644 --- a/include/unicode/prop.h +++ b/include/unicode/prop.h @@ -6,7 +6,7 @@ #include "_attrs.h" #include "_rune.h" -#include "_u8view.h" +#include "_uNview.h" struct rview { const rune *p; diff --git a/include/unicode/string.h b/include/unicode/string.h index 0c7ef79..a5b1cdb 100644 --- a/include/unicode/string.h +++ b/include/unicode/string.h @@ -5,7 +5,7 @@ #include "_alloc_fn.h" #include "_charN_t.h" -#include "_u8view.h" +#include "_uNview.h" /* clang-format off */ @@ -23,11 +23,9 @@ enum [[clang::flag_enum]] caseflags { [[nodiscard]] size_t u8gcnt(struct u8view); [[nodiscard]] size_t u8wcnt(struct u8view); [[nodiscard]] size_t u8wcnt_human(struct u8view); - size_t u8gnext(struct u8view *, struct u8view *); size_t u8wnext(struct u8view *, struct u8view *); size_t u8wnext_human(struct u8view *, struct u8view *); - [[nodiscard]] char8_t *u8casefold(size_t *, struct u8view, enum caseflags, alloc_fn, void *); [[nodiscard]] char8_t *u8lower(size_t *, struct u8view, enum caseflags, @@ -36,9 +34,34 @@ size_t u8wnext_human(struct u8view *, struct u8view *); alloc_fn, void *); [[nodiscard]] char8_t *u8upper(size_t *, struct u8view, enum caseflags, alloc_fn, void *); - +[[nodiscard]] char8_t *u8norm_nfc(size_t *, struct u8view, alloc_fn, void *); [[nodiscard]] char8_t *u8norm_nfd(size_t *, struct u8view, alloc_fn, void *); +/* Encoding-generic macros */ +#define ucsgcnt(sv) _Generic((sv), struct u8view: u8gcnt)((sv)) +#define ucswcnt(sv) _Generic((sv), struct u8view: u8wcnt)((sv)) +#define ucswcnt_human(sv) _Generic((sv), struct u8view: u8wcnt_human)((sv)) +#define ucsgnext(g, sv) _Generic((sv), struct u8view *: u8gnext)((g), (sv)) +#define ucswnext(g, sv) _Generic((sv), struct u8view *: u8wnext)((g), (sv)) +#define ucswnext_human(g, sv) \ + _Generic((sv), struct u8view *: u8wnext_human)((g), (sv)) +#define ucscasefold(dstn, sv, flags, alloc, ctx) \ + _Generic((sv), struct u8view: u8casefold)((dstn), (sv), (flags), (alloc), \ + (ctx)) +#define ucslower(dstn, sv, flags, alloc, ctx) \ + _Generic((sv), struct u8view: u8lower)((dstn), (sv), (flags), (alloc), \ + (ctx)) +#define ucstitle(dstn, sv, flags, alloc, ctx) \ + _Generic((sv), struct u8view: u8title)((dstn), (sv), (flags), (alloc), \ + (ctx)) +#define ucsupper(dstn, sv, flags, alloc, ctx) \ + _Generic((sv), struct u8view: u8upper)((dstn), (sv), (flags), (alloc), \ + (ctx)) +#define ucsnorm_nfc(dstn, sv, alloc, ctx) \ + _Generic((sv), struct u8view: u8norm_nfc)((dstn), (sv), (alloc), (ctx)) +#define ucsnorm_nfd(dstn, sv, alloc, ctx) \ + _Generic((sv), struct u8view: u8norm_nfd)((dstn), (sv), (alloc), (ctx)) + constexpr double U8CASEFOLD_SCALE = 3; constexpr double U8LOWER_SCALE = 1.5; constexpr double U8LOWER_SCALE_LT = 3; |