diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/_qmacros.h | 26 | ||||
-rw-r--r-- | include/macros.h | 6 | ||||
-rw-r--r-- | include/mbstring.h | 43 | ||||
-rw-r--r-- | include/unicode/string.h | 32 |
4 files changed, 34 insertions, 73 deletions
diff --git a/include/_qmacros.h b/include/_qmacros.h deleted file mode 100644 index d496581..0000000 --- a/include/_qmacros.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MLIB__QMACROS_H -#define MLIB__QMACROS_H - -/* Macros for qualifier-preserving functions. These are used to create wrappers - around some functions which will return a const-qualified pointer if the - input pointer is const-qualified, and a non-const-qualified pointer - otherwise. - - The macros are taken from the N3020 proposal for C23. */ - -/* clang-format off */ -#define _MLIB_PTR_IS_CONST(P) \ - _Generic(1 ? (P) : (void *)(P), \ - const void *: 1, \ - default: 0) -#define _MLIB_STATIC_IF(P, T, E) \ - _Generic(&(char[!!(P) + 1]){0}, \ - char(*)[2]: T, \ - char(*)[1]: E) -#define _MLIB_Q_PTR(T, F, S, ...) \ - _MLIB_STATIC_IF(_MLIB_PTR_IS_CONST((S)), \ - (const T *)(F)(__VA_ARGS__), \ - (T *)(F)(__VA_ARGS__)) -/* clang-format on */ - -#endif /* !MLIB__QMACROS_H */ diff --git a/include/macros.h b/include/macros.h index d4b53b4..32e8b7c 100644 --- a/include/macros.h +++ b/include/macros.h @@ -7,9 +7,9 @@ #define lengthof(a) (sizeof(a) / sizeof(*(a))) -#define memeq(...) (!memcmp(__VA_ARGS__)) -#define streq(...) (!strcmp(__VA_ARGS__)) -#define u8eq(...) (!u8cmp(__VA_ARGS__)) +#define memeq(x, y, n) (!memcmp((x), (y), (n))) +#define streq(x, y) (!strcmp((x), (y))) +#define u8eq(x, y) (!u8cmp((x), (y))) #define _MLIB_STR(s) #s #define _MLIB_CONCAT(x, y) x##y diff --git a/include/mbstring.h b/include/mbstring.h index d908284..ba654bb 100644 --- a/include/mbstring.h +++ b/include/mbstring.h @@ -4,14 +4,13 @@ #include <stddef.h> #include "_charN_t.h" -#include "_qmacros.h" #include "_rune.h" #include "_u8view.h" #define U8(...) \ ((struct u8view){__VA_OPT__(u8##__VA_ARGS__, sizeof(u8##__VA_ARGS__) - 1)}) -#define U8_ARGS(s) ((s).p), ((s).len) -#define U8_ARGSP(s) (&(s).p), (&(s).len) + +#define VSHFT(sv, n) ((sv)->p += (n), (sv)->len -= (n)) /* clang-format off */ #define u8byte1(x) (((x) & 0x80) == 0x00) @@ -29,33 +28,21 @@ constexpr rune U8_4B_MAX = 0x10FFFF; constexpr int U8_LEN_MAX = 4; #define PRIsU8 ".*s" -#define U8_PRI_ARGS(sv) ((int)(sv).len), ((sv).p) - -[[nodiscard]] bool u8haspfx(const char8_t *, size_t, const char8_t *, size_t); -[[nodiscard]] bool u8hassfx(const char8_t *, size_t, const char8_t *, size_t); - -[[nodiscard]] char8_t *u8chk(const char8_t *, size_t); - -[[nodiscard]] char8_t *u8chr(const char8_t *, size_t, rune); -[[nodiscard]] char8_t *u8rchr(const char8_t *, size_t, rune); +#define SV_PRI_ARGS(sv) ((int)(sv).len), ((sv).p) int rtou8(char8_t *, size_t, rune); -int u8tor(rune *, const char8_t *); - -[[nodiscard]] int u8cmp(const char8_t *, size_t, const char8_t *, size_t); - -int u8next(rune *, const char8_t **, size_t *); +int u8next(rune *, struct u8view *); int u8prev(rune *, const char8_t **, const char8_t *); - -[[nodiscard]] size_t u8spn(const char8_t *, size_t, const rune *, size_t); -[[nodiscard]] size_t u8cspn(const char8_t *, size_t, const rune *, size_t); - -[[nodiscard]] size_t u8len(const char8_t *, size_t); - -struct u8view u8split(const char8_t **, size_t *, rune); - -#define u8chk(s, n) _MLIB_Q_PTR(char8_t, u8chk, (s), (s), (n)) -#define u8chr(s, n, ch) _MLIB_Q_PTR(char8_t, u8chr, (s), (s), (n), (ch)) -#define u8rchr(s, n, ch) _MLIB_Q_PTR(char8_t, u8rchr, (s), (s), (n), (ch)) +int u8tor(rune *, const char8_t *); +[[nodiscard]] bool u8haspfx(struct u8view, struct u8view); +[[nodiscard]] bool u8hassfx(struct u8view, struct u8view); +[[nodiscard]] const char8_t *u8chk(struct u8view); +[[nodiscard]] const char8_t *u8chr(struct u8view, rune); +[[nodiscard]] const char8_t *u8rchr(struct u8view, rune); +[[nodiscard]] int u8cmp(struct u8view, struct u8view); +[[nodiscard]] size_t u8cspn(struct u8view, const rune *, size_t); +[[nodiscard]] size_t u8len(struct u8view); +[[nodiscard]] size_t u8spn(struct u8view, const rune *, size_t); +struct u8view u8split(struct u8view *, rune); #endif /* !MLIB_MBSTRING_H */ diff --git a/include/unicode/string.h b/include/unicode/string.h index 0ae49f0..bb8cafd 100644 --- a/include/unicode/string.h +++ b/include/unicode/string.h @@ -21,22 +21,22 @@ enum [[clang::flag_enum]] caseflags { /* clang-format on */ -[[nodiscard]] size_t u8gcnt(const char8_t *, size_t); -[[nodiscard]] size_t u8wcnt(const char8_t *, size_t); -[[nodiscard]] size_t u8wcnt_human(const char8_t *, size_t); - -size_t u8gnext(struct u8view *, const char8_t **, size_t *); -size_t u8wnext(struct u8view *, const char8_t **, size_t *); -size_t u8wnext_human(struct u8view *, const char8_t **, size_t *); - -[[mlib_warn_trunc]] size_t u8lower(char8_t *restrict, size_t, const char8_t *, - size_t, enum caseflags); -[[mlib_warn_trunc]] size_t u8title(char8_t *restrict, size_t, const char8_t *, - size_t, enum caseflags); -[[mlib_warn_trunc]] size_t u8upper(char8_t *restrict, size_t, const char8_t *, - size_t, enum caseflags); -[[mlib_warn_trunc]] size_t u8casefold(char8_t *restrict, size_t, - const char8_t *, size_t, 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 *); + +[[mlib_warn_trunc]] size_t u8lower(char8_t *restrict, size_t, struct u8view, + enum caseflags); +[[mlib_warn_trunc]] size_t u8title(char8_t *restrict, size_t, struct u8view, + enum caseflags); +[[mlib_warn_trunc]] size_t u8upper(char8_t *restrict, size_t, struct u8view, + enum caseflags); +[[mlib_warn_trunc]] size_t u8casefold(char8_t *restrict, size_t, struct u8view, + enum caseflags); constexpr double U8LOWER_SCALE = 1.5; constexpr double U8LOWER_SCALE_LT = 3; |