[polari] room: Split out nick matching from should_highlight
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] room: Split out nick matching from should_highlight
- Date: Sun, 10 Jul 2016 17:15:03 +0000 (UTC)
commit 931b2d92eaaaf59aea1d34263ee083db879e7f01
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Jul 9 02:10:43 2016 +0200
room: Split out nick matching from should_highlight
We'll soon reuse the nick matching part of the should_highlight()
method, so split it out into a separate helper function.
https://bugzilla.gnome.org/show_bug.cgi?id=768613
src/lib/polari-room.c | 50 ++++++++++++++++++++++++++++++------------------
1 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 2782cb2..15883a7 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -131,6 +131,35 @@ polari_create_room_id (TpAccount *account,
# define MESSAGE_TO_TEXT(message) message_to_casefolded_text (message)
#endif
+static gboolean
+match_self_nick (PolariRoom *room,
+ const char *text)
+{
+ PolariRoomPrivate *priv = room->priv;
+ char *match;
+ gboolean result = FALSE;
+ int len;
+
+ len = strlen (priv->self_nick);
+ match = MATCHFUNC (text, priv->self_nick);
+
+ while (match != NULL)
+ {
+ gboolean starts_word, ends_word;
+
+ /* assume ASCII nicknames, so no complex pango-style breaks */
+ starts_word = (match == text || !g_ascii_isalnum (*(match - 1)));
+ ends_word = !g_ascii_isalnum (*(match + len));
+
+ result = starts_word && ends_word;
+ if (result)
+ break;
+ match = MATCHFUNC (match + len, priv->self_nick);
+ }
+
+ return result;
+}
+
gboolean
polari_room_should_highlight_message (PolariRoom *room,
TpMessage *message)
@@ -138,9 +167,8 @@ polari_room_should_highlight_message (PolariRoom *room,
PolariRoomPrivate *priv;
TpConnection *conn;
TpContact *self;
- char *text, *match;
+ char *text;
gboolean result = FALSE;
- int len;
g_return_val_if_fail (POLARI_IS_ROOM (room), FALSE);
@@ -158,23 +186,7 @@ polari_room_should_highlight_message (PolariRoom *room,
return FALSE;
text = MESSAGE_TO_TEXT (message);
- len = strlen (priv->self_nick);
- match = MATCHFUNC (text, priv->self_nick);
-
- while (match != NULL)
- {
- gboolean starts_word, ends_word;
-
- /* assume ASCII nicknames, so no complex pango-style breaks */
- starts_word = (match == text || !g_ascii_isalnum (*(match - 1)));
- ends_word = !g_ascii_isalnum (*(match + len));
-
- result = starts_word && ends_word;
- if (result)
- break;
- match = MATCHFUNC (match + len, priv->self_nick);
- }
-
+ result = match_self_nick (room, text);
g_free (text);
return result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]