annotate src/gtksourceiter.c @ 7504:97e385fe462d

[gaim-migrate @ 8117] swedish committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Thu, 13 Nov 2003 21:30:16 +0000
parents 78c1fc730dc4
children fa6395637e2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * gtksourceiter.h
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 * Copyright (C) 2000, 2002 Paolo Maggi
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2002, 2003 Jeroen Zwartepoorte
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * it under the terms of the GNU Library General Public License as published by
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * (at your option) any later version.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * GNU Library General Public License for more details.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Library General Public License
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 /*
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * Parts of this file are copied from the gedit and glimmer project.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include <config.h>
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #endif
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include <string.h>
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "gtksourceiter.h"
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 static gchar *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 gsize needle_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 gsize haystack_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 gchar *ret = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 gchar *p;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 gchar *casefold;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 gchar *caseless_haystack;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 gint i;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 g_return_val_if_fail (haystack != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 g_return_val_if_fail (needle != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 casefold = g_utf8_casefold (haystack, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 needle_len = g_utf8_strlen (needle, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 haystack_len = g_utf8_strlen (caseless_haystack, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 if (needle_len == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 ret = (gchar *)haystack;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 if (haystack_len < needle_len)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 ret = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 p = (gchar*)caseless_haystack;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 needle_len = strlen (needle);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 i = 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 while (*p)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 if ((strncmp (p, needle, needle_len) == 0))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 ret = g_utf8_offset_to_pointer (haystack, i);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 p = g_utf8_next_char (p);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 i++;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 finally_1:
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 g_free (caseless_haystack);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 return ret;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 static gchar *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 gsize needle_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 gsize haystack_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 gchar *ret = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 gchar *p;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 gchar *casefold;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 gchar *caseless_haystack;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 gint i;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 g_return_val_if_fail (haystack != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 g_return_val_if_fail (needle != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 casefold = g_utf8_casefold (haystack, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 needle_len = g_utf8_strlen (needle, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 haystack_len = g_utf8_strlen (caseless_haystack, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 if (needle_len == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 ret = (gchar *)haystack;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 if (haystack_len < needle_len)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 ret = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 haystack_len = strlen (caseless_haystack);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 needle_len = strlen (needle);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 p = (gchar *)caseless_haystack + haystack_len - needle_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 i = haystack_len - needle_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 while (p >= caseless_haystack)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 if (strncasecmp (p, needle, needle_len) == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 ret = g_utf8_offset_to_pointer (haystack, i);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 goto finally_1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 p = g_utf8_prev_char (p);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 i--;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 finally_1:
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 g_free (caseless_haystack);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 return ret;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 static gboolean
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 g_utf8_caselessnmatch (const char *s1, const char *s2,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 gssize n1, gssize n2)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 gchar *casefold;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 gchar *normalized_s1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 gchar *normalized_s2;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 gint len_s1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 gint len_s2;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 gboolean ret = FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 g_return_val_if_fail (s1 != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 g_return_val_if_fail (s2 != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 g_return_val_if_fail (n1 > 0, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 g_return_val_if_fail (n2 > 0, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 casefold = g_utf8_casefold (s1, n1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 casefold = g_utf8_casefold (s2, n2);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 len_s1 = strlen (normalized_s1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 len_s2 = strlen (normalized_s2);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 if (len_s1 < len_s2)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 goto finally_2;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 finally_2:
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 g_free (normalized_s1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 g_free (normalized_s2);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 return ret;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 static void
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 forward_chars_with_skipping (GtkTextIter *iter,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 gint count,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 gboolean skip_invisible,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 gboolean skip_nontext)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 gint i;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 g_return_if_fail (count >= 0);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 i = count;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 while (i > 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 gboolean ignored = FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 if (skip_nontext && gtk_text_iter_get_char (iter) == GTK_TEXT_UNKNOWN_CHAR)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 ignored = TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 if (!ignored && skip_invisible &&
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 /* _gtk_text_btree_char_is_invisible (iter)*/ FALSE)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 ignored = TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 gtk_text_iter_forward_char (iter);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 if (!ignored)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 --i;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 static gboolean
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 lines_match (const GtkTextIter *start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 const gchar **lines,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 gboolean visible_only,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 gboolean slice,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 GtkTextIter *match_start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 GtkTextIter *match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 GtkTextIter next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 gchar *line_text;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 const gchar *found;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 gint offset;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 if (*lines == NULL || **lines == '\0')
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 *match_start = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 *match_end = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 return TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 next = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 gtk_text_iter_forward_line (&next);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 /* No more text in buffer, but *lines is nonempty */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 if (gtk_text_iter_equal (start, &next))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 if (slice)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 if (visible_only)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 line_text = gtk_text_iter_get_visible_slice (start, &next);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 line_text = gtk_text_iter_get_slice (start, &next);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 if (visible_only)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 line_text = gtk_text_iter_get_visible_text (start, &next);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 line_text = gtk_text_iter_get_text (start, &next);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 if (match_start) /* if this is the first line we're matching */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 found = g_utf8_strcasestr (line_text, *lines);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 /* If it's not the first line, we have to match from the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 * start of the line.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 strlen (*lines)))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 found = line_text;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 found = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 if (found == NULL)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 g_free (line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 /* Get offset to start of search string */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 offset = g_utf8_strlen (line_text, found - line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 next = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 /* If match start needs to be returned, set it to the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 * start of the search string.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 *match_start = next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 forward_chars_with_skipping (match_start, offset,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 visible_only, !slice);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 /* Go to end of search string */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 offset += g_utf8_strlen (*lines, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 forward_chars_with_skipping (&next, offset, visible_only, !slice);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 g_free (line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 ++lines;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 *match_end = next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 /* pass NULL for match_start, since we don't need to find the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 * start again.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 return lines_match (&next, lines, visible_only, slice, NULL, match_end);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 static gboolean
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 backward_lines_match (const GtkTextIter *start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 const gchar **lines,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 gboolean visible_only,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 gboolean slice,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 GtkTextIter *match_start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 GtkTextIter *match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 GtkTextIter line, next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 gchar *line_text;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 const gchar *found;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 gint offset;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 if (*lines == NULL || **lines == '\0')
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 *match_start = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 *match_end = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 return TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 line = next = *start;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 if (gtk_text_iter_get_line_offset (&next) == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 if (!gtk_text_iter_backward_line (&next))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 gtk_text_iter_set_line_offset (&next, 0);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 if (slice)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 if (visible_only)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 line_text = gtk_text_iter_get_visible_slice (&next, &line);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 line_text = gtk_text_iter_get_slice (&next, &line);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 if (visible_only)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 line_text = gtk_text_iter_get_visible_text (&next, &line);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 line_text = gtk_text_iter_get_text (&next, &line);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 if (match_start) /* if this is the first line we're matching */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 found = g_utf8_strrcasestr (line_text, *lines);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 /* If it's not the first line, we have to match from the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 * start of the line.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 strlen (*lines)))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 found = line_text;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 found = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 if (found == NULL)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 g_free (line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 /* Get offset to start of search string */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 offset = g_utf8_strlen (line_text, found - line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 /* If match start needs to be returned, set it to the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 * start of the search string.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 *match_start = next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 gtk_text_iter_set_visible_line_offset (match_start, offset);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 /* Go to end of search string */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 offset += g_utf8_strlen (*lines, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 forward_chars_with_skipping (&next, offset, visible_only, !slice);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 g_free (line_text);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 ++lines;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 *match_end = next;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 /* try to match the rest of the lines forward, passing NULL
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 * for match_start so lines_match will try to match the entire
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 * line */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 return lines_match (&next, lines, visible_only,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 slice, NULL, match_end);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 /* strsplit () that retains the delimiter as part of the string. */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 static gchar **
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 strbreakup (const char *string,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 const char *delimiter,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 gint max_tokens)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 GSList *string_list = NULL, *slist;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 gchar **str_array, *s, *casefold, *new_string;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 guint i, n = 1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 g_return_val_if_fail (string != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 g_return_val_if_fail (delimiter != NULL, NULL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 if (max_tokens < 1)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 max_tokens = G_MAXINT;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 s = strstr (string, delimiter);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 if (s)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 guint delimiter_len = strlen (delimiter);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 do
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 guint len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 len = s - string + delimiter_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 new_string = g_new (gchar, len + 1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 strncpy (new_string, string, len);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 new_string[len] = 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 casefold = g_utf8_casefold (new_string, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 g_free (new_string);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 string_list = g_slist_prepend (string_list, new_string);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 n++;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 string = s + delimiter_len;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 s = strstr (string, delimiter);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 } while (--max_tokens && s);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 if (*string)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 n++;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 casefold = g_utf8_casefold (string, -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 g_free (casefold);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 string_list = g_slist_prepend (string_list, new_string);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 str_array = g_new (gchar*, n);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 i = n - 1;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 str_array[i--] = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 for (slist = string_list; slist; slist = slist->next)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 str_array[i--] = slist->data;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 g_slist_free (string_list);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 return str_array;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 /**
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 * gtk_source_iter_forward_search:
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 * @iter: start of search
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 * @str: a search string
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 * @flags: flags affecting how the search is done
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 * @match_start: return location for start of match, or %NULL
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 * @match_end: return location for end of match, or %NULL
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 * @limit: bound for the search, or %NULL for the end of the buffer
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 * Searches forward for @str. Any match is returned by setting
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 * @match_start to the first character of the match and @match_end to the
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 * first character after the match. The search will not continue past
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 * @limit. Note that a search is a linear or O(n) operation, so you
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 * may wish to use @limit to avoid locking up your UI on large
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 * buffers.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 * If the #GTK_SOURCE_SEARCH_VISIBLE_ONLY flag is present, the match may
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 * have invisible text interspersed in @str. i.e. @str will be a
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 * possibly-noncontiguous subsequence of the matched range. similarly,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 * if you specify #GTK_SOURCE_SEARCH_TEXT_ONLY, the match may have
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 * pixbufs or child widgets mixed inside the matched range. If these
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 * flags are not given, the match must be exact; the special 0xFFFC
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 * character in @str will match embedded pixbufs or child widgets.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 * If you specify the #GTK_SOURCE_SEARCH_CASE_INSENSITIVE flag, the text will
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 * be matched regardless of what case it is in.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 * Same as gtk_text_iter_forward_search(), but supports case insensitive
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 * searching.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 * Return value: whether a match was found
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 **/
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 gboolean
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 gtk_source_iter_forward_search (const GtkTextIter *iter,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 const gchar *str,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 GtkSourceSearchFlags flags,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 GtkTextIter *match_start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 GtkTextIter *match_end,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 const GtkTextIter *limit)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 gchar **lines = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 GtkTextIter match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 gboolean retval = FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 GtkTextIter search;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 gboolean visible_only;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 gboolean slice;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 g_return_val_if_fail (iter != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 g_return_val_if_fail (str != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 return gtk_text_iter_forward_search (iter, str, flags,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 match_start, match_end,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 limit);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 if (limit && gtk_text_iter_compare (iter, limit) >= 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 if (*str == '\0')
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 /* If we can move one char, return the empty string there */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 match = *iter;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 if (gtk_text_iter_forward_char (&match))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 if (limit && gtk_text_iter_equal (&match, limit))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 *match_start = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 *match_end = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 return TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 visible_only = (flags & GTK_SOURCE_SEARCH_VISIBLE_ONLY) != 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 slice = (flags & GTK_SOURCE_SEARCH_TEXT_ONLY) == 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 /* locate all lines */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559 lines = strbreakup (str, "\n", -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 search = *iter;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 do
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 /* This loop has an inefficient worst-case, where
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 * gtk_text_iter_get_text () is called repeatedly on
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 * a single line.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 GtkTextIter end;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 if (limit && gtk_text_iter_compare (&search, limit) >= 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 break;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 if (lines_match (&search, (const gchar**)lines,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 visible_only, slice, &match, &end))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 if (limit == NULL || (limit &&
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 gtk_text_iter_compare (&end, limit) < 0))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 retval = TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 *match_start = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 *match_end = end;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 break;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 } while (gtk_text_iter_forward_line (&search));
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 g_strfreev ((gchar**)lines);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 return retval;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 /**
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 * gtk_source_iter_backward_search:
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 * @iter: a #GtkTextIter where the search begins
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 * @str: search string
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 * @flags: bitmask of flags affecting the search
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 * @match_start: return location for start of match, or %NULL
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 * @match_end: return location for end of match, or %NULL
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 * @limit: location of last possible @match_start, or %NULL for start of buffer
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 * Same as gtk_text_iter_backward_search(), but supports case insensitive
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 * searching.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 *
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 * Return value: whether a match was found
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 **/
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 gboolean
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 gtk_source_iter_backward_search (const GtkTextIter *iter,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 const gchar *str,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 GtkSourceSearchFlags flags,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 GtkTextIter *match_start,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 GtkTextIter *match_end,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 const GtkTextIter *limit)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 gchar **lines = NULL;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 GtkTextIter match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 gboolean retval = FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 GtkTextIter search;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 gboolean visible_only;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 gboolean slice;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 g_return_val_if_fail (iter != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 g_return_val_if_fail (str != NULL, FALSE);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 return gtk_text_iter_backward_search (iter, str, flags,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 match_start, match_end,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 limit);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 if (limit && gtk_text_iter_compare (iter, limit) <= 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 if (*str == '\0')
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 /* If we can move one char, return the empty string there */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 match = *iter;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 if (gtk_text_iter_backward_char (&match))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 if (limit && gtk_text_iter_equal (&match, limit))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 *match_start = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 *match_end = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 return TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 return FALSE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 visible_only = (flags & GTK_SOURCE_SEARCH_VISIBLE_ONLY) != 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 slice = (flags & GTK_SOURCE_SEARCH_TEXT_ONLY) == 0;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661 /* locate all lines */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 lines = strbreakup (str, "\n", -1);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 search = *iter;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 while (TRUE)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 /* This loop has an inefficient worst-case, where
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 * gtk_text_iter_get_text () is called repeatedly on
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 * a single line.
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 */
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 GtkTextIter end;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 if (limit && gtk_text_iter_compare (&search, limit) <= 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 break;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 if (backward_lines_match (&search, (const gchar**)lines,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 visible_only, slice, &match, &end))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 if (limit == NULL || (limit &&
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681 gtk_text_iter_compare (&end, limit) > 0))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 retval = TRUE;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685 if (match_start)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686 *match_start = match;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 if (match_end)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688 *match_end = end;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690 break;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693 if (gtk_text_iter_get_line_offset (&search) == 0)
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
695 if (!gtk_text_iter_backward_line (&search))
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 break;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 else
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699 {
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 gtk_text_iter_set_line_offset (&search, 0);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
704 g_strfreev ((gchar**)lines);
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
706 return retval;
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707 }
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 /*
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710 * gtk_source_iter_find_matching_bracket is implemented in gtksourcebuffer.c
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
711 */