[Pidgin] #17232: improve smiley matching for unicode
Pidgin
trac at pidgin.im
Thu Jul 27 16:53:46 EDT 2017
#17232: improve smiley matching for unicode
--------------------+--------------------------
Reporter: gnubfx | Owner:
Type: patch | Status: new
Milestone: 2.12.1 | Component: pidgin (gtk)
Version: 2.12.0 | Keywords: smiley tree
--------------------+--------------------------
Hi,
smileys are matched by traversing a tree and trying to find the longest
match. Comparison is bytewise. This works well for ASCII smiley-shortcuts,
not as much for unicode because unicode characters tend to start with the
same bytes. Example:
{{{
abc -> smiley1
abcdef -> smiley2
dxy -> smiley3
}}}
Now the expected behaviour for abcdxy would be to evaluate to
(smiley1)(smiley3) but it only evaluates to (smiley3).
I propose the matching routine to fall back to the last complete match,
once a string stops matching:
See pidgin/gtkimhtml.c from line 2056
{{{
--- old.c 2016-06-02 19:44:51.000000000 +0200
+++ gtkimhtml.c 2017-07-24 20:23:56.619917000 +0200
@@ -2056,7 +2056,8 @@
const gchar *x = text;
gint len = 0;
const gchar *amp;
- gint alen;
+ gint alen,
+ lastlen = 0;
while (*x) {
gchar *pos;
@@ -2091,9 +2092,12 @@
pos = strchr (t->values->str, *x);
}
- if (pos)
+ if (pos) {
t = t->children [GPOINTER_TO_INT(pos) -
GPOINTER_TO_INT(t->values->str)];
- else
+
+ if (t->image)
+ lastlen = len + alen;
+ } else
break;
x += alen;
@@ -2103,7 +2107,7 @@
if (t->image)
return len;
- return 0;
+ return lastlen;
}
}}}
--
Ticket URL: <https://developer.pidgin.im/ticket/17232>
Pidgin <https://pidgin.im>
Pidgin
More information about the Tracker
mailing list