Updated eggregex from Marco's repo

master
Yevgen Muntyan 2006-12-13 22:40:00 -06:00
parent c8b15f5ac5
commit fbf40d617b
14 changed files with 950 additions and 544 deletions

View File

@ -1145,7 +1145,7 @@ moo_html_parse_url (const char *url,
if (egg_regex_match (regex, url, 0) < 1)
{
egg_regex_unref (regex);
egg_regex_free (regex);
return FALSE;
}
@ -1157,7 +1157,7 @@ moo_html_parse_url (const char *url,
if (!*base || !**base) {g_free (*base); *base = NULL;}
if (!*anchor || !**anchor) {g_free (*anchor); *anchor = NULL;}
egg_regex_unref (regex);
egg_regex_free (regex);
return TRUE;
}

View File

@ -2305,7 +2305,7 @@ regex_unref (Regex *regex)
if (regex != NULL && --regex->ref_count == 0)
{
if (regex->resolved)
egg_regex_unref (regex->u.regex);
egg_regex_free (regex->u.regex);
else
g_free (regex->u.info.pattern);
g_free (regex);
@ -2522,7 +2522,7 @@ regex_resolve (Regex *regex,
regex->u.info.pattern,
-1, 0, 0,
replace_start_regex,
&data);
&data, NULL);
new_regex = regex_new (expanded_regex, regex->u.info.flags, NULL);
if (new_regex == NULL || !new_regex->resolved)
@ -2534,7 +2534,7 @@ regex_resolve (Regex *regex,
new_regex = regex_new ("$never-match^", 0, NULL);
}
egg_regex_unref (start_ref);
egg_regex_free (start_ref);
return new_regex;
}

View File

@ -1003,7 +1003,7 @@ expand_regex_vars (ParserState *parser_state, gchar *regex, gint len, GError **e
data.parser_state = parser_state;
data.error = NULL;
expanded_regex = egg_regex_replace_eval (egg_re, regex, len, 0, 0,
replace_by_id, &data);
replace_by_id, &data, NULL);
if (data.error == NULL)
{
@ -1011,7 +1011,7 @@ expand_regex_vars (ParserState *parser_state, gchar *regex, gint len, GError **e
regex, expanded_regex));
}
egg_regex_unref (egg_re);
egg_regex_free (egg_re);
if (data.error != NULL)
{
@ -1087,12 +1087,12 @@ expand_regex_delimiters (ParserState *parser_state,
egg_re = egg_regex_new (re, 0, 0, NULL);
expanded_regex = egg_regex_replace_eval (egg_re, regex, len, 0, 0,
replace_delimiter, parser_state);
replace_delimiter, parser_state, NULL);
DEBUG (g_message ("expanded regex delims '%s' to '%s'",
regex, expanded_regex));
egg_regex_unref (egg_re);
egg_regex_free (egg_re);
return expanded_regex;
}

View File

@ -623,7 +623,7 @@ moo_completion_group_set_pattern (MooCompletionGroup *group,
g_error_free (error);
}
egg_regex_unref (group->regex);
egg_regex_free (group->regex);
group->regex = regex;
g_free (group->parens);
@ -646,7 +646,7 @@ err:
if (error)
g_error_free (error);
g_free (real_pattern);
egg_regex_unref (regex);
egg_regex_free (regex);
}
@ -686,7 +686,7 @@ moo_completion_group_free (MooCompletionGroup *group)
{
g_return_if_fail (group != NULL);
egg_regex_unref (group->regex);
egg_regex_free (group->regex);
g_free (group->parens);
g_completion_free (group->cmpl);
g_free (group->suffix);

View File

@ -391,7 +391,7 @@ regex_ref_free (RegexRef *ref)
{
if (ref)
{
egg_regex_unref (ref->regex);
egg_regex_free (ref->regex);
g_free (ref);
}
}

View File

@ -44,7 +44,7 @@ filter_setting_free (FilterSetting *setting)
if (setting)
{
g_free (setting->config);
egg_regex_unref (setting->regex);
egg_regex_free (setting->regex);
g_free (setting);
}
}

View File

@ -248,7 +248,7 @@ filter_info_unref (FilterInfo *info)
for (i = 0; i < info->n_patterns; ++i)
if (info->patterns[i].re)
egg_regex_unref (info->patterns[i].re);
egg_regex_free (info->patterns[i].re);
g_free (info->patterns);
g_free (info);

View File

@ -230,13 +230,13 @@ moo_find_finalize (GObject *object)
MooFind *find = MOO_FIND (object);
g_object_unref (find->xml);
egg_regex_unref (find->regex);
egg_regex_free (find->regex);
G_OBJECT_CLASS(moo_find_parent_class)->finalize (object);
}
GtkWidget*
GtkWidget *
moo_find_new (gboolean replace)
{
return g_object_new (MOO_TYPE_FIND, "replace", replace, NULL);
@ -444,7 +444,7 @@ moo_find_run (MooFind *find,
search_entry = moo_glade_xml_get_widget (find->xml, "search_entry");
replace_entry = moo_glade_xml_get_widget (find->xml, "replace_entry");
egg_regex_unref (find->regex);
egg_regex_free (find->regex);
find->regex = NULL;
while (TRUE)
@ -504,7 +504,7 @@ moo_find_run (MooFind *find,
{
_moo_text_regex_error_dialog (GTK_WIDGET (find), error);
g_error_free (error);
egg_regex_unref (find->regex);
egg_regex_free (find->regex);
find->regex = NULL;
continue;
}
@ -514,8 +514,8 @@ moo_find_run (MooFind *find,
moo_prefs_set_flags (moo_edit_setting (MOO_EDIT_PREFS_SEARCH_FLAGS), flags);
g_free (last_search);
last_search = g_strdup (search_for);
egg_regex_unref (last_regex);
last_regex = egg_regex_ref (find->regex);
egg_regex_free (last_regex);
last_regex = egg_regex_copy (find->regex);
moo_history_list_add (search_history, search_for);
@ -580,7 +580,7 @@ moo_find_set_flags (MooFind *find,
}
char*
char *
moo_find_get_text (MooFind *find)
{
MooCombo *entry;
@ -590,15 +590,15 @@ moo_find_get_text (MooFind *find)
}
EggRegex*
EggRegex *
moo_find_get_regex (MooFind *find)
{
g_return_val_if_fail (MOO_IS_FIND (find), NULL);
return egg_regex_ref (find->regex);
return egg_regex_copy (find->regex);
}
char*
char *
moo_find_get_replacement (MooFind *find)
{
MooCombo *entry;
@ -779,7 +779,7 @@ moo_text_view_run_find (GtkTextView *view,
}
g_free (text);
egg_regex_unref (regex);
egg_regex_free (regex);
}
@ -816,7 +816,7 @@ moo_text_view_run_find_current_word (GtkTextView *view,
g_free (last_search);
last_search = search_term;
egg_regex_unref (last_regex);
egg_regex_free (last_regex);
last_regex = NULL;
moo_history_list_add (search_history, search_term);
@ -1263,7 +1263,7 @@ moo_text_view_run_replace (GtkTextView *view,
g_free (text);
g_free (replacement);
egg_regex_unref (regex);
egg_regex_free (regex);
}

View File

@ -218,7 +218,7 @@ get_regex (const char *pattern,
{
EggRegexCompileFlags re_flags = 0;
egg_regex_unref (saved_regex);
egg_regex_free (saved_regex);
g_free (saved_pattern);
saved_pattern = g_strdup (pattern);

View File

@ -3912,7 +3912,7 @@ quick_search_find_from (MooTextView *view,
return;
}
egg_regex_unref (re);
egg_regex_free (re);
}
buffer = get_buffer (view);

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
*
* Copyright (C) 1999, 2000 Scott Wimer
* Copyright (C) 2004, Matthias Clasen <mclasen@redhat.com>
* Copyright (C) 2005 - 2006, Marco Barisione <barisione@gmail.com>
* Copyright (C) 2005 - 2006, Marco Barisione <marco@barisione.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -19,21 +19,20 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __EGGREGEX_H__
#define __EGGREGEX_H__
/* Modified by muntyan to adapt for libmoo */
#include <glib/gtypes.h>
#include <glib/gquark.h>
#include <glib/gerror.h>
#include <glib/gstring.h>
#ifndef __EGG_REGEX_H__
#define __EGG_REGEX_H__
#include <glib.h>
G_BEGIN_DECLS
#define egg_regex_error_quark _moo_egg_regex_error_quark
#define egg_regex_new _moo_egg_regex_new
#define egg_regex_free _moo_egg_regex_free
#define egg_regex_optimize _moo_egg_regex_optimize
#define egg_regex_ref _moo_egg_regex_ref
#define egg_regex_unref _moo_egg_regex_unref
#define egg_regex_copy _moo_egg_regex_copy
#define egg_regex_get_pattern _moo_egg_regex_get_pattern
#define egg_regex_clear _moo_egg_regex_clear
@ -57,6 +56,7 @@ G_BEGIN_DECLS
#define egg_regex_split_full _moo_egg_regex_split_full
#define egg_regex_split_next _moo_egg_regex_split_next
#define egg_regex_split_next_full _moo_egg_regex_split_next_full
#define egg_regex_expand_references _moo_egg_regex_expand_references
#define egg_regex_replace _moo_egg_regex_replace
#define egg_regex_replace_literal _moo_egg_regex_replace_literal
#define egg_regex_replace_eval _moo_egg_regex_replace_eval
@ -66,6 +66,7 @@ G_BEGIN_DECLS
#define egg_regex_eval_replacement _moo_egg_regex_eval_replacement
#define egg_regex_try_eval_replacement _moo_egg_regex_try_eval_replacement
typedef enum
{
EGG_REGEX_ERROR_COMPILE,
@ -78,6 +79,8 @@ typedef enum
GQuark egg_regex_error_quark (void);
/* Remember to update EGG_REGEX_COMPILE_ALL in gregex.c after
* adding a new flag. */
typedef enum
{
EGG_REGEX_CASELESS = 1 << 0,
@ -88,16 +91,24 @@ typedef enum
EGG_REGEX_DOLLAR_ENDONLY = 1 << 5,
EGG_REGEX_UNGREEDY = 1 << 9,
EGG_REGEX_RAW = 1 << 11,
EGG_REGEX_NO_AUTO_CAPTURE = 1 << 12
EGG_REGEX_NO_AUTO_CAPTURE = 1 << 12,
EGG_REGEX_DUPNAMES = 1 << 19,
EGG_REGEX_NEWLINE_CR = 1 << 20,
EGG_REGEX_NEWLINE_CRLF = 1 << 21 | EGG_REGEX_NEWLINE_CR
} EggRegexCompileFlags;
/* Remember to update EGG_REGEX_MATCH_ALL in gregex.c after
* adding a new flag. */
typedef enum
{
EGG_REGEX_MATCH_ANCHORED = 1 << 4,
EGG_REGEX_MATCH_NOTBOL = 1 << 7,
EGG_REGEX_MATCH_NOTEOL = 1 << 8,
EGG_REGEX_MATCH_NOTEMPTY = 1 << 10,
EGG_REGEX_MATCH_PARTIAL = 1 << 15
EGG_REGEX_MATCH_ANCHORED = 1 << 4,
EGG_REGEX_MATCH_NOTBOL = 1 << 7,
EGG_REGEX_MATCH_NOTEOL = 1 << 8,
EGG_REGEX_MATCH_NOTEMPTY = 1 << 10,
EGG_REGEX_MATCH_PARTIAL = 1 << 15,
EGG_REGEX_MATCH_NEWLINE_CR = 1 << 20,
EGG_REGEX_MATCH_NEWLINE_LF = 1 << 21,
EGG_REGEX_MATCH_NEWLINE_CRLF = EGG_REGEX_MATCH_NEWLINE_CR | EGG_REGEX_MATCH_NEWLINE_LF
} EggRegexMatchFlags;
typedef struct _EggRegex EggRegex;
@ -105,124 +116,118 @@ typedef struct _EggRegex EggRegex;
typedef gboolean (*EggRegexEvalCallback) (const EggRegex*, const gchar*, GString*, gpointer);
EggRegex *egg_regex_new (const gchar *pattern,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options,
GError **error);
gboolean egg_regex_optimize (EggRegex *regex,
GError **error);
EggRegex *egg_regex_ref (EggRegex *regex);
void egg_regex_unref (EggRegex *regex);
EggRegex *egg_regex_copy (const EggRegex *regex);
const gchar * egg_regex_get_pattern
(const EggRegex *regex);
void egg_regex_clear (EggRegex *regex);
gboolean egg_regex_match_simple (const gchar *pattern,
const gchar *string,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options);
gboolean egg_regex_match (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gboolean egg_regex_match_next (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_next_full
(EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gboolean egg_regex_match_all (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_all_full
(EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gint egg_regex_get_match_count
(const EggRegex *regex);
gboolean egg_regex_is_partial_match
(const EggRegex *regex);
gchar *egg_regex_fetch (const EggRegex *regex,
gint match_num,
const gchar *string);
gboolean egg_regex_fetch_pos (const EggRegex *regex,
gint match_num,
gint *start_pos,
gint *end_pos);
gchar *egg_regex_fetch_named (const EggRegex *regex,
const gchar *name,
const gchar *string);
gboolean egg_regex_fetch_named_pos
(const EggRegex *regex,
const gchar *name,
gint *start_pos,
gint *end_pos);
gchar **egg_regex_fetch_all (const EggRegex *regex,
const gchar *string);
gint egg_regex_get_string_number
(const EggRegex *regex,
const gchar *name);
gchar **egg_regex_split_simple (const gchar *pattern,
const gchar *string,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options);
gchar **egg_regex_split (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gchar **egg_regex_split_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
gint max_tokens,
GError **error);
gchar *egg_regex_split_next (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gchar *egg_regex_split_next_full
(EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gchar *egg_regex_replace (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
const gchar *replacement,
EggRegexMatchFlags match_options,
GError **error);
gchar *egg_regex_replace_literal
(EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
const gchar *replacement,
EggRegexMatchFlags match_options);
gchar *egg_regex_replace_eval (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
EggRegexEvalCallback eval,
gpointer user_data);
gchar *egg_regex_escape_string
(const gchar *string,
gint length);
EggRegex *egg_regex_new (const gchar *pattern,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options,
GError **error);
void egg_regex_free (EggRegex *regex);
gboolean egg_regex_optimize (EggRegex *regex,
GError **error);
EggRegex *egg_regex_copy (const EggRegex *regex);
const gchar *egg_regex_get_pattern (const EggRegex *regex);
void egg_regex_clear (EggRegex *regex);
gboolean egg_regex_match_simple (const gchar *pattern,
const gchar *string,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options);
gboolean egg_regex_match (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gboolean egg_regex_match_next (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_next_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gboolean egg_regex_match_all (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gboolean egg_regex_match_all_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gint egg_regex_get_match_count (const EggRegex *regex);
gboolean egg_regex_is_partial_match (const EggRegex *regex);
gchar *egg_regex_fetch (const EggRegex *regex,
gint match_num,
const gchar *string);
gboolean egg_regex_fetch_pos (const EggRegex *regex,
gint match_num,
gint *start_pos,
gint *end_pos);
gchar *egg_regex_fetch_named (const EggRegex *regex,
const gchar *name,
const gchar *string);
gboolean egg_regex_fetch_named_pos (const EggRegex *regex,
const gchar *name,
gint *start_pos,
gint *end_pos);
gchar **egg_regex_fetch_all (const EggRegex *regex,
const gchar *string);
gint egg_regex_get_string_number (const EggRegex *regex,
const gchar *name);
gchar **egg_regex_split_simple (const gchar *pattern,
const gchar *string,
EggRegexCompileFlags compile_options,
EggRegexMatchFlags match_options);
gchar **egg_regex_split (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gchar **egg_regex_split_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
gint max_tokens,
GError **error);
gchar *egg_regex_split_next (EggRegex *regex,
const gchar *string,
EggRegexMatchFlags match_options);
gchar *egg_regex_split_next_full (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
GError **error);
gchar *egg_regex_expand_references (EggRegex *regex,
const gchar *string,
const gchar *string_to_expand,
GError **error);
gchar *egg_regex_replace (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
const gchar *replacement,
EggRegexMatchFlags match_options,
GError **error);
gchar *egg_regex_replace_literal (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
const gchar *replacement,
EggRegexMatchFlags match_options,
GError **error);
gchar *egg_regex_replace_eval (EggRegex *regex,
const gchar *string,
gssize string_len,
gint start_position,
EggRegexMatchFlags match_options,
EggRegexEvalCallback eval,
gpointer user_data,
GError **error);
gchar *egg_regex_escape_string (const gchar *string,
gint length);
/*****************************************************************************/
/* muntyan's additions
@ -245,4 +250,4 @@ char *egg_regex_try_eval_replacement (EggRegex *regex,
G_END_DECLS
#endif /* __EGGREGEX_H__ */
#endif /* __EGG_REGEX_H__ */

View File

@ -904,7 +904,7 @@ pattern_free (Pattern p,
if (p.key)
{
if (type == MOO_PREFS_MATCH_REGEX)
egg_regex_unref (p.regex);
egg_regex_free (p.regex);
else
g_free (p.key);
}

View File

@ -870,7 +870,7 @@ _moo_glob_free (MooGlob *glob)
if (glob)
{
#ifdef MOO_GLOB_REGEX
egg_regex_unref (glob->re);
egg_regex_free (glob->re);
#else
g_free (glob->pattern);
#endif