glib regular expession api



Last night I've dusted off an old patch which adds regular expression
support based on PCRE to glib. Here is the api which I currently have.
Does this look reasonable ? The full patch is attached to bug 50075.

Matthias


 typedef enum
{
  GREGEX_CASELESS          = 1 << 0,
  GREGEX_MULTILINE         = 1 << 1,
  GREGEX_DOTALL            = 1 << 2,
  GREGEX_EXTENDED          = 1 << 3,
  GREGEX_ANCHORED          = 1 << 4,
  GREGEX_DOLLAR_ENDONLY    = 1 << 5,
  GREGEX_UNGREEDY          = 1 << 9,
  GREGEX_NO_AUTO_CAPTURE   = 1 << 12
} GRegexCompileFlags;

typedef enum
{
  GREGEX_MATCH_ANCHORED    = 1 << 4,
  GREGEX_MATCH_NOTBOL      = 1 << 7,
  GREGEX_MATCH_NOTEOL      = 1 << 8,
  GREGEX_MATCH_NOTEMPTY    = 1 << 10
} GRegexMatchFlags;

typedef struct _GRegex  GRegex;

struct _GRegex 
{
  gchar *pattern;  /* the regular expression */
  gint   match;    /* boolean flag, 1 if a match was made, 0 if not */
  gint   matches;  /* number of matching sub patterns */
  gint   pos;      /* position in the string where last match left off
*/
};

typedef gchar * (*GRegexEvalCallback) (gchar *, gpointer);

/* Really quick outline of features... functions are preceded by
'g_regex_'
 *   new         - compile a pattern and put it in a g_regex structure
 *   free        - free up the memory used by the g_regex structure
 *   clear       - clear out the structure to match against a new string
 *   optimize    - study the pattern to make matching more efficient
 *   match       - try matching a pattern in the string
 *   match_next  - try matching pattern again in the string
 *   fetch       - fetch a particular matching sub pattern
 *   fetch_all   - get all of the matching sub patterns
 *   split       - split the string on a regex
 *   split_next  - for using split as an iterator of sorts
 *   replace     - replace occurances of a pattern with some text
 */

GRegex  *g_regex_new                   (const gchar         *pattern,
	 			        GRegexCompileFlags   compile_options,
				        GRegexMatchFlags     match_options,
					GError             **error);
void     g_regex_optimize              (GRegex              *regex,
					GError             **error);
void     g_regex_free                  (GRegex              *regex);
void     g_regex_clear                 (GRegex              *regex);

gint     g_regex_match                 (GRegex              *regex,
		 		        const gchar         *string,
				        gssize               string_len,
				        GRegexMatchFlags     match_options);
gint     g_regex_match_next            (GRegex              *regex,
				        const gchar         *string,
				        gssize               string_len,
				        GRegexMatchFlags     match_options);
gchar   *g_regex_fetch                 (GRegex              *regex,
				        const gchar         *string,
				        gint                 match_num);
gchar  **g_regex_fetch_all             (GRegex              *regex,
				        const gchar         *string);

gchar  **g_regex_split                 (GRegex              *regex,
				        const gchar         *string,
				        gssize               string_len,
				        GRegexMatchFlags     match_options,
				        gint                 max_pieces);
gchar   *g_regex_split_next            (GRegex              *regex,
				        const gchar         *string,
				        gssize               string_len,
				        GRegexMatchFlags     match_options);

gchar   *g_regex_replace               (GRegex              *regex,
				        const gchar         *string,
				        gssize               string_len,
				        const gchar         *replacement,
				        GRegexMatchFlags     match_options);
gchar   *g_regex_replace_eval          (GRegex              *regex,
				        const gchar         *string,
				        gssize               string_len,
				        GRegexEvalCallback   eval,
				        gpointer             user_data,
				        GRegexMatchFlags     match_options);






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