Add GRegex for regular expression matching. (#50075)
[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 - 2006, 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.h>
26
27 G_BEGIN_DECLS
28
29 typedef enum
30 {
31   G_REGEX_ERROR_COMPILE,
32   G_REGEX_ERROR_OPTIMIZE,
33   G_REGEX_ERROR_REPLACE,
34   G_REGEX_ERROR_MATCH
35 } GRegexError;
36
37 #define G_REGEX_ERROR g_regex_error_quark ()
38
39 GQuark g_regex_error_quark (void);
40
41 /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
42  * adding a new flag. */
43 typedef enum
44 {
45   G_REGEX_CASELESS          = 1 << 0,
46   G_REGEX_MULTILINE         = 1 << 1,
47   G_REGEX_DOTALL            = 1 << 2,
48   G_REGEX_EXTENDED          = 1 << 3,
49   G_REGEX_ANCHORED          = 1 << 4,
50   G_REGEX_DOLLAR_ENDONLY    = 1 << 5,
51   G_REGEX_UNGREEDY          = 1 << 9,
52   G_REGEX_RAW               = 1 << 11,
53   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
54   G_REGEX_DUPNAMES          = 1 << 19,
55   G_REGEX_NEWLINE_CR        = 1 << 20,
56   G_REGEX_NEWLINE_LF        = 1 << 21,
57   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
58 } GRegexCompileFlags;
59
60 /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
61  * adding a new flag. */
62 typedef enum
63 {
64   G_REGEX_MATCH_ANCHORED      = 1 << 4,
65   G_REGEX_MATCH_NOTBOL        = 1 << 7,
66   G_REGEX_MATCH_NOTEOL        = 1 << 8,
67   G_REGEX_MATCH_NOTEMPTY      = 1 << 10,
68   G_REGEX_MATCH_PARTIAL       = 1 << 15,
69   G_REGEX_MATCH_NEWLINE_CR    = 1 << 20,
70   G_REGEX_MATCH_NEWLINE_LF    = 1 << 21,
71   G_REGEX_MATCH_NEWLINE_CRLF  = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
72   G_REGEX_MATCH_NEWLINE_ANY   = 1 << 22,
73 } GRegexMatchFlags;
74
75 typedef struct _GRegex  GRegex;
76
77 typedef gboolean (*GRegexEvalCallback) (const GRegex*, const gchar*, GString*, gpointer);
78
79
80 GRegex           *g_regex_new                   (const gchar         *pattern,
81                                                  GRegexCompileFlags   compile_options,
82                                                  GRegexMatchFlags     match_options,
83                                                  GError             **error);
84 void              g_regex_free                  (GRegex              *regex);
85 gboolean          g_regex_optimize              (GRegex              *regex,
86                                                  GError             **error);
87 GRegex           *g_regex_copy                  (const GRegex        *regex);
88 const gchar      *g_regex_get_pattern           (const GRegex        *regex);
89 void              g_regex_clear                 (GRegex              *regex);
90 gboolean          g_regex_match_simple          (const gchar         *pattern,
91                                                  const gchar         *string,
92                                                  GRegexCompileFlags   compile_options,
93                                                  GRegexMatchFlags     match_options);
94 gboolean          g_regex_match                 (GRegex              *regex,
95                                                  const gchar         *string,
96                                                  GRegexMatchFlags     match_options);
97 gboolean          g_regex_match_full            (GRegex              *regex,
98                                                  const gchar         *string,
99                                                  gssize               string_len,
100                                                  gint                 start_position,
101                                                  GRegexMatchFlags     match_options,
102                                                  GError             **error);
103 gboolean          g_regex_match_next            (GRegex              *regex,
104                                                  const gchar         *string,
105                                                  GRegexMatchFlags     match_options);
106 gboolean          g_regex_match_next_full       (GRegex              *regex,
107                                                  const gchar         *string,
108                                                  gssize               string_len,
109                                                  gint                 start_position,
110                                                  GRegexMatchFlags     match_options,
111                                                  GError             **error);
112 gboolean          g_regex_match_all             (GRegex              *regex,
113                                                  const gchar         *string,
114                                                  GRegexMatchFlags     match_options);
115 gboolean          g_regex_match_all_full        (GRegex              *regex,
116                                                  const gchar         *string,
117                                                  gssize               string_len,
118                                                  gint                 start_position,
119                                                  GRegexMatchFlags     match_options,
120                                                  GError             **error);
121 gint              g_regex_get_match_count       (const GRegex        *regex);
122 gboolean          g_regex_is_partial_match      (const GRegex        *regex);
123 gchar            *g_regex_fetch                 (const GRegex        *regex,
124                                                  gint                 match_num,
125                                                  const gchar         *string);
126 gboolean          g_regex_fetch_pos             (const GRegex        *regex,
127                                                  gint                 match_num,
128                                                  gint                *start_pos,
129                                                  gint                *end_pos);
130 gchar            *g_regex_fetch_named           (const GRegex        *regex,
131                                                  const gchar         *name,
132                                                  const gchar         *string);
133 gboolean          g_regex_fetch_named_pos       (const GRegex        *regex,
134                                                  const gchar         *name,
135                                                  gint                *start_pos,
136                                                  gint                *end_pos);
137 gchar           **g_regex_fetch_all             (const GRegex        *regex,
138                                                  const gchar         *string);
139 gint              g_regex_get_string_number     (const GRegex        *regex, 
140                                                  const gchar         *name);
141 gchar           **g_regex_split_simple          (const gchar         *pattern,
142                                                  const gchar         *string,
143                                                  GRegexCompileFlags   compile_options,
144                                                  GRegexMatchFlags     match_options);
145 gchar           **g_regex_split                 (GRegex              *regex,
146                                                  const gchar         *string,
147                                                  GRegexMatchFlags     match_options);
148 gchar           **g_regex_split_full            (GRegex              *regex,
149                                                  const gchar         *string,
150                                                  gssize               string_len,
151                                                  gint                 start_position,
152                                                  GRegexMatchFlags     match_options,
153                                                  gint                 max_tokens,
154                                                  GError             **error);
155 gchar            *g_regex_split_next            (GRegex              *regex,
156                                                  const gchar         *string,
157                                                  GRegexMatchFlags     match_options);
158 gchar            *g_regex_split_next_full       (GRegex              *regex,
159                                                  const gchar         *string,
160                                                  gssize               string_len,
161                                                  gint                 start_position,
162                                                  GRegexMatchFlags     match_options,
163                                                  GError             **error);
164 gchar            *g_regex_expand_references     (GRegex              *regex,
165                                                  const gchar         *string,
166                                                  const gchar         *string_to_expand,
167                                                  GError             **error);
168 gchar            *g_regex_replace               (GRegex              *regex,
169                                                  const gchar         *string,
170                                                  gssize               string_len,
171                                                  gint                 start_position,
172                                                  const gchar         *replacement,
173                                                  GRegexMatchFlags     match_options,
174                                                  GError             **error);
175 gchar            *g_regex_replace_literal       (GRegex              *regex,
176                                                  const gchar         *string,
177                                                  gssize               string_len,
178                                                  gint                 start_position,
179                                                  const gchar         *replacement,
180                                                  GRegexMatchFlags     match_options,
181                                                  GError             **error);
182 gchar            *g_regex_replace_eval          (GRegex              *regex,
183                                                  const gchar         *string,
184                                                  gssize               string_len,
185                                                  gint                 start_position,
186                                                  GRegexMatchFlags     match_options,
187                                                  GRegexEvalCallback   eval,
188                                                  gpointer             user_data,
189                                                  GError             **error);
190 gchar            *g_regex_escape_string         (const gchar         *string,
191                                                  gint                 length);
192
193
194 G_END_DECLS
195
196
197 #endif  /*  __G_REGEX_H__ */