--- a/libpurple/purpletags.c Sat Nov 26 04:13:38 2022 -0600
+++ b/libpurple/purpletags.c Mon Nov 28 20:37:34 2022 -0600
@@ -126,6 +126,26 @@
tags->tags = g_list_append(tags->tags, g_strdup(tag));
+purple_tags_add_with_value(PurpleTags *tags, const char *name, + g_return_if_fail(PURPLE_IS_TAGS(tags)); + g_return_if_fail(name != NULL); + tag = g_strdup_printf("%s:%s", name, value); + purple_tags_add(tags, tag); purple_tags_remove(PurpleTags *tags, const gchar *tag) {
g_return_val_if_fail(PURPLE_IS_TAGS(tags), FALSE);
--- a/libpurple/purpletags.h Sat Nov 26 04:13:38 2022 -0600
+++ b/libpurple/purpletags.h Mon Nov 28 20:37:34 2022 -0600
@@ -103,6 +103,19 @@
void purple_tags_add(PurpleTags *tags, const gchar *tag);
+ * purple_tags_add_with_value: + * @name: The name of the tag. + * @value: (nullable): The value of the tag. + * Formats @name and @value into a tag and adds it to @tags. If the tag already + * exists, the existing tag will be replaced. +void purple_tags_add_with_value(PurpleTags *tags, const char *name, const char *value); --- a/libpurple/tests/test_tags.c Sat Nov 26 04:13:38 2022 -0600
+++ b/libpurple/tests/test_tags.c Mon Nov 28 20:37:34 2022 -0600
@@ -128,6 +128,38 @@
+test_purple_tags_add_with_value(void) { + PurpleTags *tags = purple_tags_new(); + const char *value = NULL; + gboolean found = FALSE; + purple_tags_add_with_value(tags, "tag1", "purple"); + g_assert_cmpuint(purple_tags_get_count(tags), ==, 1); + value = purple_tags_lookup(tags, "tag1", &found); + g_assert_cmpstr(value, ==, "purple"); +test_purple_tags_add_with_value_null(void) { + PurpleTags *tags = purple_tags_new(); + const char *value = NULL; + gboolean found = FALSE; + purple_tags_add_with_value(tags, "tag1", NULL); + g_assert_cmpuint(purple_tags_get_count(tags), ==, 1); + value = purple_tags_lookup(tags, "tag1", &found); test_purple_tags_remove_non_existent_with_value(void) {
PurpleTags *tags = purple_tags_new();
@@ -303,6 +335,11 @@
g_test_add_func("/tags/remove-non-existent-bare",
test_purple_tags_remove_non_existent_bare);
+ g_test_add_func("/tags/add-with-value", + test_purple_tags_add_with_value); + g_test_add_func("/tags/add-with-value-null", + test_purple_tags_add_with_value_null); g_test_add_func("/tags/add-remove-with-value",
test_purple_tags_add_remove_with_value);
g_test_add_func("/tags/add-duplicate-with-value",