Common subdirectories: ../gtksourceview (copy)/gnu-regex and ./gnu-regex
diff -u ../gtksourceview (copy)/gtksourceiter.c ./gtksourceiter.c
--- ../gtksourceview (copy)/gtksourceiter.c	2005-11-14 14:43:12.000000000 +0100
+++ ./gtksourceiter.c	2006-11-02 17:05:16.000000000 +0100
@@ -29,6 +29,7 @@
 
 #include <string.h>
 #include "gtksourceiter.h"
+#include "gtksourceregex.h"
 
 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
 
@@ -258,6 +259,116 @@
 	}
 }
 
+static char *
+get_line_text (const GtkTextIter *start,
+	const GtkTextIter *next,
+	gboolean visible_only,
+	gboolean slice)
+{
+	if (slice)
+	{
+		if (visible_only)
+			return gtk_text_iter_get_visible_slice (start, next);
+		else
+			return gtk_text_iter_get_slice (start, next);
+	}
+	else
+	{
+		if (visible_only)
+			return gtk_text_iter_get_visible_text (start, next);
+		else
+			return gtk_text_iter_get_text (start, next);
+	}
+}
+
+static gboolean
+regex_match (const GtkTextIter *start,
+	     GtkSourceRegex    *search_regex,
+	     gboolean           visible_only,
+	     gboolean           slice,
+	     GtkTextIter       *match_start,
+	     GtkTextIter       *match_end)
+{
+	gchar *line_text;
+	GtkTextIter next;
+	GtkSourceBufferMatch match;
+
+	next = *start;
+	gtk_text_iter_forward_line (&next);
+
+	if (search_regex == NULL)
+	{
+		if (match_start)
+			*match_start = *start;
+		if (match_end)
+			*match_end = *start;
+		return TRUE;
+	}
+
+	line_text = get_line_text (start, &next, visible_only, slice);
+
+	gint offset = gtk_source_regex_search (search_regex, line_text,
+		0, -1, &match, 0);
+	g_free (line_text);
+
+	if (offset >= 0)
+	{
+		*match_start = *start;
+		forward_chars_with_skipping (match_start, match.startpos, visible_only, !slice, FALSE);
+		*match_end = *start;
+		forward_chars_with_skipping (match_end, match.endpos, visible_only, !slice, FALSE);
+	}
+
+	return (offset >= 0);
+}
+
+static gboolean
+backward_regex_match (const GtkTextIter *start,
+	     GtkSourceRegex    *search_regex,
+	     gboolean           visible_only,
+	     gboolean           slice,
+	     GtkTextIter       *match_start,
+	     GtkTextIter       *match_end)
+{
+	gchar *line_text;
+	GtkTextIter next;
+	GtkSourceBufferMatch match;
+
+	next = *start;
+	if (gtk_text_iter_get_line_offset (&next) == 0)
+	{
+		if (!gtk_text_iter_backward_line (&next))
+			return FALSE;
+	}
+	else
+		gtk_text_iter_set_line_offset (&next, 0);
+	
+	if (search_regex == NULL)
+	{
+		if (match_start)
+			*match_start = *start;
+		if (match_end)
+			*match_end = *start;
+		return TRUE;
+	}
+
+	line_text = get_line_text (start, &next, visible_only, slice);
+
+	gint offset = gtk_source_regex_search (search_regex, line_text,
+		0, -1, &match, 0);
+	g_free (line_text);
+
+	if (offset >= 0)
+	{
+		*match_start = *start;
+		forward_chars_with_skipping (match_start, match.startpos, visible_only, !slice, FALSE);
+		*match_end = *start;
+		forward_chars_with_skipping (match_end, match.endpos, visible_only, !slice, FALSE);
+	}
+
+	return (offset >= 0);
+}
+
 static gboolean
 lines_match (const GtkTextIter *start,
 	     const gchar      **lines,
@@ -287,20 +398,7 @@
 	if (gtk_text_iter_equal (start, &next))
 		return FALSE;
 
-	if (slice)
-	{
-		if (visible_only)
-			line_text = gtk_text_iter_get_visible_slice (start, &next);
-		else
-			line_text = gtk_text_iter_get_slice (start, &next);
-	}
-	else
-	{
-		if (visible_only)
-			line_text = gtk_text_iter_get_visible_text (start, &next);
-		else
-			line_text = gtk_text_iter_get_text (start, &next);
-	}
+	line_text = get_line_text (start, &next, visible_only, slice);
 
 	if (match_start) /* if this is the first line we're matching */
 	{
@@ -359,6 +457,7 @@
 		      const gchar      **lines,
 		      gboolean           visible_only,
 		      gboolean           slice,
+		      GtkSourceRegex    *regex,
 		      GtkTextIter       *match_start,
 		      GtkTextIter       *match_end)
 {
@@ -385,20 +484,7 @@
 	else
 		gtk_text_iter_set_line_offset (&next, 0);
 
-	if (slice)
-	{
-		if (visible_only)
-			line_text = gtk_text_iter_get_visible_slice (&next, &line);
-		else
-			line_text = gtk_text_iter_get_slice (&next, &line);
-	}
-	else
-	{
-		if (visible_only)
-			line_text = gtk_text_iter_get_visible_text (&next, &line);
-		else
-			line_text = gtk_text_iter_get_text (&next, &line);
-	}
+	line_text = get_line_text (&next, &line, visible_only, slice);
 
 	if (match_start) /* if this is the first line we're matching */
 	{
@@ -559,11 +645,17 @@
 	GtkTextIter search;
 	gboolean visible_only;
 	gboolean slice;
+	gboolean regex;
+	gboolean case_insensitive;
+	GtkSourceRegex *search_regex = NULL;
 
 	g_return_val_if_fail (iter != NULL, FALSE);
 	g_return_val_if_fail (str != NULL, FALSE);
 
-	if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
+	regex = (flags & GTK_SOURCE_SEARCH_REGEXP) != 0;
+	case_insensitive = (flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) != 0;
+
+	if ( (!case_insensitive) && (!regex) )
 		return gtk_text_iter_forward_search (iter, str, flags,
 						     match_start, match_end,
 						     limit); 
@@ -596,11 +688,23 @@
 	visible_only = (flags & GTK_SOURCE_SEARCH_VISIBLE_ONLY) != 0;
 	slice = (flags & GTK_SOURCE_SEARCH_TEXT_ONLY) == 0;
 
-	/* locate all lines */
-	lines = strbreakup (str, "\n", -1);
-
 	search = *iter;
 
+	if (regex)
+	{
+		if (case_insensitive)
+			search_regex = gtk_source_regex_compile_case_insensitive (str);
+		else
+			search_regex = gtk_source_regex_compile(str);
+		if (search_regex == NULL) // invalid regex
+			return FALSE;
+	}
+	else
+	{
+		/* locate all lines */
+		lines = strbreakup (str, "\n", -1);
+	}
+
 	do
 	{
 		/* This loop has an inefficient worst-case, where
@@ -612,8 +716,18 @@
 		if (limit && gtk_text_iter_compare (&search, limit) >= 0)
 			break;
 
-		if (lines_match (&search, (const gchar**)lines,
-				 visible_only, slice, &match, &end))
+		gboolean is_match = FALSE;
+		if (regex)
+		{
+			is_match = regex_match (&search, search_regex,
+				 visible_only, slice, &match, &end);
+		}
+		else
+		{
+			is_match = lines_match (&search, (const gchar**)lines,
+				 visible_only, slice, &match, &end);
+		}
+		if (is_match)
 		{
 			if (limit == NULL ||
 			    (limit && gtk_text_iter_compare (&end, limit) <= 0))
@@ -629,7 +743,10 @@
 		}
 	} while (gtk_text_iter_forward_line (&search));
 
-	g_strfreev ((gchar**)lines);
+	if (regex)
+		gtk_source_regex_destroy (search_regex);
+	else
+		g_strfreev ((gchar**)lines);
 
 	return retval;
 }
@@ -662,11 +779,18 @@
 	GtkTextIter search;
 	gboolean visible_only;
 	gboolean slice;
+	gboolean regex;
+	gboolean case_insensitive;
+	GtkSourceRegex *search_regex = NULL;
 
 	g_return_val_if_fail (iter != NULL, FALSE);
 	g_return_val_if_fail (str != NULL, FALSE);
 
-	if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
+	regex = (flags & GTK_SOURCE_SEARCH_REGEXP) != 0;
+	case_insensitive = (flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) != 0;
+
+	if ( (!case_insensitive)
+			&& (!regex) )
 		return gtk_text_iter_backward_search (iter, str, flags,
 						      match_start, match_end,
 						      limit); 
@@ -699,11 +823,23 @@
 	visible_only = (flags & GTK_SOURCE_SEARCH_VISIBLE_ONLY) != 0;
 	slice = (flags & GTK_SOURCE_SEARCH_TEXT_ONLY) == 0;
 
-	/* locate all lines */
-	lines = strbreakup (str, "\n", -1);
-
 	search = *iter;
 
+	if (regex)
+	{
+		if (case_insensitive)
+			search_regex = gtk_source_regex_compile_case_insensitive (str);
+		else
+			search_regex = gtk_source_regex_compile(str);
+		if (search_regex == NULL) // invalid regex
+			return FALSE;
+	}
+	else
+	{
+		/* locate all lines */
+		lines = strbreakup (str, "\n", -1);
+	}
+
 	while (TRUE)
 	{
 		/* This loop has an inefficient worst-case, where
@@ -715,8 +851,18 @@
 		if (limit && gtk_text_iter_compare (&search, limit) <= 0)
 			break;
 
-		if (backward_lines_match (&search, (const gchar**)lines,
-					  visible_only, slice, &match, &end))
+		gboolean is_match = FALSE;
+		if (regex)
+		{
+			is_match = backward_regex_match (&search, search_regex,
+				 visible_only, slice, &match, &end);
+		}
+		else
+		{
+			is_match = backward_lines_match (&search, (const gchar**)lines,
+					  visible_only, slice, search_regex, &match, &end);
+		}
+		if (is_match)
 		{
 			if (limit == NULL || (limit &&
 					      gtk_text_iter_compare (&end, limit) > 0))
@@ -741,8 +887,10 @@
 			gtk_text_iter_set_line_offset (&search, 0);
 		}
 	}
-
-	g_strfreev ((gchar**)lines);
+	if (regex)
+		gtk_source_regex_destroy (search_regex);
+	else
+		g_strfreev ((gchar**)lines);
 
 	return retval;
 }
diff -u ../gtksourceview (copy)/gtksourceiter.h ./gtksourceiter.h
--- ../gtksourceview (copy)/gtksourceiter.h	2004-05-24 22:36:32.000000000 +0200
+++ ./gtksourceiter.h	2006-10-31 19:28:39.000000000 +0100
@@ -30,8 +30,8 @@
 {
 	GTK_SOURCE_SEARCH_VISIBLE_ONLY		 = 1 << 0,
 	GTK_SOURCE_SEARCH_TEXT_ONLY		 = 1 << 1,
-	GTK_SOURCE_SEARCH_CASE_INSENSITIVE	 = 1 << 2
-	/* Possible future plans: SEARCH_REGEXP */
+	GTK_SOURCE_SEARCH_CASE_INSENSITIVE	 = 1 << 2,
+	GTK_SOURCE_SEARCH_REGEXP		 = 1 << 3
 } GtkSourceSearchFlags;
 
 gboolean gtk_source_iter_forward_search 	(const GtkTextIter   *iter,
Binary files ../gtksourceview (copy)/gtksourceiter.o and ./gtksourceiter.o differ
diff -u ../gtksourceview (copy)/gtksourceregex.c ./gtksourceregex.c
--- ../gtksourceview (copy)/gtksourceregex.c	2005-11-14 18:18:18.000000000 +0100
+++ ./gtksourceregex.c	2006-10-31 21:20:51.000000000 +0100
@@ -44,7 +44,7 @@
 };
 
 GtkSourceRegex *
-gtk_source_regex_compile (const gchar *pattern)
+gtk_source_regex_compile_internal (const gchar *pattern, gint options)
 {
 	GtkSourceRegex *regex;
 	const char *result = NULL;
@@ -53,7 +53,7 @@
 
 	regex = g_new0 (GtkSourceRegex, 1);
 
-	re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED;
+	re_syntax_options = options;
 	regex->buf.translate = NULL;
 	regex->buf.fastmap = g_malloc (256);
 	regex->buf.allocated = 0;
@@ -79,6 +79,18 @@
 	}
 }
 
+GtkSourceRegex *
+gtk_source_regex_compile (const gchar *pattern)
+{
+	return gtk_source_regex_compile_internal (pattern, RE_SYNTAX_POSIX_MINIMAL_EXTENDED);
+}
+
+GtkSourceRegex *
+gtk_source_regex_compile_case_insensitive (const gchar *pattern)
+{
+	return gtk_source_regex_compile_internal (pattern, RE_SYNTAX_POSIX_MINIMAL_EXTENDED|RE_ICASE);
+}
+
 void
 gtk_source_regex_destroy (GtkSourceRegex *regex)
 {
@@ -134,7 +146,7 @@
 
 	regex->buf.not_bol = (options & GTK_SOURCE_REGEX_NOT_BOL);
 	regex->buf.not_eol = (options & GTK_SOURCE_REGEX_NOT_EOL);
-	
+
 	res = re_search (&regex->buf, text, length,
 			 pos, length - pos, &regex->reg);
 
diff -u ../gtksourceview (copy)/gtksourceregex.h ./gtksourceregex.h
--- ../gtksourceview (copy)/gtksourceregex.h	2004-02-21 01:08:23.000000000 +0100
+++ ./gtksourceregex.h	2006-11-01 22:13:44.000000000 +0100
@@ -43,6 +43,8 @@
 
 GtkSourceRegex *gtk_source_regex_compile 	(const gchar          *pattern);
 
+GtkSourceRegex *gtk_source_regex_compile_case_insensitive(const gchar          *pattern);
+
 void		gtk_source_regex_destroy	(GtkSourceRegex       *regex);
 
 gint 	        gtk_source_regex_search         (GtkSourceRegex       *regex,
Binary files ../gtksourceview (copy)/gtksourceregex.o and ./gtksourceregex.o differ
diff -u ../gtksourceview (copy)/gtksourceview-typebuiltins.c ./gtksourceview-typebuiltins.c
--- ../gtksourceview (copy)/gtksourceview-typebuiltins.c	2006-10-01 20:03:46.000000000 +0200
+++ ./gtksourceview-typebuiltins.c	2006-10-31 19:28:41.000000000 +0100
@@ -10,6 +10,7 @@
   { GTK_SOURCE_SEARCH_VISIBLE_ONLY, "GTK_SOURCE_SEARCH_VISIBLE_ONLY", "visible-only" },
   { GTK_SOURCE_SEARCH_TEXT_ONLY, "GTK_SOURCE_SEARCH_TEXT_ONLY", "text-only" },
   { GTK_SOURCE_SEARCH_CASE_INSENSITIVE, "GTK_SOURCE_SEARCH_CASE_INSENSITIVE", "case-insensitive" },
+  { GTK_SOURCE_SEARCH_REGEXP, "GTK_SOURCE_SEARCH_REGEXP", "regexp" },
   { 0, NULL, NULL }
 };
 
Binary files ../gtksourceview (copy)/gtksourceview-typebuiltins.o and ./gtksourceview-typebuiltins.o differ
Common subdirectories: ../gtksourceview (copy)/language-specs and ./language-specs
Common subdirectories: ../gtksourceview (copy)/.libs and ./.libs
Only in .: patch.diff
