mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()
This avoids the need for an unused third argument for most xstrjoin() calls and replaces the cases where it's needed with a more flexible function. Code generation is the same in both cases, when there are 2 string params and a compile-time known delimiter. This commit also converts 4 uses of xasprintf() to use xstrjoin*(). See also: https://godbolt.org/z/xsjrhv9b6
This commit is contained in:
parent
62b0b65d47
commit
f87c9bb9f7
7 changed files with 44 additions and 31 deletions
18
main.c
18
main.c
|
|
@ -258,7 +258,7 @@ main(int argc, char *const *argv)
|
|||
break;
|
||||
|
||||
case 't':
|
||||
tll_push_back(overrides, xstrjoin("term=", optarg, 0));
|
||||
tll_push_back(overrides, xstrjoin("term=", optarg));
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
|
|
@ -266,11 +266,11 @@ main(int argc, char *const *argv)
|
|||
break;
|
||||
|
||||
case 'T':
|
||||
tll_push_back(overrides, xstrjoin("title=", optarg, 0));
|
||||
tll_push_back(overrides, xstrjoin("title=", optarg));
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
tll_push_back(overrides, xstrjoin("app-id=", optarg, 0));
|
||||
tll_push_back(overrides, xstrjoin("app-id=", optarg));
|
||||
break;
|
||||
|
||||
case 'D': {
|
||||
|
|
@ -284,7 +284,7 @@ main(int argc, char *const *argv)
|
|||
}
|
||||
|
||||
case 'f': {
|
||||
char *font_override = xstrjoin("font=", optarg, 0);
|
||||
char *font_override = xstrjoin("font=", optarg);
|
||||
tll_push_back(overrides, font_override);
|
||||
break;
|
||||
}
|
||||
|
|
@ -658,15 +658,19 @@ out:
|
|||
|
||||
UNITTEST
|
||||
{
|
||||
char *s = xstrjoin("foo", "bar", 0);
|
||||
char *s = xstrjoin("foo", "bar");
|
||||
xassert(streq(s, "foobar"));
|
||||
free(s);
|
||||
|
||||
s = xstrjoin("foo", "bar", ' ');
|
||||
s = xstrjoin3("foo", " ", "bar");
|
||||
xassert(streq(s, "foo bar"));
|
||||
free(s);
|
||||
|
||||
s = xstrjoin("foo", "bar", ',');
|
||||
s = xstrjoin3("foo", ",", "bar");
|
||||
xassert(streq(s, "foo,bar"));
|
||||
free(s);
|
||||
|
||||
s = xstrjoin3("foo", "bar", "baz");
|
||||
xassert(streq(s, "foobarbaz"));
|
||||
free(s);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue