Repatched for gtksourceview

master
Yevgen Muntyan 2007-01-10 19:17:20 -06:00
parent f6ef4048a4
commit ce5b7a687a
1 changed files with 32 additions and 17 deletions

View File

@ -32,10 +32,6 @@
#define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
#define g_utf8_strcasestr gtk_source_strcasestr
#define g_utf8_strrcasestr gtk_source_strrcasestr
#define g_utf8_caselessnmatch gtk_source_caselessnmatch
/* this function acts like g_utf8_offset_to_pointer() except that if it finds a
* decomposable character it consumes the decomposition length from the given
* offset. So it's useful when the offset was calculated for the normalized
@ -60,8 +56,27 @@ pointer_from_offset_skipping_decomp (const gchar *str, gint offset)
return p;
}
static gboolean
exact_prefix_cmp (const gchar *string,
const gchar *prefix,
guint prefix_len)
{
GUnicodeType type;
if (strncmp (string, prefix, prefix_len) != 0)
return FALSE;
if (string[prefix_len] == '\0')
return TRUE;
type = g_unichar_type (g_utf8_get_char (string + prefix_len));
return type != G_UNICODE_NON_SPACING_MARK &&
type != G_UNICODE_ENCLOSING_MARK &&
type != G_UNICODE_NON_SPACING_MARK;
}
static const gchar *
g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
gtk_source_strcasestr (const gchar *haystack, const gchar *needle)
{
gsize needle_len;
gsize haystack_len;
@ -99,7 +114,7 @@ g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
while (*p)
{
if ((strncmp (p, needle, needle_len) == 0))
if (exact_prefix_cmp (p, needle, needle_len))
{
ret = pointer_from_offset_skipping_decomp (haystack, i);
goto finally_1;
@ -116,7 +131,7 @@ finally_1:
}
static const gchar *
g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
gtk_source_strrcasestr (const gchar *haystack, const gchar *needle)
{
gsize needle_len;
gsize haystack_len;
@ -154,7 +169,7 @@ g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
while (p >= caseless_haystack)
{
if (strncmp (p, needle, needle_len) == 0)
if (exact_prefix_cmp (p, needle, needle_len))
{
ret = pointer_from_offset_skipping_decomp (haystack, i);
goto finally_1;
@ -171,8 +186,8 @@ finally_1:
}
static gboolean
g_utf8_caselessnmatch (const char *s1, const char *s2,
gssize n1, gssize n2)
gtk_source_caselessnmatch (const char *s1, const char *s2,
gssize n1, gssize n2)
{
gchar *casefold;
gchar *normalized_s1;
@ -204,7 +219,7 @@ g_utf8_caselessnmatch (const char *s1, const char *s2,
finally_2:
g_free (normalized_s1);
g_free (normalized_s2);
g_free (normalized_s2);
return ret;
}
@ -308,15 +323,15 @@ lines_match (const GtkTextIter *start,
if (match_start) /* if this is the first line we're matching */
{
found = g_utf8_strcasestr (line_text, *lines);
found = gtk_source_strcasestr (line_text, *lines);
}
else
{
/* If it's not the first line, we have to match from the
* start of the line.
*/
if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
strlen (*lines)))
if (gtk_source_caselessnmatch (line_text, *lines, strlen (line_text),
strlen (*lines)))
found = line_text;
else
found = NULL;
@ -406,15 +421,15 @@ backward_lines_match (const GtkTextIter *start,
if (match_start) /* if this is the first line we're matching */
{
found = g_utf8_strrcasestr (line_text, *lines);
found = gtk_source_strrcasestr (line_text, *lines);
}
else
{
/* If it's not the first line, we have to match from the
* start of the line.
*/
if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
strlen (*lines)))
if (gtk_source_caselessnmatch (line_text, *lines, strlen (line_text),
strlen (*lines)))
found = line_text;
else
found = NULL;