migrate per-thread magazine caches from single-thread scenario to first
[platform/upstream/glib.git] / glib / gregex.h
1 /* GRegex -- regular expression API wrapper around PCRE.
2  *
3  * Copyright (C) 1999, 2000 Scott Wimer
4  * Copyright (C) 2004, Matthias Clasen <mclasen@redhat.com>
5  * Copyright (C) 2005 - 2007, Marco Barisione <marco@barisione.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #ifndef __G_REGEX_H__
23 #define __G_REGEX_H__
24
25 #include <glib/gerror.h>
26 #include <glib/gstring.h>
27
28 G_BEGIN_DECLS
29
30 typedef enum
31 {
32   G_REGEX_ERROR_COMPILE,
33   G_REGEX_ERROR_OPTIMIZE,
34   G_REGEX_ERROR_REPLACE,
35   G_REGEX_ERROR_MATCH
36 } GRegexError;
37
38 #define G_REGEX_ERROR g_regex_error_quark ()
39
40 GQuark g_regex_error_quark (void);
41
42 /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
43  * adding a new flag. */
44 typedef enum
45 {
46   G_REGEX_CASELESS          = 1 << 0,
47   G_REGEX_MULTILINE         = 1 << 1,
48   G_REGEX_DOTALL            = 1 << 2,
49   G_REGEX_EXTENDED          = 1 << 3,
50   G_REGEX_ANCHORED          = 1 << 4,
51   G_REGEX_DOLLAR_ENDONLY    = 1 << 5,
52   G_REGEX_UNGREEDY          = 1 << 9,
53   G_REGEX_RAW               = 1 << 11,
54   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
55   G_REGEX_OPTIMIZE          = 1 << 13,
56   G_REGEX_DUPNAMES          = 1 << 19,
57   G_REGEX_NEWLINE_CR        = 1 << 20,
58   G_REGEX_NEWLINE_LF        = 1 << 21,
59   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
60 } GRegexCompileFlags;
61
62 /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
63  * adding a new flag. */
64 typedef enum
65 {
66   G_REGEX_MATCH_ANCHORED      = 1 << 4,
67   G_REGEX_MATCH_NOTBOL        = 1 << 7,
68   G_REGEX_MATCH_NOTEOL        = 1 << 8,
69   G_REGEX_MATCH_NOTEMPTY      = 1 << 10,
70   G_REGEX_MATCH_PARTIAL       = 1 << 15,
71   G_REGEX_MATCH_NEWLINE_CR    = 1 << 20,
72   G_REGEX_MATCH_NEWLINE_LF    = 1 << 21,
73   G_REGEX_MATCH_NEWLINE_CRLF  = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
74   G_REGEX_MATCH_NEWLINE_ANY   = 1 << 22
75 } GRegexMatchFlags;
76
77 typedef struct _GRegex          GRegex;
78 typedef struct _GMatchInfo      GMatchInfo;
79
80 typedef gboolean (*GRegexEvalCallback)          (const GMatchInfo *match_info,
81                                                  GString          *result,
82                                                  gpointer          user_data);
83
84
85 GRegex           *g_regex_new                   (const gchar         *pattern,
86                                                  GRegexCompileFlags   compile_options,
87                                                  GRegexMatchFlags     match_options,
88                                                  GError             **error);
89 GRegex           *g_regex_ref                   (GRegex              *regex);
90 void              g_regex_unref                 (GRegex              *regex);
91 const gchar      *g_regex_get_pattern           (const GRegex        *regex);
92 gint              g_regex_get_max_backref       (const GRegex        *regex);
93 gint              g_regex_get_capture_count     (const GRegex        *regex);
94 gint              g_regex_get_string_number     (const GRegex        *regex, 
95                                                  const gchar         *name);
96 gchar            *g_regex_escape_string         (const gchar         *string,
97                                                  gint                 length);
98
99 /* Matching. */
100 gboolean          g_regex_match_simple          (const gchar         *pattern,
101                                                  const gchar         *string,
102                                                  GRegexCompileFlags   compile_options,
103                                                  GRegexMatchFlags     match_options);
104 gboolean          g_regex_match                 (const GRegex        *regex,
105                                                  const gchar         *string,
106                                                  GRegexMatchFlags     match_options,
107                                                  GMatchInfo         **match_info);
108 gboolean          g_regex_match_full            (const GRegex        *regex,
109                                                  const gchar         *string,
110                                                  gssize               string_len,
111                                                  gint                 start_position,
112                                                  GRegexMatchFlags     match_options,
113                                                  GMatchInfo         **match_info,
114                                                  GError             **error);
115 gboolean          g_regex_match_all             (const GRegex        *regex,
116                                                  const gchar         *string,
117                                                  GRegexMatchFlags     match_options,
118                                                  GMatchInfo         **match_info);
119 gboolean          g_regex_match_all_full        (const GRegex        *regex,
120                                                  const gchar         *string,
121                                                  gssize               string_len,
122                                                  gint                 start_position,
123                                                  GRegexMatchFlags     match_options,
124                                                  GMatchInfo         **match_info,
125                                                  GError             **error);
126
127 /* String splitting. */
128 gchar           **g_regex_split_simple          (const gchar         *pattern,
129                                                  const gchar         *string,
130                                                  GRegexCompileFlags   compile_options,
131                                                  GRegexMatchFlags     match_options);
132 gchar           **g_regex_split                 (const GRegex        *regex,
133                                                  const gchar         *string,
134                                                  GRegexMatchFlags     match_options);
135 gchar           **g_regex_split_full            (const GRegex        *regex,
136                                                  const gchar         *string,
137                                                  gssize               string_len,
138                                                  gint                 start_position,
139                                                  GRegexMatchFlags     match_options,
140                                                  gint                 max_tokens,
141                                                  GError             **error);
142
143 /* String replacement. */
144 gchar            *g_regex_replace               (const GRegex        *regex,
145                                                  const gchar         *string,
146                                                  gssize               string_len,
147                                                  gint                 start_position,
148                                                  const gchar         *replacement,
149                                                  GRegexMatchFlags     match_options,
150                                                  GError             **error);
151 gchar            *g_regex_replace_literal       (const GRegex        *regex,
152                                                  const gchar         *string,
153                                                  gssize               string_len,
154                                                  gint                 start_position,
155                                                  const gchar         *replacement,
156                                                  GRegexMatchFlags     match_options,
157                                                  GError             **error);
158 gchar            *g_regex_replace_eval          (const GRegex        *regex,
159                                                  const gchar         *string,
160                                                  gssize               string_len,
161                                                  gint                 start_position,
162                                                  GRegexMatchFlags     match_options,
163                                                  GRegexEvalCallback   eval,
164                                                  gpointer             user_data,
165                                                  GError             **error);
166 gboolean          g_regex_check_replacement     (const gchar         *replacement,
167                                                  gboolean            *has_references,
168                                                  GError             **error);
169
170 /* Match info */
171 GRegex           *g_match_info_get_regex        (const GMatchInfo    *match_info);
172 const gchar      *g_match_info_get_string       (const GMatchInfo    *match_info);
173
174 void              g_match_info_free             (GMatchInfo          *match_info);
175 gboolean          g_match_info_next             (GMatchInfo          *match_info,
176                                                  GError             **error);
177 gboolean          g_match_info_matches          (const GMatchInfo    *match_info);
178 gint              g_match_info_get_match_count  (const GMatchInfo    *match_info);
179 gboolean          g_match_info_is_partial_match (const GMatchInfo    *match_info);
180 gchar            *g_match_info_expand_references(const GMatchInfo    *match_info,
181                                                  const gchar         *string_to_expand,
182                                                  GError             **error);
183 gchar            *g_match_info_fetch            (const GMatchInfo    *match_info,
184                                                  gint                 match_num);
185 gboolean          g_match_info_fetch_pos        (const GMatchInfo    *match_info,
186                                                  gint                 match_num,
187                                                  gint                *start_pos,
188                                                  gint                *end_pos);
189 gchar            *g_match_info_fetch_named      (const GMatchInfo    *match_info,
190                                                  const gchar         *name);
191 gboolean          g_match_info_fetch_named_pos  (const GMatchInfo    *match_info,
192                                                  const gchar         *name,
193                                                  gint                *start_pos,
194                                                  gint                *end_pos);
195 gchar           **g_match_info_fetch_all        (const GMatchInfo    *match_info);
196
197 G_END_DECLS
198
199
200 #endif  /*  __G_REGEX_H__ */