aboutsummaryrefslogtreecommitdiff
path: root/lib/optparse
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-04 04:01:45 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-04 04:01:45 +0200
commitac1b4bcbaeaee7d2ef9132dcdc254f2d08691650 (patch)
tree90250966629653f0462cf17bc0b6f2476fb6d1fc /lib/optparse
parent8b923ba5e5bb37ea26350b4c1c688b8697706609 (diff)
Go all in on string views, and fix manuals
Diffstat (limited to 'lib/optparse')
-rw-r--r--lib/optparse/optparse.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/optparse/optparse.c b/lib/optparse/optparse.c
index 407fa62..757dd47 100644
--- a/lib/optparse/optparse.c
+++ b/lib/optparse/optparse.c
@@ -44,11 +44,10 @@ optparse(struct optparse *st, const struct op_option *opts, size_t nopts)
st->optind++;
/* Skip ‘--’ */
- opt.p += 2;
- opt.len -= 2;
+ VSHFT(&opt, 2);
const struct op_option *o = nullptr;
- const char8_t *eq_p = u8chr(opt.p, '=', opt.len);
+ const char8_t *eq_p = u8chr(opt, '=');
struct u8view opt_no_eq = {
.p = opt.p,
.len = eq_p == nullptr ? opt.len : (size_t)(eq_p - opt.p),
@@ -56,7 +55,7 @@ optparse(struct optparse *st, const struct op_option *opts, size_t nopts)
for (size_t i = 0; i < nopts; i++) {
struct u8view lo = opts[i].longopt;
- if (lo.p == nullptr || !u8haspfx(U8_ARGS(lo), U8_ARGS(opt_no_eq)))
+ if (lo.p == nullptr || !u8haspfx(lo, opt_no_eq))
continue;
if (o != nullptr)
return error(st, OPT_MSG_INVALID, opt_no_eq);
@@ -146,7 +145,7 @@ rune
error_s(struct optparse *st, const char *msg, struct u8view s)
{
snprintf(st->errmsg, sizeof(st->errmsg), u8"%s — ‘%.*s’", msg,
- U8_PRI_ARGS(s));
+ SV_PRI_ARGS(s));
return -1;
}