/pidgin/main: a304796f1c09: Smiley parser: upgrade purple_smiley...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Apr 7 17:11:40 EDT 2014


Changeset: a304796f1c09308927228c91821bba072f0f61ae
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-07 23:11 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/a304796f1c09

Description:

Smiley parser: upgrade purple_smiley_find for html sentry

diffstat:

 libpurple/smiley-parser.c |  38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diffs (75 lines):

diff --git a/libpurple/smiley-parser.c b/libpurple/smiley-parser.c
--- a/libpurple/smiley-parser.c
+++ b/libpurple/smiley-parser.c
@@ -189,12 +189,21 @@ purple_smiley_parse_custom(const gchar *
 }
 
 static gboolean
-smiley_find_cb(const gchar *word, gpointer _smiley, gpointer _found_smileys)
+smiley_find_cb(const gchar *word, gpointer _smiley, gpointer _parse_data)
 {
 	PurpleSmiley *smiley = _smiley;
-	GHashTable *found_smileys = _found_smileys;
+	PurpleSmileyParseData *parse_data = _parse_data;
 
-	g_hash_table_insert(found_smileys, smiley, smiley);
+	/* a special-case for html_sentry */
+	if (smiley == NULL) {
+		purple_smiley_parse_check_html(word, parse_data);
+		return FALSE;
+	}
+
+	if (parse_data->in_html_tag)
+		return FALSE;
+
+	g_hash_table_insert(parse_data->job.find.found_smileys, smiley, smiley);
 
 	return TRUE;
 }
@@ -203,10 +212,11 @@ GList *
 purple_smiley_find(PurpleSmileyList *smileys, const gchar *message,
 	gboolean is_html)
 {
-	PurpleTrie *trie;
-	GHashTable *found_smileys;
+	PurpleTrie *smileys_trie;
 	GList *found_list;
 	gchar *escaped_message = NULL;
+	PurpleSmileyParseData parse_data;
+	GSList trie_1, trie_2;
 
 	if (message == NULL || message[0] == '\0')
 		return NULL;
@@ -214,21 +224,25 @@ purple_smiley_find(PurpleSmileyList *smi
 	if (smileys == NULL || purple_smiley_list_is_empty(smileys))
 		return NULL;
 
-	trie = purple_smiley_list_get_trie(smileys);
-	g_return_val_if_fail(trie != NULL, NULL);
+	smileys_trie = purple_smiley_list_get_trie(smileys);
+	g_return_val_if_fail(smileys_trie != NULL, NULL);
 
 	if (!is_html)
 		message = escaped_message = g_markup_escape_text(message, -1);
 
-	found_smileys = g_hash_table_new(g_direct_hash, g_direct_equal);
-	purple_trie_find(trie, message, smiley_find_cb, found_smileys);
+	parse_data.job.find.found_smileys =
+		g_hash_table_new(g_direct_hash, g_direct_equal);
 
-	/* TODO: use html_sentry and purple_trie_multi_replace */
+	trie_1.data = html_sentry;
+	trie_2.data = smileys_trie;
+	trie_1.next = &trie_2;
+	trie_2.next = NULL;
+	purple_trie_multi_find(&trie_1, message, smiley_find_cb, &parse_data);
 
 	g_free(escaped_message);
 
-	found_list = g_hash_table_get_values(found_smileys);
-	g_hash_table_destroy(found_smileys);
+	found_list = g_hash_table_get_values(parse_data.job.find.found_smileys);
+	g_hash_table_destroy(parse_data.job.find.found_smileys);
 
 	return found_list;
 }



More information about the Commits mailing list