libpurple/purpletags.c

Sat, 05 Nov 2022 00:15:03 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Sat, 05 Nov 2022 00:15:03 -0500
changeset 41892
39e595f7d056
parent 41736
d78c0951ea2c
child 41908
9d2735c0e848
permissions
-rw-r--r--

Add purple_tag_parse for parsing tags

Testing Done:
Ran the unit tests. Output everything via printf to verify unicode characters were fine with a forced failure, and learned that `g_message` won't output emoji I guess..

Reviewed at https://reviews.imfreedom.org/r/2027/

41736
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpletags.h"
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include "util.h"
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 struct _PurpleTags {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 GObject parent;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 GList *tags;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 };
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 G_DEFINE_TYPE(PurpleTags, purple_tags, G_TYPE_OBJECT)
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 /******************************************************************************
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 * GObject Implementation
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 *****************************************************************************/
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 static void
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 purple_tags_dispose(GObject *obj) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 PurpleTags *tags = PURPLE_TAGS(obj);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 if(tags->tags != NULL) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 g_list_free_full(tags->tags, g_free);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 tags->tags = NULL;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 G_OBJECT_CLASS(purple_tags_parent_class)->dispose(obj);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 static void
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 purple_tags_init(PurpleTags *tags) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 static void
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 purple_tags_class_init(PurpleTagsClass *klass) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 obj_class->dispose = purple_tags_dispose;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 /******************************************************************************
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 * Public API
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 *****************************************************************************/
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 PurpleTags *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 purple_tags_new(void) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 return g_object_new(PURPLE_TYPE_TAGS, NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 const gchar *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 purple_tags_lookup(PurpleTags *tags, const gchar *name, gboolean *found) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 size_t name_len = 0;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 g_return_val_if_fail(PURPLE_IS_TAGS(tags), FALSE);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 g_return_val_if_fail(name != NULL, FALSE);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 /* Assume we're going to find the tag, if we don't we set found to false
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 * before we return. This sounds silly, but it saves some additional logic
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 * below.
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 */
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 if(found) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 *found = TRUE;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 name_len = strlen(name);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 for(GList *l = tags->tags; l != NULL; l = l->next) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 const gchar *tag = l->data;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 if(g_str_has_prefix(tag, name)) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 const gchar *value = tag + name_len;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 if(*value == '\0') {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 return NULL;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 } else if(*value == ':') {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 return value+1;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 /* We didn't find the tag, so set found to false if necessary. */
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 if(found) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 *found = FALSE;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 return NULL;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 const gchar *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 purple_tags_get(PurpleTags *tags, const gchar *name) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 g_return_val_if_fail(name != NULL, NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 return purple_tags_lookup(tags, name, NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 void
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 purple_tags_add(PurpleTags *tags, const gchar *tag) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 g_return_if_fail(PURPLE_IS_TAGS(tags));
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 g_return_if_fail(tag != NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 tags->tags = g_list_append(tags->tags, g_strdup(tag));
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 gboolean
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 purple_tags_remove(PurpleTags *tags, const gchar *tag) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 g_return_val_if_fail(PURPLE_IS_TAGS(tags), FALSE);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 g_return_val_if_fail(tag != NULL, FALSE);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 for(GList *l = tags->tags; l != NULL; l = l->next) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 gchar *etag = l->data;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 if(purple_strequal(etag, tag)) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 g_free(etag);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 tags->tags = g_list_delete_link(tags->tags, l);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 return TRUE;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 return FALSE;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 guint
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 purple_tags_get_count(PurpleTags *tags) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 g_return_val_if_fail(PURPLE_IS_TAGS(tags), 0);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 return g_list_length(tags->tags);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 GList *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 purple_tags_get_all(PurpleTags *tags) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 return tags->tags;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 gchar *
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 purple_tags_to_string(PurpleTags *tags, const gchar *separator) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 GString *value = NULL;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 value = g_string_new("");
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 for(GList *l = tags->tags; l != NULL; l = l->next) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 const gchar *tag = l->data;
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 g_string_append(value, tag);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 if(separator != NULL && l->next != NULL) {
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 g_string_append(value, separator);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 }
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 return g_string_free(value, FALSE);
d78c0951ea2c Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 }
41892
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
178
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
179 void
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
180 purple_tag_parse(const char *tag, char **name, char **value) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
181 const char *colon = NULL;
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
182
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
183 g_return_if_fail(tag != NULL);
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
184
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
185 colon = g_strstr_len(tag, -1, ":");
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
186 if(colon == NULL) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
187 if(name != NULL) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
188 *name = g_strdup(tag);
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
189 }
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
190 if(value != NULL) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
191 *value = NULL;
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
192 }
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
193 } else {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
194 if(name != NULL) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
195 *name = g_strndup(tag, colon - tag);
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
196 }
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
197 if(value != NULL) {
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
198 *value = g_strdup(colon + 1);
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
199 }
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
200 }
39e595f7d056 Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents: 41736
diff changeset
201 }

mercurial