[gedit/wip/use-gsv-search: 4/9] utils: use gsv utils functions



commit 13005638c69b430e0f8740b942fcd028f2a9ceab
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 1 11:37:25 2013 +0200

    utils: use gsv utils functions

 gedit/gedit-utils.c |  122 +--------------------------------------------------
 1 files changed, 2 insertions(+), 120 deletions(-)
---
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 135878f..7a0692a 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -280,131 +280,13 @@ gedit_utils_set_atk_relation (GtkWidget       *obj1,
 gchar *
 gedit_utils_escape_search_text (const gchar* text)
 {
-       GString *str;
-       gint length;
-       const gchar *p;
-       const gchar *end;
-
-       if (text == NULL)
-               return NULL;
-
-       gedit_debug_message (DEBUG_SEARCH, "Text: %s", text);
-
-       length = strlen (text);
-
-       /* no escape when typing.
-        * The short circuit works only for ascii, but we only
-        * care about not escaping a single '\' */
-       if (length == 1)
-               return g_strdup (text);
-
-       str = g_string_new ("");
-
-       p = text;
-       end = text + length;
-
-       while (p != end)
-       {
-               const gchar *next;
-               next = g_utf8_next_char (p);
-
-               switch (*p)
-               {
-                               case '\n':
-                               g_string_append (str, "\\n");
-                               break;
-                       case '\r':
-                               g_string_append (str, "\\r");
-                               break;
-                       case '\t':
-                               g_string_append (str, "\\t");
-                               break;
-                       case '\\':
-                               g_string_append (str, "\\\\");
-                               break;
-                       default:
-                               g_string_append_len (str, p, next - p);
-                               break;
-               }
-
-               p = next;
-       }
-
-       return g_string_free (str, FALSE);
+       return gtk_source_utils_escape_search_text (text);
 }
 
 gchar *
 gedit_utils_unescape_search_text (const gchar *text)
 {
-       GString *str;
-       gint length;
-       gboolean drop_prev = FALSE;
-       const gchar *cur;
-       const gchar *end;
-       const gchar *prev;
-
-       if (text == NULL)
-               return NULL;
-
-       length = strlen (text);
-
-       str = g_string_new ("");
-
-       cur = text;
-       end = text + length;
-       prev = NULL;
-
-       while (cur != end)
-       {
-               const gchar *next;
-               next = g_utf8_next_char (cur);
-
-               if (prev && (*prev == '\\'))
-               {
-                       switch (*cur)
-                       {
-                               case 'n':
-                                       str = g_string_append (str, "\n");
-                                       break;
-                               case 'r':
-                                       str = g_string_append (str, "\r");
-                                       break;
-                               case 't':
-                                       str = g_string_append (str, "\t");
-                                       break;
-                               case '\\':
-                                       str = g_string_append (str, "\\");
-                                       drop_prev = TRUE;
-                                       break;
-                               default:
-                                       str = g_string_append (str, "\\");
-                                       str = g_string_append_len (str, cur, next - cur);
-                                       break;
-                       }
-               }
-               else if (*cur != '\\')
-               {
-                       str = g_string_append_len (str, cur, next - cur);
-               }
-               else if ((next == end) && (*cur == '\\'))
-               {
-                       str = g_string_append (str, "\\");
-               }
-
-               if (!drop_prev)
-               {
-                       prev = cur;
-               }
-               else
-               {
-                       prev = NULL;
-                       drop_prev = FALSE;
-               }
-
-               cur = next;
-       }
-
-       return g_string_free (str, FALSE);
+       return gtk_source_utils_unescape_search_text (text);
 }
 
 void


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