/* GRegex -- regular expression API wrapper around PCRE.
 * Copyright (C) 1999 Scott Wimer
 * Copyright (C) 2004 Matthias Clasen
 *
 * This is basically an ease of user wrapper around the functionality of
 * PCRE.
 *
 * With this library, we are, hopefully, drastically reducing the code
 * complexity necessary by making use of a more complex and detailed
 * data structure to store the regex info.  I am hoping to have a regex
 * interface that is almost as easy to use as Perl's.  <fingers crossed>
 *
 * Author: Scott Wimer <scottw@cgibuilder.com>
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *
 * This library is free software, you can distribute it or modify it
 * under the following terms:
 *  1) The GNU General Public License (GPL)
 *  2) The GNU Library General Public License (LGPL)
 *  3) The Perl Artistic license (Artistic)
 *  4) The BSD license (BSD)
 *
 * In short, you can use this library in any code you desire, so long as
 * the Copyright notice above remains intact.  If you do make changes to
 * it, I would appreciate that you let me know so I can improve this 
 * library for everybody, but I'm not gonna force you to.
 * 
 * Please note that this library is just a wrapper around Philip Hazel's
 * PCRE library.  Please see the file 'LICENSE' in your PCRE distribution.
 * And, if you live in England, please send him a pint of good beer, his
 * library is great.
 *
 */
#ifndef __GREGEX_H__
#define __GREGEX_H__

#include <glib.h>
#include <stdio.h>
#include <string.h>

G_BEGIN_DECLS

typedef enum
{
  G_REGEX_ERROR_COMPILE,
  G_REGEX_ERROR_OPTIMIZE
} GRegexError;

#define G_REGEX_ERROR g_regex_error_quark ()

GQuark g_regex_error_quark (void);

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;

typedef gboolean (*GRegexEvalCallback) (GRegex*, const gchar*, GString*, 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);


G_END_DECLS


#endif  /*  __GREGEX_H__ */
