Lines Matching full:regex
21 glib/tests/regex.c | 128 ++++++++++++++++++++++++---------------------
53 GRegexMatchFlags match_opts; /* options used at match time on the regex */
55 + JITStatus jit_status; /* indicates the status of jit compiler for this compiled regex */
106 +enable_jit_with_match_options (GRegex *regex,
111 + if (!(regex->orig_compile_opts & G_REGEX_OPTIMIZE))
113 + if (regex->jit_status == JIT_STATUS_DISABLED)
116 + old_jit_options = regex->jit_options;
127 + retval = pcre2_jit_compile (regex->pcre_re, new_jit_options);
131 + regex->jit_status = JIT_STATUS_ENABLED;
132 + regex->jit_options = new_jit_options;
138 + regex->jit_status = JIT_STATUS_DISABLED;
144 + regex->jit_status = JIT_STATUS_DISABLED;
150 + regex->jit_status = JIT_STATUS_DISABLED;
161 opts = map_to_pcre2_match_flags (match_info->regex->match_opts | match_info->match_opts);
162 - match_info->matches = pcre2_match (match_info->regex->pcre_re,
170 + enable_jit_with_match_options (match_info->regex, opts);
171 + if (match_info->regex->jit_status == JIT_STATUS_ENABLED)
173 + match_info->matches = pcre2_jit_match (match_info->regex->pcre_re,
183 + match_info->matches = pcre2_match (match_info->regex->pcre_re,
195 regex->compile_opts = compile_options;
196 regex->orig_compile_opts = orig_compile_opts;
197 regex->match_opts = match_options;
198 + enable_jit_with_match_options (regex, regex->match_opts);
200 return regex;
202 @@ -1836,10 +1910,8 @@ g_regex_get_compile_flags (const GRegex *regex)
204 g_return_val_if_fail (regex != NULL, 0);
208 extra_flags = (regex->orig_compile_opts & G_REGEX_OPTIMIZE);
212 pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_NEWLINE, &info_value);
245 diff --git a/glib/tests/regex.c b/glib/tests/regex.c
247 --- a/glib/tests/regex.c
248 +++ b/glib/tests/regex.c
250 GRegex *regex;
253 - regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
254 + regex = g_regex_new (data->pattern, data->compile_opts, G_REGEX_MATCH_DEFAULT, NULL);
256 g_assert (regex != NULL);
259 g_regex_unref (regex);
272 path = g_strdup_printf ("/regex/match/partial/%d", ++total); \
286 - regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_DEFAULT, G_REGEX_MATCH_…
287 + regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_OPTIMIZE, G_REGEX_MATCH…
288 res = g_regex_match (regex, "ppPP01", 0, &match);
295 - regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_DEFAULT, G_REGEX_MATCH_…
296 + regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_OPTIMIZE, G_REGEX_MATCH…
297 res = g_regex_match (regex, "a:b:\340\254\236:\333\253:\316\240", 0, &match);
304 - regex = g_regex_new ("\\w+(?=;)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
305 + regex = g_regex_new ("\\w+(?=;)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
306 g_assert (regex);
308 res = g_regex_match (regex, "word1 word2: word3;", 0, &match);
310 g_regex_unref (regex);
313 - regex = g_regex_new ("foo(?!bar)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
314 + regex = g_regex_new ("foo(?!bar)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
315 g_assert (regex);
317 res = g_regex_match (regex, "foobar foobaz", 0, &match);
319 g_regex_unref (regex);
322 - regex = g_regex_new ("(?!bar)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
323 + regex = g_regex_new ("(?!bar)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
324 g_assert (regex);
326 res = g_regex_match (regex, "foobar foobaz", 0, &match);
331 - regex = g_regex_new ("(?<!foo)bar", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
332 + regex = g_regex_new ("(?<!foo)bar", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
333 g_assert (regex);
335 res = g_regex_match (regex, "foobar boobar", 0, &match);
337 g_regex_unref (regex);
340 - regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
341 + regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
342 g_assert (regex);
344 res = g_regex_match (regex, "don poo, and bullock poo", 0, &match);
347 g_regex_unref (regex);
349 - regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
350 + regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
351 g_assert (regex == NULL);
355 - regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
356 + regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
357 g_assert (regex == NULL);
361 - regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
362 + regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
363 g_assert (regex);
365 res = g_regex_match (regex, "abfoo, abdfoo, abcfoo", 0, &match);
368 g_regex_unref (regex);
370 - regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
371 + regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
372 g_assert (regex);
374 res = g_regex_match (regex, "abcabcabcabcabcabcabcabcabcd", 0, &match);
377 g_regex_unref (regex);
379 - regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
380 + regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
381 g_assert (regex);
383 res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
386 g_regex_unref (regex);
388 - regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error…
389 + regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &erro…
390 g_assert (regex);
392 res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
395 g_regex_unref (regex);
397 - regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
398 + regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error…
399 g_assert (regex);
401 res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
404 g_regex_unref (regex);
406 - regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
407 + regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
408 g_assert (regex);
410 res = g_regex_match (regex, "foobarbaz barfoobaz barbarbaz", 0, &match);
415 - regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
416 + regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
417 g_assert (regex);
419 g_assert_cmpint (g_regex_get_capture_count (regex), ==, 1);
422 g_regex_unref (regex);
424 - regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &…
425 + regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, …
426 g_assert (regex);
428 g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
431 g_regex_unref (regex);
433 - regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT,…
434 + regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT…
435 g_assert (regex);
437 res = g_regex_match (regex, "the white queen", 0, &match);
440 g_regex_unref (regex);
442 - regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_DEFAULT, G_REGEX_MATC…
443 + regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_OPTIMIZE, G_REGEX_MAT…
444 g_assert (regex);
446 g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
449 g_regex_unref (regex);
451 - regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
452 + regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
453 g_assert (regex);
455 g_assert_cmpint (g_regex_get_max_backref (regex), ==, 1);
458 g_regex_unref (regex);
460 - regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
461 + regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
462 g_assert (regex);
464 res = g_regex_match (regex, "abcabc abcdef defabc defdef", 0, &match);
467 g_regex_unref (regex);
469 - regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN…
470 + regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN…
471 g_assert (regex);
473 res = g_regex_match (regex, "Mon Tuesday Wed Saturday", 0, &match);
476 g_regex_unref (regex);
478 - regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
479 + regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_OPTIMIZE|G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &e…
480 g_assert (regex);
482 res = g_regex_match (regex, "aaaaaaaaaaaaaaaa", 0, &match);
487 - regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT,…
488 + regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT…
489 g_assert (regex);
491 res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
493 g_regex_unref (regex);
496 - regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MAT…
497 + regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MA…
498 g_assert (regex);
500 res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
503 g_regex_unref (regex);
505 - regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEF…
506 + regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DE…
507 g_assert (regex);
509 res = g_regex_match (regex, "a[zzzzzz]b", 0, &match);
512 regex = g_regex_new ("(?(DEFINE) (?<byte> 2[0-4]\\d | 25[0-5] | 1\\d\\d | [1-9]?\\d) )"
516 g_assert (regex);
518 res = g_regex_match (regex, "128.0.0.1", 0, &match);
521 regex = g_regex_new ("^(?(?=[^a-z]*[a-z])"
525 g_assert (regex);
527 res = g_regex_match (regex, "01-abc-24", 0, &match);
532 - regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &er…
533 + regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_M…
534 g_assert (regex);
536 res = g_regex_match (regex, "(middle)", 0, &match);
539 g_regex_unref (regex);
541 - regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAUL…
542 + regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_R…
543 g_assert (regex);
545 res = g_regex_match (regex, "((((((((((((((((middle))))))))))))))))", 0, &match);
548 g_regex_unref (regex);
550 - regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH…
551 + regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTEND…
552 g_assert (regex);
554 … g_regex_match (regex, "(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()", 0, &match);
557 g_regex_unref (regex);
559 - regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_EXTENDED, G_REGEX_MATCH…
560 + regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_OPTIMIZE|G_REGEX_EXTEND…
561 g_assert (regex);
563 res = g_regex_match (regex, "<ab<01<23<4>>>>", 0, &match);
566 g_regex_unref (regex);
568 - regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
569 + regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
570 g_assert (regex);
572 res = g_regex_match (regex, "abcdcba", 0, &match);
575 g_regex_unref (regex);
577 - regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAUL…
578 + regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAU…
579 g_assert (regex);
581 res = g_regex_match (regex, "abcdcba", 0, &match);
584 g_regex_unref (regex);
586 - regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$…
587 + regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$…
588 g_assert (regex);
590 res = g_regex_match (regex, "abcdcba", 0, &match);
592 g_test_add_func ("/regex/compile-errors", test_compile_errors);