glib2 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,4 +59,7 @@
59
59
 
60
60
  #define RVAL2GBINDINGFLAGS(o) (RVAL2GFLAGS(o, G_TYPE_BINDING_FLAGS))
61
61
  #define GBINDINGFLAGS2RVAL(o) (GFLAGS2RVAL(o, G_TYPE_BINDING_FLAGS))
62
+ #define RVAL2GREGEXMATCHOPTIONSFLAGS(o) (RVAL2GFLAGS(o, G_TYPE_REGEX_MATCH_FLAGS))
63
+ #define RVAL2GREGEXCOMPILEOPTIONSFLAGS(o) (RVAL2GFLAGS(o, G_TYPE_REGEX_COMPILE_FLAGS))
64
+ #define GMATCHINFO2RVAL(o) (BOXED2RVAL(o, G_TYPE_MATCH_INFO))
62
65
  #endif /* __GLIB2CONVERSIONS_H__ */
@@ -52,7 +52,6 @@ rg_initialize(gint argc, VALUE *argv, VALUE self)
52
52
  VALUE arg1, arg2;
53
53
 
54
54
  GIOChannel* io = NULL;
55
- rb_secure(4);
56
55
  rb_scan_args(argc, argv, "11", &arg1, &arg2);
57
56
 
58
57
  if (TYPE(arg1) != T_STRING){
@@ -406,7 +405,6 @@ rg_write(VALUE self, VALUE buf)
406
405
  GIOStatus status;
407
406
  GError* err = NULL;
408
407
 
409
- rb_secure(4);
410
408
  buf = rb_obj_as_string(buf);
411
409
 
412
410
  StringValue(buf);
@@ -426,7 +424,6 @@ rg_putc(VALUE self, VALUE thechar)
426
424
  GIOStatus status;
427
425
  gunichar unichar;
428
426
 
429
- rb_secure(4);
430
427
  if (TYPE(thechar) == T_FIXNUM) {
431
428
  unichar = NUM2UINT(thechar);
432
429
  } else {
@@ -31,7 +31,6 @@ rg_initialize(VALUE self, VALUE socket)
31
31
  GIOChannel *io = NULL;
32
32
  int fd;
33
33
 
34
- rb_secure(4);
35
34
  /* TODO: support IO object */
36
35
  fd = NUM2INT(socket);
37
36
  io = g_io_channel_win32_new_socket(rb_w32_get_osfhandle(fd));
@@ -0,0 +1,179 @@
1
+ /*
2
+ * Copyright (C) 2015-2016 Ruby-GNOME2 Project Team
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * This library is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with this library; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
+ * MA 02110-1301 USA
18
+ */
19
+
20
+ #include "rbgprivate.h"
21
+
22
+ #define RG_TARGET_NAMESPACE cMatchInfo
23
+ #define _SELF(s) ((GMatchInfo*)RVAL2BOXED(s, G_TYPE_MATCH_INFO))
24
+
25
+ static VALUE
26
+ rg_regex(VALUE self)
27
+ {
28
+ GRegex *regex;
29
+ regex = g_match_info_get_regex(_SELF(self));
30
+ return BOXED2RVAL(regex, G_TYPE_REGEX);
31
+ }
32
+
33
+ static VALUE
34
+ rg_string(VALUE self)
35
+ {
36
+ return rb_iv_get(self, "@string");
37
+ }
38
+
39
+ static VALUE
40
+ rg_matches_p(VALUE self)
41
+ {
42
+ return CBOOL2RVAL(g_match_info_matches(_SELF(self)));
43
+ }
44
+
45
+ static VALUE
46
+ rg_match_count(VALUE self)
47
+ {
48
+ return INT2NUM(g_match_info_get_match_count(_SELF(self)));
49
+ }
50
+
51
+ static VALUE
52
+ rg_partial_match_p(VALUE self)
53
+ {
54
+ return CBOOL2RVAL(g_match_info_is_partial_match(_SELF(self)));
55
+ }
56
+
57
+ static VALUE
58
+ rg_fetch(VALUE self, VALUE rb_match_reference)
59
+ {
60
+ gchar *match;
61
+
62
+ switch (TYPE(rb_match_reference)) {
63
+ case RUBY_T_FIXNUM:
64
+ {
65
+ gint match_num;
66
+ match_num = NUM2INT(rb_match_reference);
67
+ match = g_match_info_fetch(_SELF(self), match_num);
68
+ }
69
+ break;
70
+ case RUBY_T_STRING:
71
+ case RUBY_T_SYMBOL:
72
+ {
73
+ const gchar *match_name;
74
+ match_name = RVAL2CSTR_ACCEPT_SYMBOL(rb_match_reference);
75
+ match = g_match_info_fetch_named(_SELF(self), match_name);
76
+ }
77
+ break;
78
+ default:
79
+ rb_raise(rb_eArgError, "Expected a String, a Symbol or an Integer");
80
+ break;
81
+ }
82
+
83
+ return CSTR2RVAL_FREE(match);
84
+ }
85
+
86
+ static VALUE
87
+ rg_fetch_pos(VALUE self, VALUE rb_match_reference)
88
+ {
89
+ gint start_pos = 0;
90
+ gint end_pos = 0;
91
+ gboolean fetched = FALSE;
92
+
93
+ switch (TYPE(rb_match_reference)) {
94
+ case RUBY_T_FIXNUM:
95
+ {
96
+ gint match_num;
97
+ match_num = NUM2INT(rb_match_reference);
98
+ fetched = g_match_info_fetch_pos(_SELF(self), match_num,
99
+ &start_pos, &end_pos);
100
+ }
101
+ break;
102
+ case RUBY_T_STRING:
103
+ case RUBY_T_SYMBOL:
104
+ {
105
+ const gchar *match_name;
106
+ match_name = RVAL2CSTR_ACCEPT_SYMBOL(rb_match_reference);
107
+ fetched = g_match_info_fetch_named_pos(_SELF(self), match_name,
108
+ &start_pos, &end_pos);
109
+ }
110
+ break;
111
+ default:
112
+ rb_raise(rb_eArgError, "Expected a String, a Symbol or an Integer");
113
+ break;
114
+ }
115
+
116
+ if (!fetched) {
117
+ return Qnil;
118
+ }
119
+
120
+ return rb_ary_new_from_args(2, INT2NUM(start_pos), INT2NUM(end_pos));
121
+ }
122
+
123
+ static VALUE
124
+ rg_fetch_all(VALUE self)
125
+ {
126
+ gchar **strings;
127
+ strings = g_match_info_fetch_all(_SELF(self));
128
+ return STRV2RVAL_FREE(strings);
129
+ }
130
+
131
+ static VALUE
132
+ rg_next(VALUE self)
133
+ {
134
+ gboolean matched;
135
+ GError *error = NULL;
136
+
137
+ matched = g_match_info_next(_SELF(self), &error);
138
+
139
+ if (error)
140
+ RAISE_GERROR(error);
141
+
142
+ return CBOOL2RVAL(matched);
143
+ }
144
+
145
+ static VALUE
146
+ rg_expand_references(VALUE self, VALUE rb_string)
147
+ {
148
+ const gchar *string = RVAL2CSTR(rb_string);
149
+ gchar *expanded_string = NULL;
150
+ GError *error = NULL;
151
+
152
+ expanded_string = g_match_info_expand_references(_SELF(self),
153
+ string,
154
+ &error);
155
+ if (error)
156
+ RAISE_GERROR(error);
157
+
158
+ return CSTR2RVAL_FREE(expanded_string);
159
+ }
160
+
161
+ void
162
+ Init_glib_matchinfo(void)
163
+ {
164
+ VALUE RG_TARGET_NAMESPACE;
165
+
166
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MATCH_INFO, "MatchInfo", mGLib);
167
+ RG_DEF_METHOD(regex, 0);
168
+ RG_DEF_METHOD(string, 0);
169
+ RG_DEF_METHOD_P(matches, 0);
170
+ RG_DEF_METHOD(match_count, 0);
171
+ RG_DEF_METHOD_P(partial_match, 0);
172
+ RG_DEF_METHOD(fetch, 1);
173
+ RG_DEF_ALIAS("[]", "fetch");
174
+ RG_DEF_METHOD(fetch_pos, 1);
175
+ RG_DEF_ALIAS("fetch_position", "fetch_pos");
176
+ RG_DEF_METHOD(fetch_all, 0);
177
+ RG_DEF_METHOD(next, 0);
178
+ RG_DEF_METHOD(expand_references, 1);
179
+ }
@@ -0,0 +1,484 @@
1
+ /*
2
+ * Copyright (C) 2015-2016 Ruby-GNOME2 Project Team
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * This library is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with this library; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
+ * MA 02110-1301 USA
18
+ */
19
+
20
+ #include "rbgprivate.h"
21
+
22
+ /* They MRI are internal definitions. Using them reduces
23
+ * maintainability. We should reconsider about using them when they
24
+ * are changed in MRI. */
25
+ /* from vm_core.h */
26
+ #define RUBY_TAG_BREAK 0x2
27
+
28
+ /* from internal.h */
29
+ struct vm_throw_data {
30
+ VALUE flags;
31
+ VALUE reserved;
32
+ const VALUE throw_obj;
33
+ /* const struct rb_control_frame_struct *catch_frame; */
34
+ /* VALUE throw_state; */
35
+ };
36
+ /* from vm_insnhelper.h */
37
+ #define THROW_DATA_VAL(obj) (((struct vm_throw_data *)(obj))->throw_obj)
38
+
39
+
40
+ #define RG_TARGET_NAMESPACE cRegex
41
+ #define _SELF(s) ((GRegex*)RVAL2BOXED(s, G_TYPE_REGEX))
42
+
43
+ static VALUE
44
+ rg_initialize(gint argc, VALUE *argv, VALUE self)
45
+ {
46
+ GError *error = NULL;
47
+ GRegex *regex = NULL;
48
+
49
+ VALUE rb_pattern, rb_compile_options, rb_match_options;
50
+ VALUE rb_options;
51
+ const char *pattern;
52
+ GRegexCompileFlags compile_options = 0;
53
+ GRegexMatchFlags match_options = 0;
54
+
55
+ rb_scan_args(argc, argv, "11", &rb_pattern, &rb_options);
56
+ rbg_scan_options(rb_options,
57
+ "compile_options", &rb_compile_options,
58
+ "match_options", &rb_match_options,
59
+ NULL);
60
+
61
+ pattern = RVAL2CSTR(rb_pattern);
62
+ if (!NIL_P(rb_compile_options))
63
+ compile_options = RVAL2GREGEXCOMPILEOPTIONSFLAGS(rb_compile_options);
64
+ if (!NIL_P(rb_match_options))
65
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
66
+
67
+ regex = g_regex_new(pattern,
68
+ compile_options,
69
+ match_options,
70
+ &error);
71
+ if (error)
72
+ RAISE_GERROR(error);
73
+
74
+ G_INITIALIZE(self, regex);
75
+ return Qnil;
76
+ }
77
+
78
+ static VALUE
79
+ rg_pattern(VALUE self)
80
+ {
81
+ return CSTR2RVAL(g_regex_get_pattern(_SELF(self)));
82
+ }
83
+
84
+ static VALUE
85
+ rg_compile_flags(VALUE self)
86
+ {
87
+ return UINT2NUM(g_regex_get_compile_flags(_SELF(self)));
88
+ }
89
+
90
+ static VALUE
91
+ rg_match_flags(VALUE self)
92
+ {
93
+ return UINT2NUM(g_regex_get_match_flags(_SELF(self)));
94
+ }
95
+
96
+ static VALUE
97
+ rg_split(gint argc, VALUE *argv, VALUE self)
98
+ {
99
+ VALUE rb_string, rb_start_position, rb_match_options, rb_max_tokens, rb_options;
100
+ GError *error = NULL;
101
+ gchar **strings;
102
+ const gchar *string;
103
+ gssize string_len = -1;
104
+ gint start_position = 0;
105
+ GRegexMatchFlags match_options = 0;
106
+ gint max_tokens = 0;
107
+
108
+ rb_scan_args(argc, argv, "11", &rb_string, &rb_options);
109
+
110
+ rbg_scan_options(rb_options,
111
+ "start_position", &rb_start_position,
112
+ "match_options", &rb_match_options,
113
+ "max_tokens", &rb_max_tokens,
114
+ NULL);
115
+ string = RVAL2CSTR(rb_string);
116
+ string_len = RSTRING_LEN(rb_string);
117
+
118
+ if (!NIL_P(rb_start_position))
119
+ start_position = NUM2INT(rb_start_position);
120
+ if (!NIL_P(rb_match_options))
121
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
122
+ if (!NIL_P(rb_max_tokens))
123
+ max_tokens = NUM2INT(rb_max_tokens);
124
+
125
+ strings = g_regex_split_full(_SELF(self),
126
+ string,
127
+ string_len,
128
+ start_position,
129
+ match_options,
130
+ max_tokens,
131
+ &error);
132
+
133
+ if (error)
134
+ RAISE_GERROR(error);
135
+
136
+ return STRV2RVAL_FREE(strings);
137
+ }
138
+
139
+ static VALUE
140
+ rg_match(gint argc, VALUE *argv, VALUE self)
141
+ {
142
+ VALUE rb_string, rb_start_position, rb_match_options, rb_options;
143
+ VALUE rb_frozen_string, rb_match_info;
144
+ GMatchInfo *match_info = NULL;
145
+ GError *error = NULL;
146
+ const gchar *string;
147
+ gssize string_len = -1;
148
+ gint start_position = 0;
149
+ GRegexMatchFlags match_options = 0;
150
+
151
+ rb_scan_args(argc, argv, "11", &rb_string, &rb_options);
152
+
153
+ rbg_scan_options(rb_options,
154
+ "start_position", &rb_start_position,
155
+ "match_options", &rb_match_options,
156
+ NULL);
157
+
158
+ if (OBJ_FROZEN(rb_string)) {
159
+ rb_frozen_string = rb_string;
160
+ } else {
161
+ rb_frozen_string = rb_str_dup(rb_string);
162
+ rb_str_freeze(rb_frozen_string);
163
+ }
164
+
165
+ string = RVAL2CSTR(rb_frozen_string);
166
+ string_len = RSTRING_LEN(rb_frozen_string);
167
+
168
+
169
+ if (!NIL_P(rb_start_position))
170
+ start_position = NUM2INT(rb_start_position);
171
+ if (!NIL_P(rb_match_options))
172
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
173
+
174
+ g_regex_match_full(_SELF(self),
175
+ string,
176
+ string_len,
177
+ start_position,
178
+ match_options,
179
+ &match_info,
180
+ &error);
181
+
182
+ if (error)
183
+ RAISE_GERROR(error);
184
+
185
+ if (!match_info)
186
+ return Qnil;
187
+
188
+ rb_match_info = GMATCHINFO2RVAL(match_info);
189
+ g_match_info_unref(match_info);
190
+ rb_iv_set(rb_match_info, "@string", rb_frozen_string);
191
+ return rb_match_info;
192
+ }
193
+
194
+ static VALUE
195
+ rg_max_backref(VALUE self)
196
+ {
197
+ return INT2NUM(g_regex_get_max_backref(_SELF(self)));
198
+ }
199
+
200
+ static VALUE
201
+ rg_capture_count(VALUE self)
202
+ {
203
+ return INT2NUM(g_regex_get_capture_count(_SELF(self)));
204
+ }
205
+
206
+ static VALUE
207
+ rg_has_cr_or_lf_p(VALUE self)
208
+ {
209
+ return CBOOL2RVAL(g_regex_get_has_cr_or_lf(_SELF(self)));
210
+ }
211
+
212
+ static VALUE
213
+ rg_max_lookbehind(VALUE self)
214
+ {
215
+ return INT2NUM(g_regex_get_max_lookbehind(_SELF(self)));
216
+ }
217
+
218
+ static VALUE
219
+ rg_string_number(VALUE self, VALUE string)
220
+ {
221
+ return INT2NUM(g_regex_get_string_number(_SELF(self), RVAL2CSTR(string)));
222
+ }
223
+
224
+ static VALUE
225
+ rg_match_all(gint argc, VALUE *argv, VALUE self)
226
+ {
227
+ VALUE rb_string, rb_start_position, rb_match_options, rb_options;
228
+ VALUE rb_frozen_string, rb_match_info;
229
+ GMatchInfo *match_info = NULL;
230
+ GError *error = NULL;
231
+ const gchar *string;
232
+ gssize string_len = -1;
233
+ gint start_position = 0;
234
+ GRegexMatchFlags match_options = 0;
235
+
236
+ rb_scan_args(argc, argv, "11", &rb_string, &rb_options);
237
+
238
+ rbg_scan_options(rb_options,
239
+ "start_position", &rb_start_position,
240
+ "match_options", &rb_match_options,
241
+ NULL);
242
+
243
+ if (OBJ_FROZEN(rb_string)) {
244
+ rb_frozen_string = rb_string;
245
+ } else {
246
+ rb_frozen_string = rb_str_dup(rb_string);
247
+ rb_str_freeze(rb_frozen_string);
248
+ }
249
+
250
+ string = RVAL2CSTR(rb_frozen_string);
251
+ string_len = RSTRING_LEN(rb_frozen_string);
252
+
253
+
254
+ if (!NIL_P(rb_start_position))
255
+ start_position = NUM2INT(rb_start_position);
256
+ if (!NIL_P(rb_match_options))
257
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
258
+
259
+ g_regex_match_all_full(_SELF(self),
260
+ string,
261
+ string_len,
262
+ start_position,
263
+ match_options,
264
+ &match_info,
265
+ &error);
266
+
267
+ if (error)
268
+ RAISE_GERROR(error);
269
+
270
+ if (!match_info)
271
+ return Qnil;
272
+
273
+ rb_match_info = GMATCHINFO2RVAL(match_info);
274
+ g_match_info_unref(match_info);
275
+ rb_iv_set(rb_match_info, "@string", rb_frozen_string);
276
+ return rb_match_info;
277
+ }
278
+
279
+ typedef struct {
280
+ VALUE callback;
281
+ const GMatchInfo *match_info;
282
+ int status;
283
+ } RGRegexEvalCallbackData;
284
+
285
+ static VALUE
286
+ rg_regex_eval_callback_body(VALUE user_data)
287
+ {
288
+ RGRegexEvalCallbackData *data = (RGRegexEvalCallbackData *)user_data;
289
+ VALUE rb_match_info;
290
+
291
+ rb_match_info = BOXED2RVAL((GMatchInfo *)(data->match_info),
292
+ G_TYPE_MATCH_INFO);
293
+
294
+ return rb_funcall(data->callback, rb_intern("call"), 1, rb_match_info);
295
+ }
296
+
297
+ static gboolean
298
+ rg_regex_eval_callback(const GMatchInfo *match_info,
299
+ GString *result,
300
+ gpointer user_data)
301
+ {
302
+ VALUE returned_data;
303
+ RGRegexEvalCallbackData *data = user_data;
304
+
305
+ data->match_info = match_info;
306
+ returned_data = rb_protect(rg_regex_eval_callback_body,
307
+ (VALUE)data,
308
+ &(data->status));
309
+
310
+ if (data->status == RUBY_TAG_BREAK) {
311
+ returned_data = THROW_DATA_VAL(rb_errinfo());
312
+ }
313
+
314
+ if (NIL_P(returned_data)) {
315
+ gchar *matched;
316
+ matched = g_match_info_fetch(match_info, 0);
317
+ g_string_append(result, matched);
318
+ g_free(matched);
319
+ } else {
320
+ g_string_append(result, RVAL2CSTR(returned_data));
321
+ }
322
+
323
+ return data->status != 0;
324
+ }
325
+
326
+ static VALUE
327
+ rg_replace(gint argc, VALUE *argv, VALUE self)
328
+ {
329
+ VALUE rb_string;
330
+ VALUE rb_replacement;
331
+ VALUE rb_options;
332
+ VALUE rb_start_position;
333
+ VALUE rb_match_options;
334
+ VALUE rb_literal;
335
+ GError *error = NULL;
336
+ gchar *modified_string;
337
+ const gchar *string;
338
+ const gchar *replacement;
339
+ gssize string_len = -1;
340
+ gint start_position = 0;
341
+ GRegexMatchFlags match_options = 0;
342
+
343
+
344
+ if (rb_block_given_p()) {
345
+ RGRegexEvalCallbackData data;
346
+
347
+ rb_scan_args(argc, argv, "11", &rb_string, &rb_options);
348
+ rbg_scan_options(rb_options,
349
+ "start_position", &rb_start_position,
350
+ "match_options", &rb_match_options,
351
+ NULL);
352
+
353
+ string = RVAL2CSTR(rb_string);
354
+ string_len = RSTRING_LEN(rb_string);
355
+
356
+ if (!NIL_P(rb_start_position))
357
+ start_position = NUM2INT(rb_start_position);
358
+ if (!NIL_P(rb_match_options))
359
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
360
+
361
+ data.callback = rb_block_proc();
362
+ data.status = 0;
363
+
364
+ modified_string = g_regex_replace_eval(_SELF(self),
365
+ string,
366
+ string_len,
367
+ start_position,
368
+ match_options,
369
+ rg_regex_eval_callback,
370
+ &data,
371
+ &error);
372
+ if (!(data.status == 0 || data.status == RUBY_TAG_BREAK)) {
373
+ if (error)
374
+ g_error_free(error);
375
+ g_free(modified_string);
376
+ rb_jump_tag(data.status);
377
+ }
378
+ } else {
379
+ rb_scan_args(argc, argv, "21", &rb_string, &rb_replacement, &rb_options);
380
+
381
+ rbg_scan_options(rb_options,
382
+ "start_position", &rb_start_position,
383
+ "match_options", &rb_match_options,
384
+ "literal", &rb_literal,
385
+ NULL);
386
+
387
+ string = RVAL2CSTR(rb_string);
388
+ string_len = RSTRING_LEN(rb_string);
389
+ replacement = RVAL2CSTR(rb_replacement);
390
+
391
+ if (!NIL_P(rb_start_position))
392
+ start_position = NUM2INT(rb_start_position);
393
+ if (!NIL_P(rb_match_options))
394
+ match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);
395
+
396
+ if (RVAL2CBOOL(rb_literal)) {
397
+ modified_string = g_regex_replace_literal(_SELF(self),
398
+ string,
399
+ string_len,
400
+ start_position,
401
+ replacement,
402
+ match_options,
403
+ &error);
404
+
405
+ } else {
406
+ modified_string = g_regex_replace(_SELF(self),
407
+ string,
408
+ string_len,
409
+ start_position,
410
+ replacement,
411
+ match_options,
412
+ &error);
413
+ }
414
+ }
415
+
416
+ if (error)
417
+ RAISE_GERROR(error);
418
+
419
+ return CSTR2RVAL_FREE(modified_string);
420
+ }
421
+
422
+
423
+ static VALUE
424
+ rg_s_escape_string(G_GNUC_UNUSED VALUE self, VALUE string)
425
+ {
426
+ return CSTR2RVAL(g_regex_escape_string(RVAL2CSTR(string), RSTRING_LEN(string)));
427
+ }
428
+
429
+ static VALUE
430
+ rg_s_check_replacement(G_GNUC_UNUSED VALUE self, VALUE rb_replacement)
431
+ {
432
+ const gchar *replacement;
433
+ GError *error = NULL;
434
+
435
+ replacement = RVAL2CSTR(rb_replacement);
436
+ g_regex_check_replacement(replacement, NULL, &error);
437
+ if (error)
438
+ RAISE_GERROR(error);
439
+
440
+ return Qtrue;
441
+ }
442
+
443
+ static VALUE
444
+ rg_s_have_reference_p(G_GNUC_UNUSED VALUE self, VALUE rb_replacement)
445
+ {
446
+ const gchar *replacement;
447
+ gboolean has_references;
448
+ GError *error = NULL;
449
+
450
+ replacement = RVAL2CSTR(rb_replacement);
451
+ g_regex_check_replacement(replacement, &has_references, &error);
452
+
453
+ if (error)
454
+ RAISE_GERROR(error);
455
+
456
+ return CBOOL2RVAL(has_references);
457
+ }
458
+
459
+ void
460
+ Init_glib_regex(void)
461
+ {
462
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_REGEX, "Regex", mGLib);
463
+
464
+ RG_DEF_METHOD(initialize, -1);
465
+ RG_DEF_METHOD(pattern, 0);
466
+ RG_DEF_METHOD(compile_flags, 0);
467
+ RG_DEF_METHOD(match_flags, 0);
468
+ RG_DEF_METHOD(split, -1);
469
+ RG_DEF_METHOD(match, -1);
470
+ RG_DEF_METHOD(max_backref, 0);
471
+ RG_DEF_METHOD(capture_count, 0);
472
+ RG_DEF_METHOD_P(has_cr_or_lf, 0);
473
+ RG_DEF_METHOD(max_lookbehind, 0);
474
+ RG_DEF_METHOD(string_number, 1);
475
+ RG_DEF_METHOD(match_all, -1);
476
+ RG_DEF_METHOD(replace, -1);
477
+
478
+ RG_DEF_SMETHOD(escape_string, 1);
479
+ RG_DEF_SMETHOD(check_replacement, 1);
480
+ RG_DEF_SMETHOD_P(have_reference, 1);
481
+
482
+ G_DEF_CLASS(G_TYPE_REGEX_MATCH_FLAGS, "RegexMatchFlags", mGLib);
483
+ G_DEF_CLASS(G_TYPE_REGEX_COMPILE_FLAGS, "RegexCompileFlags", mGLib);
484
+ }