aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-15 19:20:44 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-15 19:20:44 +0200
commitd8760ab5cf8378fa50e48453149e96a1392253e2 (patch)
tree3ee857325aefe46070d21c0339feee068987222a /include
parentb6792f703c715ccfc0854c4e8ee3ca703565f4eb (diff)
Shorten the string view type names
Diffstat (limited to 'include')
-rw-r--r--include/_uNview.h18
-rw-r--r--include/cli.h4
-rw-r--r--include/macros.h2
-rw-r--r--include/mbstring.h59
-rw-r--r--include/unicode/prop.h6
-rw-r--r--include/unicode/string.h48
6 files changed, 68 insertions, 69 deletions
diff --git a/include/_uNview.h b/include/_uNview.h
index 9d0d5e2..1001807 100644
--- a/include/_uNview.h
+++ b/include/_uNview.h
@@ -1,23 +1,23 @@
-#ifndef MLIB__U8VIEW_H
-#define MLIB__U8VIEW_H
+#ifndef MLIB__UNVIEW_H
+#define MLIB__UNVIEW_H
#include <stddef.h>
#include "_charN_t.h"
-struct u8view {
+typedef struct {
const char8_t *p;
size_t len;
-};
+} u8view_t;
-struct u16view {
+typedef struct {
const char16_t *p;
size_t len;
-};
+} u16view_t;
-struct u32view {
+typedef struct {
const char32_t *p;
size_t len;
-};
+} u32view_t;
-#endif /* !MLIB__U8VIEW_H */
+#endif /* !MLIB__UNVIEW_H */
diff --git a/include/cli.h b/include/cli.h
index b2545ae..970b228 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -14,7 +14,7 @@ struct optparser {
int optind;
char errmsg[128];
- struct u8view optarg;
+ u8view_t optarg;
};
enum cliarg {
@@ -25,7 +25,7 @@ enum cliarg {
struct cli_option {
rune shortopt;
- struct u8view longopt;
+ u8view_t longopt;
enum cliarg argtype;
};
diff --git a/include/macros.h b/include/macros.h
index 74dd5e5..8f08364 100644
--- a/include/macros.h
+++ b/include/macros.h
@@ -11,7 +11,7 @@
#define streq(x, y) (!strcmp((x), (y)))
#define u8eq(x, y) (!u8cmp((x), (y)))
-#define ucseq(lhs, rhs) (!_Generic((lhs), struct u8view: u8cmp)((lhs), (rhs)))
+#define ucseq(lhs, rhs) (!_Generic((lhs), u8view_t: u8cmp)((lhs), (rhs)))
#define _MLIB_STR(s) #s
#define _MLIB_CONCAT(x, y) x##y
diff --git a/include/mbstring.h b/include/mbstring.h
index 309069b..e28c479 100644
--- a/include/mbstring.h
+++ b/include/mbstring.h
@@ -7,17 +7,16 @@
#include "_rune.h"
#include "_uNview.h"
-#define U8(...) \
- ((struct u8view){__VA_OPT__(u8##__VA_ARGS__, sizeof(u8##__VA_ARGS__) - 1)})
-#define U16(...) \
- ((struct u16view){__VA_OPT__(u##__VA_ARGS__, sizeof(u##__VA_ARGS__) - 1)})
-#define U32(...) \
- ((struct u32view){__VA_OPT__(U##__VA_ARGS__, sizeof(U##__VA_ARGS__) - 1)})
-/* clang-format off */
+#define U8(...) \
+ ((u8view_t){__VA_OPT__(u8##__VA_ARGS__, sizeof(u8##__VA_ARGS__) - 1)})
+#define U16(...) \
+ ((u16view_t){__VA_OPT__(u##__VA_ARGS__, sizeof(u##__VA_ARGS__) - 1)})
+#define U32(...) \
+ ((u32view_t){__VA_OPT__(U##__VA_ARGS__, sizeof(U##__VA_ARGS__) - 1)})
+
#define U8C(s) {u8##s, sizeof(u8##s) - 1}
#define U16C(s) { u##s, sizeof (u##s) - 1}
#define U32C(s) { U##s, sizeof (U##s) - 1}
-/* clang-format on */
#define VSHFT(sv, n) ((sv)->p += (n), (sv)->len -= (n))
@@ -41,41 +40,41 @@ constexpr rune MBEND = 0x110000;
#define SV_PRI_ARGS(sv) ((int)(sv).len), ((sv).p)
int rtou8(char8_t *, size_t, rune);
-int u8next(rune *, struct u8view *);
+int u8next(rune *, u8view_t *);
int u8prev(rune *, const char8_t **, const char8_t *);
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);
-rune u8cut(struct u8view *restrict, struct u8view *restrict, const rune *,
+[[nodiscard]] bool u8haspfx(u8view_t, u8view_t);
+[[nodiscard]] bool u8hassfx(u8view_t, u8view_t);
+[[nodiscard]] const char8_t *u8chk(u8view_t);
+[[nodiscard]] const char8_t *u8chr(u8view_t, rune);
+[[nodiscard]] const char8_t *u8rchr(u8view_t, rune);
+[[nodiscard]] int u8cmp(u8view_t, u8view_t);
+[[nodiscard]] size_t u8cspn(u8view_t, const rune *, size_t);
+[[nodiscard]] size_t u8len(u8view_t);
+[[nodiscard]] size_t u8spn(u8view_t, const rune *, size_t);
+rune u8cut(u8view_t *restrict, u8view_t *restrict, const rune *,
size_t);
/* Encoding-generic macros */
#define rtoucs(buf, bufsz, ch) \
_Generic((buf), char8_t *: rtou8)((buf), (bufsz), (ch))
-#define ucsnext(ch, sv) _Generic((sv), struct u8view *: u8next)((ch), (sv))
+#define ucsnext(ch, sv) _Generic((sv), u8view_t *: u8next)((ch), (sv))
#define ucsprev(ch, p, start) \
_Generic((p), const char8_t **: u8prev)((ch), (p), (start))
#define ucstor(ch, p) \
_Generic((p), char8_t *: u8tor, const char8_t *: u8tor)((ch), (p))
-#define ucshaspfx(sv, pfx) _Generic((sv), struct u8view: u8haspfx)((sv), (pfx))
-#define ucshassfx(sv, sfx) _Generic((sv), struct u8view: u8hassfx)((sv), (sfx))
-#define ucschk(sv) _Generic((sv), struct u8view: u8chk)((sv))
-#define ucschr(sv, ch) _Generic((sv), struct u8view: u8chr)((sv), (ch))
-#define ucsrchr(sv, ch) _Generic((sv), struct u8view: u8rchr)((sv), (ch))
-#define ucscmp(lhs, rhs) _Generic((lhs), struct u8view: u8cmp)((lhs), (rhs))
+#define ucshaspfx(sv, pfx) _Generic((sv), u8view_t: u8haspfx)((sv), (pfx))
+#define ucshassfx(sv, sfx) _Generic((sv), u8view_t: u8hassfx)((sv), (sfx))
+#define ucschk(sv) _Generic((sv), u8view_t: u8chk)((sv))
+#define ucschr(sv, ch) _Generic((sv), u8view_t: u8chr)((sv), (ch))
+#define ucsrchr(sv, ch) _Generic((sv), u8view_t: u8rchr)((sv), (ch))
+#define ucscmp(lhs, rhs) _Generic((lhs), u8view_t: u8cmp)((lhs), (rhs))
#define ucscspn(sv, delims, ndelims) \
- _Generic((sv), struct u8view: u8cspn)((sv), (delims), (ndelims))
-#define ucslen(sv) _Generic((sv), struct u8view: u8len)((sv))
+ _Generic((sv), u8view_t: u8cspn)((sv), (delims), (ndelims))
+#define ucslen(sv) _Generic((sv), u8view_t: u8len)((sv))
#define ucsspn(sv, delims, ndelims) \
- _Generic((sv), struct u8view: u8spn)((sv), (delims), (ndelims))
+ _Generic((sv), u8view_t: u8spn)((sv), (delims), (ndelims))
#define ucscut(x, y, seps, nseps) \
- _Generic((y), struct u8view *: u8cut)(x, y, seps, nseps)
+ _Generic((y), u8view_t *: u8cut)(x, y, seps, nseps)
#endif /* !MLIB_MBSTRING_H */
diff --git a/include/unicode/prop.h b/include/unicode/prop.h
index e11aa21..a3498f0 100644
--- a/include/unicode/prop.h
+++ b/include/unicode/prop.h
@@ -1117,7 +1117,7 @@ enum uprop_wb : uint_least8_t {
};
/* Not a Unicode property; but a nice-to-have */
-[[_mlib_pure]] struct u8view uprop_blkname(enum uprop_blk);
+[[_mlib_pure]] u8view_t uprop_blkname(enum uprop_blk);
[[_mlib_pure]] double uprop_get_nv(rune);
[[_mlib_pure]] enum uprop_age uprop_get_age(rune);
@@ -1159,8 +1159,8 @@ enum uprop_wb : uint_least8_t {
[[_mlib_pure]] struct rview uprop_get_nfkc_scf(rune);
[[_mlib_pure]] struct rview uprop_get_tc(rune, struct tcctx);
[[_mlib_pure]] struct rview uprop_get_uc(rune, struct ucctx);
-[[_mlib_pure]] struct u8view uprop_get_na1(rune);
-[[_mlib_pure]] struct u8view uprop_get_na(rune);
+[[_mlib_pure]] u8view_t uprop_get_na1(rune);
+[[_mlib_pure]] u8view_t uprop_get_na(rune);
[[_mlib_pure]] struct uprop_sc_view uprop_get_scx(rune);
/* PROP PREDICATES START */
diff --git a/include/unicode/string.h b/include/unicode/string.h
index 6908fe7..7d62171 100644
--- a/include/unicode/string.h
+++ b/include/unicode/string.h
@@ -30,47 +30,47 @@ enum normform {
/* clang-format on */
-[[nodiscard]] size_t u8wdth(struct u8view, int);
-[[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,
+[[nodiscard]] size_t u8wdth(u8view_t, int);
+[[nodiscard]] size_t u8gcnt(u8view_t);
+[[nodiscard]] size_t u8wcnt(u8view_t);
+[[nodiscard]] size_t u8wcnt_human(u8view_t);
+size_t u8gnext(u8view_t *, u8view_t *);
+size_t u8wnext(u8view_t *, u8view_t *);
+size_t u8wnext_human(u8view_t *, u8view_t *);
+[[nodiscard]] char8_t *u8casefold(size_t *, u8view_t, enum caseflags,
alloc_fn, void *);
-[[nodiscard]] char8_t *u8lower(size_t *, struct u8view, enum caseflags,
+[[nodiscard]] char8_t *u8lower(size_t *, u8view_t, enum caseflags,
alloc_fn, void *);
-[[nodiscard]] char8_t *u8title(size_t *, struct u8view, enum caseflags,
+[[nodiscard]] char8_t *u8title(size_t *, u8view_t, enum caseflags,
alloc_fn, void *);
-[[nodiscard]] char8_t *u8upper(size_t *, struct u8view, enum caseflags,
+[[nodiscard]] char8_t *u8upper(size_t *, u8view_t, enum caseflags,
alloc_fn, void *);
-[[nodiscard]] char8_t *u8norm(size_t *, struct u8view, alloc_fn, void *,
+[[nodiscard]] char8_t *u8norm(size_t *, u8view_t, alloc_fn, void *,
enum normform);
/* Encoding-generic macros */
-#define ucswdth(sv, ts) _Generic((sv), struct u8view: u8wdth)((sv), (ts))
-#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 ucswdth(sv, ts) _Generic((sv), u8view_t: u8wdth)((sv), (ts))
+#define ucsgcnt(sv) _Generic((sv), u8view_t: u8gcnt)((sv))
+#define ucswcnt(sv) _Generic((sv), u8view_t: u8wcnt)((sv))
+#define ucswcnt_human(sv) _Generic((sv), u8view_t: u8wcnt_human)((sv))
+#define ucsgnext(g, sv) _Generic((sv), u8view_t *: u8gnext)((g), (sv))
+#define ucswnext(g, sv) _Generic((sv), u8view_t *: u8wnext)((g), (sv))
#define ucswnext_human(g, sv) \
- _Generic((sv), struct u8view *: u8wnext_human)((g), (sv))
+ _Generic((sv), u8view_t *: u8wnext_human)((g), (sv))
#define ucscasefold(dstn, sv, flags, alloc, ctx) \
- _Generic((sv), struct u8view: u8casefold)((dstn), (sv), (flags), (alloc), \
+ _Generic((sv), u8view_t: u8casefold)((dstn), (sv), (flags), (alloc), \
(ctx))
#define ucslower(dstn, sv, flags, alloc, ctx) \
- _Generic((sv), struct u8view: u8lower)((dstn), (sv), (flags), (alloc), \
+ _Generic((sv), u8view_t: u8lower)((dstn), (sv), (flags), (alloc), \
(ctx))
#define ucstitle(dstn, sv, flags, alloc, ctx) \
- _Generic((sv), struct u8view: u8title)((dstn), (sv), (flags), (alloc), \
+ _Generic((sv), u8view_t: u8title)((dstn), (sv), (flags), (alloc), \
(ctx))
#define ucsupper(dstn, sv, flags, alloc, ctx) \
- _Generic((sv), struct u8view: u8upper)((dstn), (sv), (flags), (alloc), \
+ _Generic((sv), u8view_t: u8upper)((dstn), (sv), (flags), (alloc), \
(ctx))
#define ucsnorm(dstn, sv, alloc, ctx, nf) \
- _Generic((sv), struct u8view: u8norm)((dstn), (sv), (alloc), (ctx), (nf))
+ _Generic((sv), u8view_t: u8norm)((dstn), (sv), (alloc), (ctx), (nf))
constexpr double U8CASEFOLD_SCALE = 3;
constexpr double U8LOWER_SCALE = 1.5;