From 88fc843d3e9c31d50afbf1554344df05314931d3 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 5 Aug 2024 18:39:15 +0200 Subject: [PATCH] Use xs_between() where applicable. --- mastoapi.c | 4 ++-- xs.h | 8 ++++---- xs_url.h | 2 +- xs_version.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mastoapi.c b/mastoapi.c index 7bd68a6..0c3b07e 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -3324,11 +3324,11 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path, persist_image("avatar", v, payload, &snac); } else - if (xs_starts_and_ends("fields_attributes", k, "[name]")) { + if (xs_between("fields_attributes", k, "[name]")) { field_name = strcmp(v, "") != 0 ? v : NULL; } else - if (xs_starts_and_ends("fields_attributes", k, "[value]")) { + if (xs_between("fields_attributes", k, "[value]")) { if (field_name != NULL) { new_fields = xs_dict_set(new_fields, field_name, v); snac.config = xs_dict_set(snac.config, "metadata", new_fields); diff --git a/xs.h b/xs.h index d1a874c..608dc3a 100644 --- a/xs.h +++ b/xs.h @@ -80,9 +80,9 @@ xs_str *xs_replace_in(xs_str *str, const char *sfrom, const char *sto, int times #define xs_replace_n(str, sfrom, sto, times) xs_replace_in(xs_dup(str), sfrom, sto, times) xs_str *xs_fmt(const char *fmt, ...); int xs_str_in(const char *haystack, const char *needle); -int xs_starts_and_ends(const char *prefix, const char *str, const char *suffix); -#define xs_startswith(str, prefix) xs_starts_and_ends(prefix, str, NULL) -#define xs_endswith(str, suffix) xs_starts_and_ends(NULL, str, suffix) +int xs_between(const char *prefix, const char *str, const char *suffix); +#define xs_startswith(str, prefix) xs_between(prefix, str, NULL) +#define xs_endswith(str, suffix) xs_between(NULL, str, suffix) xs_str *xs_crop_i(xs_str *str, int start, int end); xs_str *xs_lstrip_chars_i(xs_str *str, const char *chars); xs_str *xs_rstrip_chars_i(xs_str *str, const char *chars); @@ -586,7 +586,7 @@ int xs_str_in(const char *haystack, const char *needle) } -int xs_starts_and_ends(const char *prefix, const char *str, const char *suffix) +int xs_between(const char *prefix, const char *str, const char *suffix) /* returns true if str starts with prefix and ends with suffix */ { int sz = strlen(str); diff --git a/xs_url.h b/xs_url.h index 9deda38..56e0f53 100644 --- a/xs_url.h +++ b/xs_url.h @@ -109,7 +109,7 @@ xs_dict *xs_multipart_form_data(const char *payload, int p_size, const char *hea boundary = xs_dup(xs_list_get(l1, 1)); /* Tokodon sends the boundary header with double quotes surrounded */ - if (xs_starts_and_ends("\"", boundary, "\"") != 0) + if (xs_between("\"", boundary, "\"") != 0) boundary = xs_strip_chars_i(boundary, "\""); boundary = xs_fmt("--%s", boundary); diff --git a/xs_version.h b/xs_version.h index 98a46d0..0f81d28 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* fb6646ef1b1d5f24768bc829680eb70272755584 2024-08-05T05:32:08+02:00 */ +/* 3536c4e2ab0849eccf81c50741028453e9ad7f3a 2024-08-05T18:37:46+02:00 */