[polari] room: Use case-insensitive matching for nick highlights



commit 7ba3a926057b910d8e531da93ec4d0072aff2bed
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Feb 8 18:50:37 2016 +0100

    room: Use case-insensitive matching for nick highlights
    
    For nicks that aren't all lowercase(*), it is easy enough to get the
    case wrong when not using tab completion, so use case-insensitive
    matching for nick highlights.
    
    (*) or shouty all uppercase of course
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761723

 configure.ac          |    3 +++
 src/lib/polari-room.c |   19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0893f54..c99d2e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,6 +18,7 @@ IT_PROG_INTLTOOL([0.50.0])
 GOBJECT_INTROSPECTION_REQUIRE([0.9.6])
 
 AX_CHECK_ENABLE_DEBUG([yes])
+AC_USE_SYSTEM_EXTENSIONS
 AX_COMPILER_FLAGS()
 
 AC_PROG_CC
@@ -35,6 +36,8 @@ PKG_CHECK_MODULES(POLARI,
                   gtk+-3.0 >= 3.15.6
                   telepathy-glib);
 
+AC_CHECK_FUNCS([strcasestr])
+
 AC_PATH_PROG([GJS_CONSOLE],[gjs-console],[no])
 
 if test "$GJS_CONSOLE" = "no"; then
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 2777205..ea4450f 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -118,6 +118,19 @@ polari_create_room_id (TpAccount    *account,
   return id;
 }
 
+#ifdef HAVE_STRCASESTR
+#  define MATCHFUNC(haystick,needle) strcasestr (haystick, needle)
+#  define MESSAGE_TO_TEXT(message) tp_message_to_text (message, NULL)
+#else
+   static inline char *
+   message_to_casefolded_text (TpMessage *message) {
+     g_autofree char *tmp = tp_message_to_text (message, NULL);
+     return g_utf8_casefold (tmp, -1);
+   }
+#  define MATCHFUNC(haystick,needle) strstr (haystick, needle)
+#  define MESSAGE_TO_TEXT(message) message_to_casefolded_text (message)
+#endif
+
 gboolean
 polari_room_should_highlight_message (PolariRoom *room,
                                       TpMessage *message)
@@ -144,9 +157,9 @@ polari_room_should_highlight_message (PolariRoom *room,
   if (tp_signalled_message_get_sender (message) == self)
     return FALSE;
 
-  text = tp_message_to_text (message, NULL);
+  text = MESSAGE_TO_TEXT (message);
   len = strlen (priv->self_nick);
-  match = strstr (text, priv->self_nick);
+  match = MATCHFUNC (text, priv->self_nick);
 
   while (match != NULL)
     {
@@ -159,7 +172,7 @@ polari_room_should_highlight_message (PolariRoom *room,
       result = starts_word && ends_word;
       if (result)
         break;
-      match = strstr (match + len, priv->self_nick);
+      match = MATCHFUNC (match + len, priv->self_nick);
     }
 
   g_free (text);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]