1b5975d6bSopenharmony_ciFrom 8d5a44dc8f36cce270519bd52fcecf330ccb43b4 Mon Sep 17 00:00:00 2001
2b5975d6bSopenharmony_ciFrom: Aleksei Rybalkin <aleksei@rybalkin.org>
3b5975d6bSopenharmony_ciDate: Tue, 12 Jul 2022 11:46:34 +0000
4b5975d6bSopenharmony_ciSubject: [PATCH] replace pcre1 with pcre2
5b5975d6bSopenharmony_ci
6b5975d6bSopenharmony_ciConflict:NA
7b5975d6bSopenharmony_ciReference:https://gitlab.gnome.org/GNOME/glib/-/commit/8d5a44dc8f36cce270519bd52fcecf330ccb43b4
8b5975d6bSopenharmony_ci
9b5975d6bSopenharmony_ci---
10b5975d6bSopenharmony_ci docs/reference/glib/regex-syntax.xml |   46 --
11b5975d6bSopenharmony_ci glib/gregex.c                        | 1113 ++++++++++++++++----------
12b5975d6bSopenharmony_ci glib/gregex.h                        |   11 +-
13b5975d6bSopenharmony_ci glib/meson.build                     |   10 +-
14b5975d6bSopenharmony_ci glib/tests/meson.build               |    4 +-
15b5975d6bSopenharmony_ci glib/tests/regex.c                   |  175 ++--
16b5975d6bSopenharmony_ci meson.build                          |   41 +-
17b5975d6bSopenharmony_ci po/sk.po                             |    2 +-
18b5975d6bSopenharmony_ci subprojects/pcre.wrap                |   11 -
19b5975d6bSopenharmony_ci 9 files changed, 819 insertions(+), 594 deletions(-)
20b5975d6bSopenharmony_ci delete mode 100644 subprojects/pcre.wrap
21b5975d6bSopenharmony_ci
22b5975d6bSopenharmony_cidiff --git a/docs/reference/glib/regex-syntax.xml b/docs/reference/glib/regex-syntax.xml
23b5975d6bSopenharmony_ciindex 5dd9291..0b413aa 100644
24b5975d6bSopenharmony_ci--- a/docs/reference/glib/regex-syntax.xml
25b5975d6bSopenharmony_ci+++ b/docs/reference/glib/regex-syntax.xml
26b5975d6bSopenharmony_ci@@ -2442,52 +2442,6 @@ processing option does not affect the called subpattern.
27b5975d6bSopenharmony_ci </para>
28b5975d6bSopenharmony_ci </refsect1>
29b5975d6bSopenharmony_ci 
30b5975d6bSopenharmony_ci-<!-- Callouts are not supported by GRegex
31b5975d6bSopenharmony_ci-<refsect1>
32b5975d6bSopenharmony_ci-<title>Callouts</title>
33b5975d6bSopenharmony_ci-<para>
34b5975d6bSopenharmony_ci-Perl has a feature whereby using the sequence (?{...}) causes arbitrary
35b5975d6bSopenharmony_ci-Perl code to be obeyed in the middle of matching a regular expression.
36b5975d6bSopenharmony_ci-This makes it possible, amongst other things, to extract different substrings that match the same pair of parentheses when there is a repetition.
37b5975d6bSopenharmony_ci-</para>
38b5975d6bSopenharmony_ci-
39b5975d6bSopenharmony_ci-<para>
40b5975d6bSopenharmony_ci-PCRE provides a similar feature, but of course it cannot obey arbitrary
41b5975d6bSopenharmony_ci-Perl code. The feature is called "callout". The caller of PCRE provides
42b5975d6bSopenharmony_ci-an external function by putting its entry point in the global variable
43b5975d6bSopenharmony_ci-pcre_callout. By default, this variable contains NULL, which disables
44b5975d6bSopenharmony_ci-all calling out.
45b5975d6bSopenharmony_ci-</para>
46b5975d6bSopenharmony_ci-
47b5975d6bSopenharmony_ci-<para>
48b5975d6bSopenharmony_ci-Within a regular expression, (?C) indicates the points at which the
49b5975d6bSopenharmony_ci-external function is to be called. If you want to identify different
50b5975d6bSopenharmony_ci-callout points, you can put a number less than 256 after the letter C.
51b5975d6bSopenharmony_ci-The default value is zero. For example, this pattern has two callout
52b5975d6bSopenharmony_ci-points:
53b5975d6bSopenharmony_ci-</para>
54b5975d6bSopenharmony_ci-
55b5975d6bSopenharmony_ci-<programlisting>
56b5975d6bSopenharmony_ci-(?C1)abc(?C2)def
57b5975d6bSopenharmony_ci-</programlisting>
58b5975d6bSopenharmony_ci-
59b5975d6bSopenharmony_ci-<para>
60b5975d6bSopenharmony_ci-If the PCRE_AUTO_CALLOUT flag is passed to pcre_compile(), callouts are
61b5975d6bSopenharmony_ci-automatically installed before each item in the pattern. They are all
62b5975d6bSopenharmony_ci-numbered 255.
63b5975d6bSopenharmony_ci-</para>
64b5975d6bSopenharmony_ci-
65b5975d6bSopenharmony_ci-<para>
66b5975d6bSopenharmony_ci-During matching, when PCRE reaches a callout point (and pcre_callout is
67b5975d6bSopenharmony_ci-set), the external function is called. It is provided with the number
68b5975d6bSopenharmony_ci-of the callout, the position in the pattern, and, optionally, one item
69b5975d6bSopenharmony_ci-of data originally supplied by the caller of pcre_exec(). The callout
70b5975d6bSopenharmony_ci-function may cause matching to proceed, to backtrack, or to fail altogether. A complete description of the interface to the callout function
71b5975d6bSopenharmony_ci-is given in the pcrecallout documentation.
72b5975d6bSopenharmony_ci-</para>
73b5975d6bSopenharmony_ci-</refsect1>
74b5975d6bSopenharmony_ci--->
75b5975d6bSopenharmony_ci-
76b5975d6bSopenharmony_ci <refsect1>
77b5975d6bSopenharmony_ci <title>Copyright</title>
78b5975d6bSopenharmony_ci <para>
79b5975d6bSopenharmony_cidiff --git a/glib/gregex.c b/glib/gregex.c
80b5975d6bSopenharmony_ciindex 9a8229a..da37213 100644
81b5975d6bSopenharmony_ci--- a/glib/gregex.c
82b5975d6bSopenharmony_ci+++ b/glib/gregex.c
83b5975d6bSopenharmony_ci@@ -22,7 +22,8 @@
84b5975d6bSopenharmony_ci 
85b5975d6bSopenharmony_ci #include <string.h>
86b5975d6bSopenharmony_ci 
87b5975d6bSopenharmony_ci-#include <pcre.h>
88b5975d6bSopenharmony_ci+#define PCRE2_CODE_UNIT_WIDTH 8
89b5975d6bSopenharmony_ci+#include <pcre2.h>
90b5975d6bSopenharmony_ci 
91b5975d6bSopenharmony_ci #include "gtypes.h"
92b5975d6bSopenharmony_ci #include "gregex.h"
93b5975d6bSopenharmony_ci@@ -107,87 +108,63 @@
94b5975d6bSopenharmony_ci  * library written by Philip Hazel.
95b5975d6bSopenharmony_ci  */
96b5975d6bSopenharmony_ci 
97b5975d6bSopenharmony_ci+/* Signifies that flags have already been converted from pcre1 to pcre2. The
98b5975d6bSopenharmony_ci+ * value 0x04000000u is also the value of PCRE2_MATCH_INVALID_UTF in pcre2.h,
99b5975d6bSopenharmony_ci+ * but it is not used in gregex, so we can reuse it for this flag.
100b5975d6bSopenharmony_ci+ */
101b5975d6bSopenharmony_ci+#define G_REGEX_FLAGS_CONVERTED 0x04000000u
102b5975d6bSopenharmony_ci /* Mask of all the possible values for GRegexCompileFlags. */
103b5975d6bSopenharmony_ci-#define G_REGEX_COMPILE_MASK (G_REGEX_CASELESS          | \
104b5975d6bSopenharmony_ci-                              G_REGEX_MULTILINE         | \
105b5975d6bSopenharmony_ci-                              G_REGEX_DOTALL            | \
106b5975d6bSopenharmony_ci-                              G_REGEX_EXTENDED          | \
107b5975d6bSopenharmony_ci-                              G_REGEX_ANCHORED          | \
108b5975d6bSopenharmony_ci-                              G_REGEX_DOLLAR_ENDONLY    | \
109b5975d6bSopenharmony_ci-                              G_REGEX_UNGREEDY          | \
110b5975d6bSopenharmony_ci-                              G_REGEX_RAW               | \
111b5975d6bSopenharmony_ci-                              G_REGEX_NO_AUTO_CAPTURE   | \
112b5975d6bSopenharmony_ci-                              G_REGEX_OPTIMIZE          | \
113b5975d6bSopenharmony_ci-                              G_REGEX_FIRSTLINE         | \
114b5975d6bSopenharmony_ci-                              G_REGEX_DUPNAMES          | \
115b5975d6bSopenharmony_ci-                              G_REGEX_NEWLINE_CR        | \
116b5975d6bSopenharmony_ci-                              G_REGEX_NEWLINE_LF        | \
117b5975d6bSopenharmony_ci-                              G_REGEX_NEWLINE_CRLF      | \
118b5975d6bSopenharmony_ci-                              G_REGEX_NEWLINE_ANYCRLF   | \
119b5975d6bSopenharmony_ci-                              G_REGEX_BSR_ANYCRLF       | \
120b5975d6bSopenharmony_ci-                              G_REGEX_JAVASCRIPT_COMPAT)
121b5975d6bSopenharmony_ci+#define G_REGEX_COMPILE_MASK (PCRE2_CASELESS |        \
122b5975d6bSopenharmony_ci+                              PCRE2_MULTILINE |       \
123b5975d6bSopenharmony_ci+                              PCRE2_DOTALL |          \
124b5975d6bSopenharmony_ci+                              PCRE2_EXTENDED |        \
125b5975d6bSopenharmony_ci+                              PCRE2_ANCHORED |        \
126b5975d6bSopenharmony_ci+                              PCRE2_DOLLAR_ENDONLY |  \
127b5975d6bSopenharmony_ci+                              PCRE2_UNGREEDY |        \
128b5975d6bSopenharmony_ci+                              PCRE2_UTF |             \
129b5975d6bSopenharmony_ci+                              PCRE2_NO_AUTO_CAPTURE | \
130b5975d6bSopenharmony_ci+                              PCRE2_FIRSTLINE |       \
131b5975d6bSopenharmony_ci+                              PCRE2_DUPNAMES |        \
132b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_CR |      \
133b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_LF |      \
134b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_CRLF |    \
135b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_ANYCRLF | \
136b5975d6bSopenharmony_ci+                              PCRE2_BSR_ANYCRLF |     \
137b5975d6bSopenharmony_ci+                              G_REGEX_FLAGS_CONVERTED)
138b5975d6bSopenharmony_ci 
139b5975d6bSopenharmony_ci /* Mask of all GRegexCompileFlags values that are (not) passed trough to PCRE */
140b5975d6bSopenharmony_ci #define G_REGEX_COMPILE_PCRE_MASK (G_REGEX_COMPILE_MASK & ~G_REGEX_COMPILE_NONPCRE_MASK)
141b5975d6bSopenharmony_ci-#define G_REGEX_COMPILE_NONPCRE_MASK (G_REGEX_RAW              | \
142b5975d6bSopenharmony_ci-                                      G_REGEX_OPTIMIZE)
143b5975d6bSopenharmony_ci+#define G_REGEX_COMPILE_NONPCRE_MASK (PCRE2_UTF | \
144b5975d6bSopenharmony_ci+                                      G_REGEX_FLAGS_CONVERTED)
145b5975d6bSopenharmony_ci 
146b5975d6bSopenharmony_ci /* Mask of all the possible values for GRegexMatchFlags. */
147b5975d6bSopenharmony_ci-#define G_REGEX_MATCH_MASK (G_REGEX_MATCH_ANCHORED         | \
148b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NOTBOL           | \
149b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NOTEOL           | \
150b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NOTEMPTY         | \
151b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_PARTIAL          | \
152b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NEWLINE_CR       | \
153b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NEWLINE_LF       | \
154b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NEWLINE_CRLF     | \
155b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NEWLINE_ANY      | \
156b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NEWLINE_ANYCRLF  | \
157b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_BSR_ANYCRLF      | \
158b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_BSR_ANY          | \
159b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_PARTIAL_SOFT     | \
160b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_PARTIAL_HARD     | \
161b5975d6bSopenharmony_ci-                            G_REGEX_MATCH_NOTEMPTY_ATSTART)
162b5975d6bSopenharmony_ci-
163b5975d6bSopenharmony_ci-/* we rely on these flags having the same values */
164b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_CASELESS          == PCRE_CASELESS);
165b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MULTILINE         == PCRE_MULTILINE);
166b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_DOTALL            == PCRE_DOTALL);
167b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_EXTENDED          == PCRE_EXTENDED);
168b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_ANCHORED          == PCRE_ANCHORED);
169b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_DOLLAR_ENDONLY    == PCRE_DOLLAR_ENDONLY);
170b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_UNGREEDY          == PCRE_UNGREEDY);
171b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_NO_AUTO_CAPTURE   == PCRE_NO_AUTO_CAPTURE);
172b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_FIRSTLINE         == PCRE_FIRSTLINE);
173b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_DUPNAMES          == PCRE_DUPNAMES);
174b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_NEWLINE_CR        == PCRE_NEWLINE_CR);
175b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_NEWLINE_LF        == PCRE_NEWLINE_LF);
176b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_NEWLINE_CRLF      == PCRE_NEWLINE_CRLF);
177b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_NEWLINE_ANYCRLF   == PCRE_NEWLINE_ANYCRLF);
178b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_BSR_ANYCRLF       == PCRE_BSR_ANYCRLF);
179b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_JAVASCRIPT_COMPAT == PCRE_JAVASCRIPT_COMPAT);
180b5975d6bSopenharmony_ci-
181b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_ANCHORED         == PCRE_ANCHORED);
182b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NOTBOL           == PCRE_NOTBOL);
183b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NOTEOL           == PCRE_NOTEOL);
184b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NOTEMPTY         == PCRE_NOTEMPTY);
185b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_PARTIAL          == PCRE_PARTIAL);
186b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NEWLINE_CR       == PCRE_NEWLINE_CR);
187b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NEWLINE_LF       == PCRE_NEWLINE_LF);
188b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NEWLINE_CRLF     == PCRE_NEWLINE_CRLF);
189b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NEWLINE_ANY      == PCRE_NEWLINE_ANY);
190b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NEWLINE_ANYCRLF  == PCRE_NEWLINE_ANYCRLF);
191b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_BSR_ANYCRLF      == PCRE_BSR_ANYCRLF);
192b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_BSR_ANY          == PCRE_BSR_UNICODE);
193b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_PARTIAL_SOFT     == PCRE_PARTIAL_SOFT);
194b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_PARTIAL_HARD     == PCRE_PARTIAL_HARD);
195b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_MATCH_NOTEMPTY_ATSTART == PCRE_NOTEMPTY_ATSTART);
196b5975d6bSopenharmony_ci-
197b5975d6bSopenharmony_ci-/* These PCRE flags are unused or not exposed publicly in GRegexFlags, so
198b5975d6bSopenharmony_ci- * it should be ok to reuse them for different things.
199b5975d6bSopenharmony_ci- */
200b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_OPTIMIZE          == PCRE_NO_UTF8_CHECK);
201b5975d6bSopenharmony_ci-G_STATIC_ASSERT (G_REGEX_RAW               == PCRE_UTF8);
202b5975d6bSopenharmony_ci+#define G_REGEX_MATCH_MASK (PCRE2_ANCHORED |         \
203b5975d6bSopenharmony_ci+                            PCRE2_NOTBOL |           \
204b5975d6bSopenharmony_ci+                            PCRE2_NOTEOL |           \
205b5975d6bSopenharmony_ci+                            PCRE2_NOTEMPTY |         \
206b5975d6bSopenharmony_ci+                            PCRE2_PARTIAL_SOFT |     \
207b5975d6bSopenharmony_ci+                            PCRE2_NEWLINE_CR |       \
208b5975d6bSopenharmony_ci+                            PCRE2_NEWLINE_LF |       \
209b5975d6bSopenharmony_ci+                            PCRE2_NEWLINE_CRLF |     \
210b5975d6bSopenharmony_ci+                            PCRE2_NEWLINE_ANY |      \
211b5975d6bSopenharmony_ci+                            PCRE2_NEWLINE_ANYCRLF |  \
212b5975d6bSopenharmony_ci+                            PCRE2_BSR_ANYCRLF |      \
213b5975d6bSopenharmony_ci+                            PCRE2_BSR_UNICODE |      \
214b5975d6bSopenharmony_ci+                            PCRE2_PARTIAL_SOFT |     \
215b5975d6bSopenharmony_ci+                            PCRE2_PARTIAL_HARD |     \
216b5975d6bSopenharmony_ci+                            PCRE2_NOTEMPTY_ATSTART | \
217b5975d6bSopenharmony_ci+                            G_REGEX_FLAGS_CONVERTED)
218b5975d6bSopenharmony_ci+
219b5975d6bSopenharmony_ci+#define G_REGEX_NEWLINE_MASK (PCRE2_NEWLINE_CR |     \
220b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_LF |     \
221b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_CRLF |   \
222b5975d6bSopenharmony_ci+                              PCRE2_NEWLINE_ANYCRLF)
223b5975d6bSopenharmony_ci+
224b5975d6bSopenharmony_ci+#define G_REGEX_MATCH_NEWLINE_MASK (PCRE2_NEWLINE_CR |      \
225b5975d6bSopenharmony_ci+                                    PCRE2_NEWLINE_LF |      \
226b5975d6bSopenharmony_ci+                                    PCRE2_NEWLINE_CRLF |    \
227b5975d6bSopenharmony_ci+                                    PCRE2_NEWLINE_ANYCRLF | \
228b5975d6bSopenharmony_ci+                                    PCRE2_NEWLINE_ANY)
229b5975d6bSopenharmony_ci 
230b5975d6bSopenharmony_ci /* if the string is in UTF-8 use g_utf8_ functions, else use
231b5975d6bSopenharmony_ci  * use just +/- 1. */
232b5975d6bSopenharmony_ci@@ -208,24 +185,26 @@ struct _GMatchInfo
233b5975d6bSopenharmony_ci   gint pos;                     /* position in the string where last match left off */
234b5975d6bSopenharmony_ci   gint  n_offsets;              /* number of offsets */
235b5975d6bSopenharmony_ci   gint *offsets;                /* array of offsets paired 0,1 ; 2,3 ; 3,4 etc */
236b5975d6bSopenharmony_ci-  gint *workspace;              /* workspace for pcre_dfa_exec() */
237b5975d6bSopenharmony_ci+  gint *workspace;              /* workspace for pcre2_dfa_match() */
238b5975d6bSopenharmony_ci   gint n_workspace;             /* number of workspace elements */
239b5975d6bSopenharmony_ci   const gchar *string;          /* string passed to the match function */
240b5975d6bSopenharmony_ci   gssize string_len;            /* length of string, in bytes */
241b5975d6bSopenharmony_ci+  pcre2_match_context *match_context;
242b5975d6bSopenharmony_ci+  pcre2_match_data *match_data;
243b5975d6bSopenharmony_ci };
244b5975d6bSopenharmony_ci 
245b5975d6bSopenharmony_ci struct _GRegex
246b5975d6bSopenharmony_ci {
247b5975d6bSopenharmony_ci   gint ref_count;               /* the ref count for the immutable part (atomic) */
248b5975d6bSopenharmony_ci   gchar *pattern;               /* the pattern */
249b5975d6bSopenharmony_ci-  pcre *pcre_re;                /* compiled form of the pattern */
250b5975d6bSopenharmony_ci-  GRegexCompileFlags compile_opts;      /* options used at compile time on the pattern */
251b5975d6bSopenharmony_ci+  pcre2_code *pcre_re;          /* compiled form of the pattern */
252b5975d6bSopenharmony_ci+  GRegexCompileFlags compile_opts;      /* options used at compile time on the pattern, pcre2 values */
253b5975d6bSopenharmony_ci+  GRegexCompileFlags orig_compile_opts; /* options used at compile time on the pattern, gregex values */
254b5975d6bSopenharmony_ci   GRegexMatchFlags match_opts;  /* options used at match time on the regex */
255b5975d6bSopenharmony_ci-  pcre_extra *extra;            /* data stored when G_REGEX_OPTIMIZE is used */
256b5975d6bSopenharmony_ci };
257b5975d6bSopenharmony_ci 
258b5975d6bSopenharmony_ci /* TRUE if ret is an error code, FALSE otherwise. */
259b5975d6bSopenharmony_ci-#define IS_PCRE_ERROR(ret) ((ret) < PCRE_ERROR_NOMATCH && (ret) != PCRE_ERROR_PARTIAL)
260b5975d6bSopenharmony_ci+#define IS_PCRE2_ERROR(ret) ((ret) < PCRE2_ERROR_NOMATCH && (ret) != PCRE2_ERROR_PARTIAL)
261b5975d6bSopenharmony_ci 
262b5975d6bSopenharmony_ci typedef struct _InterpolationData InterpolationData;
263b5975d6bSopenharmony_ci static gboolean  interpolation_list_needs_match (GList *list);
264b5975d6bSopenharmony_ci@@ -236,70 +215,249 @@ static GList    *split_replacement              (const gchar *replacement,
265b5975d6bSopenharmony_ci                                                  GError **error);
266b5975d6bSopenharmony_ci static void      free_interpolation_data        (InterpolationData *data);
267b5975d6bSopenharmony_ci 
268b5975d6bSopenharmony_ci+static gint
269b5975d6bSopenharmony_ci+map_to_pcre2_compile_flags (gint pcre1_flags)
270b5975d6bSopenharmony_ci+{
271b5975d6bSopenharmony_ci+  /* Maps compile flags from pcre1 to pcre2 values
272b5975d6bSopenharmony_ci+   */
273b5975d6bSopenharmony_ci+  gint pcre2_flags = G_REGEX_FLAGS_CONVERTED;
274b5975d6bSopenharmony_ci+
275b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_FLAGS_CONVERTED)
276b5975d6bSopenharmony_ci+    return pcre1_flags;
277b5975d6bSopenharmony_ci+
278b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_CASELESS)
279b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_CASELESS;
280b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MULTILINE)
281b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_MULTILINE;
282b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_DOTALL)
283b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_DOTALL;
284b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_EXTENDED)
285b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_EXTENDED;
286b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_ANCHORED)
287b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_ANCHORED;
288b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_DOLLAR_ENDONLY)
289b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_DOLLAR_ENDONLY;
290b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_UNGREEDY)
291b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_UNGREEDY;
292b5975d6bSopenharmony_ci+  if (!(pcre1_flags & G_REGEX_RAW))
293b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_UTF;
294b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_NO_AUTO_CAPTURE)
295b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NO_AUTO_CAPTURE;
296b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_FIRSTLINE)
297b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_FIRSTLINE;
298b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_DUPNAMES)
299b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_DUPNAMES;
300b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_NEWLINE_CR)
301b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_CR;
302b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_NEWLINE_LF)
303b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_LF;
304b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
305b5975d6bSopenharmony_ci+  if ((pcre1_flags & G_REGEX_NEWLINE_CRLF) == G_REGEX_NEWLINE_CRLF)
306b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_CRLF;
307b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
308b5975d6bSopenharmony_ci+  if ((pcre1_flags & G_REGEX_NEWLINE_ANYCRLF) == G_REGEX_NEWLINE_ANYCRLF)
309b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_ANYCRLF;
310b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_BSR_ANYCRLF)
311b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_BSR_ANYCRLF;
312b5975d6bSopenharmony_ci+
313b5975d6bSopenharmony_ci+  /* these are not available in pcre2 */
314b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
315b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_OPTIMIZE)
316b5975d6bSopenharmony_ci+    pcre2_flags |= 0;
317b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_JAVASCRIPT_COMPAT)
318b5975d6bSopenharmony_ci+    pcre2_flags |= 0;
319b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
320b5975d6bSopenharmony_ci+
321b5975d6bSopenharmony_ci+  return pcre2_flags;
322b5975d6bSopenharmony_ci+}
323b5975d6bSopenharmony_ci+
324b5975d6bSopenharmony_ci+static gint
325b5975d6bSopenharmony_ci+map_to_pcre2_match_flags (gint pcre1_flags)
326b5975d6bSopenharmony_ci+{
327b5975d6bSopenharmony_ci+  /* Maps match flags from pcre1 to pcre2 values
328b5975d6bSopenharmony_ci+   */
329b5975d6bSopenharmony_ci+  gint pcre2_flags = G_REGEX_FLAGS_CONVERTED;
330b5975d6bSopenharmony_ci+
331b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_FLAGS_CONVERTED)
332b5975d6bSopenharmony_ci+    return pcre1_flags;
333b5975d6bSopenharmony_ci+
334b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_ANCHORED)
335b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_ANCHORED;
336b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NOTBOL)
337b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NOTBOL;
338b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NOTEOL)
339b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NOTEOL;
340b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NOTEMPTY)
341b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NOTEMPTY;
342b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_PARTIAL)
343b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_PARTIAL_SOFT;
344b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NEWLINE_CR)
345b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_CR;
346b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NEWLINE_LF)
347b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_LF;
348b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
349b5975d6bSopenharmony_ci+  if ((pcre1_flags & G_REGEX_MATCH_NEWLINE_CRLF) == G_REGEX_MATCH_NEWLINE_CRLF)
350b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_CRLF;
351b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NEWLINE_ANY)
352b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_ANY;
353b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
354b5975d6bSopenharmony_ci+  if ((pcre1_flags & G_REGEX_MATCH_NEWLINE_ANYCRLF) == G_REGEX_MATCH_NEWLINE_ANYCRLF)
355b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NEWLINE_ANYCRLF;
356b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_BSR_ANYCRLF)
357b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_BSR_ANYCRLF;
358b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_BSR_ANY)
359b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_BSR_UNICODE;
360b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_PARTIAL_SOFT)
361b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_PARTIAL_SOFT;
362b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_PARTIAL_HARD)
363b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_PARTIAL_HARD;
364b5975d6bSopenharmony_ci+  if (pcre1_flags & G_REGEX_MATCH_NOTEMPTY_ATSTART)
365b5975d6bSopenharmony_ci+    pcre2_flags |= PCRE2_NOTEMPTY_ATSTART;
366b5975d6bSopenharmony_ci+
367b5975d6bSopenharmony_ci+  return pcre2_flags;
368b5975d6bSopenharmony_ci+}
369b5975d6bSopenharmony_ci+
370b5975d6bSopenharmony_ci+static gint
371b5975d6bSopenharmony_ci+map_to_pcre1_compile_flags (gint pcre2_flags)
372b5975d6bSopenharmony_ci+{
373b5975d6bSopenharmony_ci+  /* Maps compile flags from pcre2 to pcre1 values
374b5975d6bSopenharmony_ci+   */
375b5975d6bSopenharmony_ci+  gint pcre1_flags = 0;
376b5975d6bSopenharmony_ci+
377b5975d6bSopenharmony_ci+  if (!(pcre2_flags & G_REGEX_FLAGS_CONVERTED))
378b5975d6bSopenharmony_ci+    return pcre2_flags;
379b5975d6bSopenharmony_ci+
380b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_CASELESS)
381b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_CASELESS;
382b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_MULTILINE)
383b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MULTILINE;
384b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_DOTALL)
385b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_DOTALL;
386b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_EXTENDED)
387b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_EXTENDED;
388b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_ANCHORED)
389b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_ANCHORED;
390b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_DOLLAR_ENDONLY)
391b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_DOLLAR_ENDONLY;
392b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_UNGREEDY)
393b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_UNGREEDY;
394b5975d6bSopenharmony_ci+  if (!(pcre2_flags & PCRE2_UTF))
395b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_RAW;
396b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NO_AUTO_CAPTURE)
397b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_NO_AUTO_CAPTURE;
398b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_FIRSTLINE)
399b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_FIRSTLINE;
400b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_DUPNAMES)
401b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_DUPNAMES;
402b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NEWLINE_CR)
403b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_NEWLINE_CR;
404b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NEWLINE_LF)
405b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_NEWLINE_LF;
406b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
407b5975d6bSopenharmony_ci+  if ((pcre2_flags & PCRE2_NEWLINE_CRLF) == PCRE2_NEWLINE_CRLF)
408b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_NEWLINE_CRLF;
409b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
410b5975d6bSopenharmony_ci+  if ((pcre2_flags & PCRE2_NEWLINE_ANYCRLF) == PCRE2_NEWLINE_ANYCRLF)
411b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_NEWLINE_ANYCRLF;
412b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_BSR_ANYCRLF)
413b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_BSR_ANYCRLF;
414b5975d6bSopenharmony_ci+
415b5975d6bSopenharmony_ci+  return pcre1_flags;
416b5975d6bSopenharmony_ci+}
417b5975d6bSopenharmony_ci+
418b5975d6bSopenharmony_ci+static gint
419b5975d6bSopenharmony_ci+map_to_pcre1_match_flags (gint pcre2_flags)
420b5975d6bSopenharmony_ci+{
421b5975d6bSopenharmony_ci+  /* Maps match flags from pcre2 to pcre1 values
422b5975d6bSopenharmony_ci+   */
423b5975d6bSopenharmony_ci+  gint pcre1_flags = 0;
424b5975d6bSopenharmony_ci+
425b5975d6bSopenharmony_ci+  if (!(pcre2_flags & G_REGEX_FLAGS_CONVERTED))
426b5975d6bSopenharmony_ci+    return pcre2_flags;
427b5975d6bSopenharmony_ci+
428b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_ANCHORED)
429b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_ANCHORED;
430b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NOTBOL)
431b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NOTBOL;
432b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NOTEOL)
433b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NOTEOL;
434b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NOTEMPTY)
435b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NOTEMPTY;
436b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_PARTIAL_SOFT)
437b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_PARTIAL;
438b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NEWLINE_CR)
439b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NEWLINE_CR;
440b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NEWLINE_LF)
441b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NEWLINE_LF;
442b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
443b5975d6bSopenharmony_ci+  if ((pcre2_flags & PCRE2_NEWLINE_CRLF) == PCRE2_NEWLINE_CRLF)
444b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NEWLINE_CRLF;
445b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NEWLINE_ANY)
446b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NEWLINE_ANY;
447b5975d6bSopenharmony_ci+  /* Check for exact match for a composite flag */
448b5975d6bSopenharmony_ci+  if ((pcre2_flags & PCRE2_NEWLINE_ANYCRLF) == PCRE2_NEWLINE_ANYCRLF)
449b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NEWLINE_ANYCRLF;
450b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_BSR_ANYCRLF)
451b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_BSR_ANYCRLF;
452b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_BSR_UNICODE)
453b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_BSR_ANY;
454b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_PARTIAL_SOFT)
455b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_PARTIAL_SOFT;
456b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_PARTIAL_HARD)
457b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_PARTIAL_HARD;
458b5975d6bSopenharmony_ci+  if (pcre2_flags & PCRE2_NOTEMPTY_ATSTART)
459b5975d6bSopenharmony_ci+    pcre1_flags |= G_REGEX_MATCH_NOTEMPTY_ATSTART;
460b5975d6bSopenharmony_ci+
461b5975d6bSopenharmony_ci+  return pcre1_flags;
462b5975d6bSopenharmony_ci+}
463b5975d6bSopenharmony_ci 
464b5975d6bSopenharmony_ci static const gchar *
465b5975d6bSopenharmony_ci match_error (gint errcode)
466b5975d6bSopenharmony_ci {
467b5975d6bSopenharmony_ci   switch (errcode)
468b5975d6bSopenharmony_ci     {
469b5975d6bSopenharmony_ci-    case PCRE_ERROR_NOMATCH:
470b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NOMATCH:
471b5975d6bSopenharmony_ci       /* not an error */
472b5975d6bSopenharmony_ci       break;
473b5975d6bSopenharmony_ci-    case PCRE_ERROR_NULL:
474b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NULL:
475b5975d6bSopenharmony_ci       /* NULL argument, this should not happen in GRegex */
476b5975d6bSopenharmony_ci       g_warning ("A NULL argument was passed to PCRE");
477b5975d6bSopenharmony_ci       break;
478b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADOPTION:
479b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BADOPTION:
480b5975d6bSopenharmony_ci       return "bad options";
481b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADMAGIC:
482b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BADMAGIC:
483b5975d6bSopenharmony_ci       return _("corrupted object");
484b5975d6bSopenharmony_ci-    case PCRE_ERROR_UNKNOWN_OPCODE:
485b5975d6bSopenharmony_ci-      return N_("internal error or corrupted object");
486b5975d6bSopenharmony_ci-    case PCRE_ERROR_NOMEMORY:
487b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NOMEMORY:
488b5975d6bSopenharmony_ci       return _("out of memory");
489b5975d6bSopenharmony_ci-    case PCRE_ERROR_NOSUBSTRING:
490b5975d6bSopenharmony_ci-      /* not used by pcre_exec() */
491b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NOSUBSTRING:
492b5975d6bSopenharmony_ci+      /* not used by pcre2_match() */
493b5975d6bSopenharmony_ci       break;
494b5975d6bSopenharmony_ci-    case PCRE_ERROR_MATCHLIMIT:
495b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MATCHLIMIT:
496b5975d6bSopenharmony_ci       return _("backtracking limit reached");
497b5975d6bSopenharmony_ci-    case PCRE_ERROR_CALLOUT:
498b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CALLOUT:
499b5975d6bSopenharmony_ci       /* callouts are not implemented */
500b5975d6bSopenharmony_ci       break;
501b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADUTF8:
502b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADUTF8_OFFSET:
503b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BADUTFOFFSET:
504b5975d6bSopenharmony_ci       /* we do not check if strings are valid */
505b5975d6bSopenharmony_ci       break;
506b5975d6bSopenharmony_ci-    case PCRE_ERROR_PARTIAL:
507b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PARTIAL:
508b5975d6bSopenharmony_ci       /* not an error */
509b5975d6bSopenharmony_ci       break;
510b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADPARTIAL:
511b5975d6bSopenharmony_ci-      return _("the pattern contains items not supported for partial matching");
512b5975d6bSopenharmony_ci-    case PCRE_ERROR_INTERNAL:
513b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL:
514b5975d6bSopenharmony_ci       return _("internal error");
515b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADCOUNT:
516b5975d6bSopenharmony_ci-      /* negative ovecsize, this should not happen in GRegex */
517b5975d6bSopenharmony_ci-      g_warning ("A negative ovecsize was passed to PCRE");
518b5975d6bSopenharmony_ci-      break;
519b5975d6bSopenharmony_ci-    case PCRE_ERROR_DFA_UITEM:
520b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DFA_UITEM:
521b5975d6bSopenharmony_ci       return _("the pattern contains items not supported for partial matching");
522b5975d6bSopenharmony_ci-    case PCRE_ERROR_DFA_UCOND:
523b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DFA_UCOND:
524b5975d6bSopenharmony_ci       return _("back references as conditions are not supported for partial matching");
525b5975d6bSopenharmony_ci-    case PCRE_ERROR_DFA_UMLIMIT:
526b5975d6bSopenharmony_ci-      /* the match_field field is not used in GRegex */
527b5975d6bSopenharmony_ci-      break;
528b5975d6bSopenharmony_ci-    case PCRE_ERROR_DFA_WSSIZE:
529b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DFA_WSSIZE:
530b5975d6bSopenharmony_ci       /* handled expanding the workspace */
531b5975d6bSopenharmony_ci       break;
532b5975d6bSopenharmony_ci-    case PCRE_ERROR_DFA_RECURSE:
533b5975d6bSopenharmony_ci-    case PCRE_ERROR_RECURSIONLIMIT:
534b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DFA_RECURSE:
535b5975d6bSopenharmony_ci+    case PCRE2_ERROR_RECURSIONLIMIT:
536b5975d6bSopenharmony_ci       return _("recursion limit reached");
537b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADNEWLINE:
538b5975d6bSopenharmony_ci-      return _("invalid combination of newline flags");
539b5975d6bSopenharmony_ci-    case PCRE_ERROR_BADOFFSET:
540b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BADOFFSET:
541b5975d6bSopenharmony_ci       return _("bad offset");
542b5975d6bSopenharmony_ci-    case PCRE_ERROR_SHORTUTF8:
543b5975d6bSopenharmony_ci-      return _("short utf8");
544b5975d6bSopenharmony_ci-    case PCRE_ERROR_RECURSELOOP:
545b5975d6bSopenharmony_ci+    case PCRE2_ERROR_RECURSELOOP:
546b5975d6bSopenharmony_ci       return _("recursion loop");
547b5975d6bSopenharmony_ci     default:
548b5975d6bSopenharmony_ci       break;
549b5975d6bSopenharmony_ci@@ -310,242 +468,263 @@ match_error (gint errcode)
550b5975d6bSopenharmony_ci static void
551b5975d6bSopenharmony_ci translate_compile_error (gint *errcode, const gchar **errmsg)
552b5975d6bSopenharmony_ci {
553b5975d6bSopenharmony_ci-  /* Compile errors are created adding 100 to the error code returned
554b5975d6bSopenharmony_ci-   * by PCRE.
555b5975d6bSopenharmony_ci-   * If errcode is known we put the translatable error message in
556b5975d6bSopenharmony_ci-   * erromsg. If errcode is unknown we put the generic
557b5975d6bSopenharmony_ci-   * G_REGEX_ERROR_COMPILE error code in errcode and keep the
558b5975d6bSopenharmony_ci-   * untranslated error message returned by PCRE.
559b5975d6bSopenharmony_ci+  /* If errcode is known we put the translatable error message in
560b5975d6bSopenharmony_ci+   * errmsg. If errcode is unknown we put the generic
561b5975d6bSopenharmony_ci+   * G_REGEX_ERROR_COMPILE error code in errcode.
562b5975d6bSopenharmony_ci    * Note that there can be more PCRE errors with the same GRegexError
563b5975d6bSopenharmony_ci    * and that some PCRE errors are useless for us.
564b5975d6bSopenharmony_ci    */
565b5975d6bSopenharmony_ci-  *errcode += 100;
566b5975d6bSopenharmony_ci 
567b5975d6bSopenharmony_ci   switch (*errcode)
568b5975d6bSopenharmony_ci     {
569b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_STRAY_BACKSLASH:
570b5975d6bSopenharmony_ci+    case PCRE2_ERROR_END_BACKSLASH:
571b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_STRAY_BACKSLASH;
572b5975d6bSopenharmony_ci       *errmsg = _("\\ at end of pattern");
573b5975d6bSopenharmony_ci       break;
574b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_CONTROL_CHAR:
575b5975d6bSopenharmony_ci+    case PCRE2_ERROR_END_BACKSLASH_C:
576b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MISSING_CONTROL_CHAR;
577b5975d6bSopenharmony_ci       *errmsg = _("\\c at end of pattern");
578b5975d6bSopenharmony_ci       break;
579b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNRECOGNIZED_ESCAPE:
580b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNKNOWN_ESCAPE:
581b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE:
582b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNRECOGNIZED_ESCAPE;
583b5975d6bSopenharmony_ci       *errmsg = _("unrecognized character following \\");
584b5975d6bSopenharmony_ci       break;
585b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER:
586b5975d6bSopenharmony_ci+    case PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER:
587b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER;
588b5975d6bSopenharmony_ci       *errmsg = _("numbers out of order in {} quantifier");
589b5975d6bSopenharmony_ci       break;
590b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_QUANTIFIER_TOO_BIG:
591b5975d6bSopenharmony_ci+    case PCRE2_ERROR_QUANTIFIER_TOO_BIG:
592b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_QUANTIFIER_TOO_BIG;
593b5975d6bSopenharmony_ci       *errmsg = _("number too big in {} quantifier");
594b5975d6bSopenharmony_ci       break;
595b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS:
596b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_SQUARE_BRACKET:
597b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS;
598b5975d6bSopenharmony_ci       *errmsg = _("missing terminating ] for character class");
599b5975d6bSopenharmony_ci       break;
600b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS:
601b5975d6bSopenharmony_ci+    case PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS:
602b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS;
603b5975d6bSopenharmony_ci       *errmsg = _("invalid escape sequence in character class");
604b5975d6bSopenharmony_ci       break;
605b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_RANGE_OUT_OF_ORDER:
606b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CLASS_RANGE_ORDER:
607b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_RANGE_OUT_OF_ORDER;
608b5975d6bSopenharmony_ci       *errmsg = _("range out of order in character class");
609b5975d6bSopenharmony_ci       break;
610b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_NOTHING_TO_REPEAT:
611b5975d6bSopenharmony_ci+    case PCRE2_ERROR_QUANTIFIER_INVALID:
612b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT:
613b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_NOTHING_TO_REPEAT;
614b5975d6bSopenharmony_ci       *errmsg = _("nothing to repeat");
615b5975d6bSopenharmony_ci       break;
616b5975d6bSopenharmony_ci-    case 111: /* internal error: unexpected repeat */
617b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_INTERNAL;
618b5975d6bSopenharmony_ci-      *errmsg = _("unexpected repeat");
619b5975d6bSopenharmony_ci-      break;
620b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNRECOGNIZED_CHARACTER:
621b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY:
622b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
623b5975d6bSopenharmony_ci       *errmsg = _("unrecognized character after (? or (?-");
624b5975d6bSopenharmony_ci       break;
625b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS:
626b5975d6bSopenharmony_ci+    case PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS:
627b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS;
628b5975d6bSopenharmony_ci       *errmsg = _("POSIX named classes are supported only within a class");
629b5975d6bSopenharmony_ci       break;
630b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNMATCHED_PARENTHESIS:
631b5975d6bSopenharmony_ci+    case PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING:
632b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED;
633b5975d6bSopenharmony_ci+      *errmsg = _("POSIX collating elements are not supported");
634b5975d6bSopenharmony_ci+      break;
635b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS:
636b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS:
637b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING:
638b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNMATCHED_PARENTHESIS;
639b5975d6bSopenharmony_ci       *errmsg = _("missing terminating )");
640b5975d6bSopenharmony_ci       break;
641b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE:
642b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE:
643b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE;
644b5975d6bSopenharmony_ci       *errmsg = _("reference to non-existent subpattern");
645b5975d6bSopenharmony_ci       break;
646b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNTERMINATED_COMMENT:
647b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_COMMENT_CLOSING:
648b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNTERMINATED_COMMENT;
649b5975d6bSopenharmony_ci       *errmsg = _("missing ) after comment");
650b5975d6bSopenharmony_ci       break;
651b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_EXPRESSION_TOO_LARGE:
652b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PATTERN_TOO_LARGE:
653b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_EXPRESSION_TOO_LARGE;
654b5975d6bSopenharmony_ci       *errmsg = _("regular expression is too large");
655b5975d6bSopenharmony_ci       break;
656b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MEMORY_ERROR:
657b5975d6bSopenharmony_ci-      *errmsg = _("failed to get memory");
658b5975d6bSopenharmony_ci-      break;
659b5975d6bSopenharmony_ci-    case 122: /* unmatched parentheses */
660b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_UNMATCHED_PARENTHESIS;
661b5975d6bSopenharmony_ci-      *errmsg = _(") without opening (");
662b5975d6bSopenharmony_ci-      break;
663b5975d6bSopenharmony_ci-    case 123: /* internal error: code overflow */
664b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_INTERNAL;
665b5975d6bSopenharmony_ci-      *errmsg = _("code overflow");
666b5975d6bSopenharmony_ci-      break;
667b5975d6bSopenharmony_ci-    case 124: /* "unrecognized character after (?<\0 */
668b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
669b5975d6bSopenharmony_ci-      *errmsg = _("unrecognized character after (?<");
670b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_CONDITION_CLOSING:
671b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MALFORMED_CONDITION;
672b5975d6bSopenharmony_ci+      *errmsg = _("malformed number or name after (?(");
673b5975d6bSopenharmony_ci       break;
674b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND:
675b5975d6bSopenharmony_ci+    case PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH:
676b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND;
677b5975d6bSopenharmony_ci       *errmsg = _("lookbehind assertion is not fixed length");
678b5975d6bSopenharmony_ci       break;
679b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MALFORMED_CONDITION:
680b5975d6bSopenharmony_ci-      *errmsg = _("malformed number or name after (?(");
681b5975d6bSopenharmony_ci-      break;
682b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES:
683b5975d6bSopenharmony_ci+    case PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES:
684b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES;
685b5975d6bSopenharmony_ci       *errmsg = _("conditional group contains more than two branches");
686b5975d6bSopenharmony_ci       break;
687b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_ASSERTION_EXPECTED:
688b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED:
689b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_ASSERTION_EXPECTED;
690b5975d6bSopenharmony_ci       *errmsg = _("assertion expected after (?(");
691b5975d6bSopenharmony_ci       break;
692b5975d6bSopenharmony_ci-    case 129:
693b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_UNMATCHED_PARENTHESIS;
694b5975d6bSopenharmony_ci-      /* translators: '(?R' and '(?[+-]digits' are both meant as (groups of)
695b5975d6bSopenharmony_ci-       * sequences here, '(?-54' would be an example for the second group.
696b5975d6bSopenharmony_ci-       */
697b5975d6bSopenharmony_ci-      *errmsg = _("(?R or (?[+-]digits must be followed by )");
698b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BAD_RELATIVE_REFERENCE:
699b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE;
700b5975d6bSopenharmony_ci+      *errmsg = _("a numbered reference must not be zero");
701b5975d6bSopenharmony_ci       break;
702b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME:
703b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNKNOWN_POSIX_CLASS:
704b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME;
705b5975d6bSopenharmony_ci       *errmsg = _("unknown POSIX class name");
706b5975d6bSopenharmony_ci       break;
707b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED:
708b5975d6bSopenharmony_ci-      *errmsg = _("POSIX collating elements are not supported");
709b5975d6bSopenharmony_ci-      break;
710b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_HEX_CODE_TOO_LARGE:
711b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CODE_POINT_TOO_BIG:
712b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INVALID_HEXADECIMAL:
713b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_HEX_CODE_TOO_LARGE;
714b5975d6bSopenharmony_ci       *errmsg = _("character value in \\x{...} sequence is too large");
715b5975d6bSopenharmony_ci       break;
716b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_CONDITION:
717b5975d6bSopenharmony_ci-      *errmsg = _("invalid condition (?(0)");
718b5975d6bSopenharmony_ci-      break;
719b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND:
720b5975d6bSopenharmony_ci+    case PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C:
721b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND;
722b5975d6bSopenharmony_ci       *errmsg = _("\\C not allowed in lookbehind assertion");
723b5975d6bSopenharmony_ci       break;
724b5975d6bSopenharmony_ci-    case 137: /* PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u\0 */
725b5975d6bSopenharmony_ci-      /* A number of Perl escapes are not handled by PCRE.
726b5975d6bSopenharmony_ci-       * Therefore it explicitly raises ERR37.
727b5975d6bSopenharmony_ci-       */
728b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_UNRECOGNIZED_ESCAPE;
729b5975d6bSopenharmony_ci-      *errmsg = _("escapes \\L, \\l, \\N{name}, \\U, and \\u are not supported");
730b5975d6bSopenharmony_ci-      break;
731b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INFINITE_LOOP:
732b5975d6bSopenharmony_ci-      *errmsg = _("recursive call could loop indefinitely");
733b5975d6bSopenharmony_ci-      break;
734b5975d6bSopenharmony_ci-    case 141: /* unrecognized character after (?P\0 */
735b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
736b5975d6bSopenharmony_ci-      *errmsg = _("unrecognized character after (?P");
737b5975d6bSopenharmony_ci-      break;
738b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR:
739b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_NAME_TERMINATOR:
740b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR;
741b5975d6bSopenharmony_ci       *errmsg = _("missing terminator in subpattern name");
742b5975d6bSopenharmony_ci       break;
743b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME:
744b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME:
745b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME;
746b5975d6bSopenharmony_ci       *errmsg = _("two named subpatterns have the same name");
747b5975d6bSopenharmony_ci       break;
748b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MALFORMED_PROPERTY:
749b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY:
750b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MALFORMED_PROPERTY;
751b5975d6bSopenharmony_ci       *errmsg = _("malformed \\P or \\p sequence");
752b5975d6bSopenharmony_ci       break;
753b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNKNOWN_PROPERTY:
754b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY:
755b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNKNOWN_PROPERTY;
756b5975d6bSopenharmony_ci       *errmsg = _("unknown property name after \\P or \\p");
757b5975d6bSopenharmony_ci       break;
758b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG:
759b5975d6bSopenharmony_ci+    case PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG:
760b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG;
761b5975d6bSopenharmony_ci       *errmsg = _("subpattern name is too long (maximum 32 characters)");
762b5975d6bSopenharmony_ci       break;
763b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_TOO_MANY_SUBPATTERNS:
764b5975d6bSopenharmony_ci+    case PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS:
765b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_TOO_MANY_SUBPATTERNS;
766b5975d6bSopenharmony_ci       *errmsg = _("too many named subpatterns (maximum 10,000)");
767b5975d6bSopenharmony_ci       break;
768b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_OCTAL_VALUE:
769b5975d6bSopenharmony_ci+    case PCRE2_ERROR_OCTAL_BYTE_TOO_BIG:
770b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INVALID_OCTAL_VALUE;
771b5975d6bSopenharmony_ci       *errmsg = _("octal value is greater than \\377");
772b5975d6bSopenharmony_ci       break;
773b5975d6bSopenharmony_ci-    case 152: /* internal error: overran compiling workspace */
774b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_INTERNAL;
775b5975d6bSopenharmony_ci-      *errmsg = _("overran compiling workspace");
776b5975d6bSopenharmony_ci-      break;
777b5975d6bSopenharmony_ci-    case 153: /* internal error: previously-checked referenced subpattern not found */
778b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_INTERNAL;
779b5975d6bSopenharmony_ci-      *errmsg = _("previously-checked referenced subpattern not found");
780b5975d6bSopenharmony_ci-      break;
781b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE:
782b5975d6bSopenharmony_ci+    case PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES:
783b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE;
784b5975d6bSopenharmony_ci       *errmsg = _("DEFINE group contains more than one branch");
785b5975d6bSopenharmony_ci       break;
786b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS:
787b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE:
788b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS;
789b5975d6bSopenharmony_ci       *errmsg = _("inconsistent NEWLINE options");
790b5975d6bSopenharmony_ci       break;
791b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_BACK_REFERENCE:
792b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_G_SYNTAX:
793b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MISSING_BACK_REFERENCE;
794b5975d6bSopenharmony_ci       *errmsg = _("\\g is not followed by a braced, angle-bracketed, or quoted name or "
795b5975d6bSopenharmony_ci                   "number, or by a plain number");
796b5975d6bSopenharmony_ci       break;
797b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE:
798b5975d6bSopenharmony_ci-      *errmsg = _("a numbered reference must not be zero");
799b5975d6bSopenharmony_ci-      break;
800b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN:
801b5975d6bSopenharmony_ci+    case PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED:
802b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN;
803b5975d6bSopenharmony_ci       *errmsg = _("an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)");
804b5975d6bSopenharmony_ci       break;
805b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_UNKNOWN_BACKTRACKING_CONTROL_VERB:
806b5975d6bSopenharmony_ci+    case PCRE2_ERROR_VERB_UNKNOWN:
807b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNKNOWN_BACKTRACKING_CONTROL_VERB;
808b5975d6bSopenharmony_ci       *errmsg = _("(*VERB) not recognized");
809b5975d6bSopenharmony_ci       break;
810b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_NUMBER_TOO_BIG:
811b5975d6bSopenharmony_ci+    case PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG:
812b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_NUMBER_TOO_BIG;
813b5975d6bSopenharmony_ci       *errmsg = _("number is too big");
814b5975d6bSopenharmony_ci       break;
815b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_SUBPATTERN_NAME:
816b5975d6bSopenharmony_ci+    case PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED:
817b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MISSING_SUBPATTERN_NAME;
818b5975d6bSopenharmony_ci       *errmsg = _("missing subpattern name after (?&");
819b5975d6bSopenharmony_ci       break;
820b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_DIGIT:
821b5975d6bSopenharmony_ci-      *errmsg = _("digit expected after (?+");
822b5975d6bSopenharmony_ci-      break;
823b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_DATA_CHARACTER:
824b5975d6bSopenharmony_ci-      *errmsg = _("] is an invalid data character in JavaScript compatibility mode");
825b5975d6bSopenharmony_ci-      break;
826b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_EXTRA_SUBPATTERN_NAME:
827b5975d6bSopenharmony_ci+    case PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH:
828b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_EXTRA_SUBPATTERN_NAME;
829b5975d6bSopenharmony_ci       *errmsg = _("different names for subpatterns of the same number are not allowed");
830b5975d6bSopenharmony_ci       break;
831b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED:
832b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MARK_MISSING_ARGUMENT:
833b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED;
834b5975d6bSopenharmony_ci       *errmsg = _("(*MARK) must have an argument");
835b5975d6bSopenharmony_ci       break;
836b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_INVALID_CONTROL_CHAR:
837b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_C_SYNTAX:
838b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INVALID_CONTROL_CHAR;
839b5975d6bSopenharmony_ci       *errmsg = _( "\\c must be followed by an ASCII character");
840b5975d6bSopenharmony_ci       break;
841b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_MISSING_NAME:
842b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_K_SYNTAX:
843b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_MISSING_NAME;
844b5975d6bSopenharmony_ci       *errmsg = _("\\k is not followed by a braced, angle-bracketed, or quoted name");
845b5975d6bSopenharmony_ci       break;
846b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_NOT_SUPPORTED_IN_CLASS:
847b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_N_IN_CLASS:
848b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_NOT_SUPPORTED_IN_CLASS;
849b5975d6bSopenharmony_ci       *errmsg = _("\\N is not supported in a class");
850b5975d6bSopenharmony_ci       break;
851b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_TOO_MANY_FORWARD_REFERENCES:
852b5975d6bSopenharmony_ci-      *errmsg = _("too many forward references");
853b5975d6bSopenharmony_ci-      break;
854b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_NAME_TOO_LONG:
855b5975d6bSopenharmony_ci+    case PCRE2_ERROR_VERB_NAME_TOO_LONG:
856b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_NAME_TOO_LONG;
857b5975d6bSopenharmony_ci       *errmsg = _("name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)");
858b5975d6bSopenharmony_ci       break;
859b5975d6bSopenharmony_ci-    case G_REGEX_ERROR_CHARACTER_VALUE_TOO_LARGE:
860b5975d6bSopenharmony_ci-      *errmsg = _("character value in \\u.... sequence is too large");
861b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_CODE_OVERFLOW:
862b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INTERNAL;
863b5975d6bSopenharmony_ci+      *errmsg = _("code overflow");
864b5975d6bSopenharmony_ci       break;
865b5975d6bSopenharmony_ci-
866b5975d6bSopenharmony_ci-    case 116: /* erroffset passed as NULL */
867b5975d6bSopenharmony_ci-      /* This should not happen as we never pass a NULL erroffset */
868b5975d6bSopenharmony_ci-      g_warning ("erroffset passed as NULL");
869b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_COMPILE;
870b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P:
871b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
872b5975d6bSopenharmony_ci+      *errmsg = _("unrecognized character after (?P");
873b5975d6bSopenharmony_ci       break;
874b5975d6bSopenharmony_ci-    case 117: /* unknown option bit(s) set */
875b5975d6bSopenharmony_ci-      /* This should not happen as we check options before passing them
876b5975d6bSopenharmony_ci-       * to pcre_compile2() */
877b5975d6bSopenharmony_ci-      g_warning ("unknown option bit(s) set");
878b5975d6bSopenharmony_ci-      *errcode = G_REGEX_ERROR_COMPILE;
879b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE:
880b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INTERNAL;
881b5975d6bSopenharmony_ci+      *errmsg = _("overran compiling workspace");
882b5975d6bSopenharmony_ci       break;
883b5975d6bSopenharmony_ci-    case 132: /* this version of PCRE is compiled without UTF support */
884b5975d6bSopenharmony_ci-    case 144: /* invalid UTF-8 string */
885b5975d6bSopenharmony_ci-    case 145: /* support for \\P, \\p, and \\X has not been compiled */
886b5975d6bSopenharmony_ci-    case 167: /* this version of PCRE is not compiled with Unicode property support */
887b5975d6bSopenharmony_ci-    case 173: /* disallowed Unicode code point (>= 0xd800 && <= 0xdfff) */
888b5975d6bSopenharmony_ci-    case 174: /* invalid UTF-16 string */
889b5975d6bSopenharmony_ci-      /* These errors should not happen as we are using an UTF-8 and UCP-enabled PCRE
890b5975d6bSopenharmony_ci-       * and we do not check if strings are valid */
891b5975d6bSopenharmony_ci-    case 170: /* internal error: unknown opcode in find_fixedlength() */
892b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN:
893b5975d6bSopenharmony_ci       *errcode = G_REGEX_ERROR_INTERNAL;
894b5975d6bSopenharmony_ci+      *errmsg = _("previously-checked referenced subpattern not found");
895b5975d6bSopenharmony_ci       break;
896b5975d6bSopenharmony_ci-
897b5975d6bSopenharmony_ci+    case PCRE2_ERROR_HEAP_FAILED:
898b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW:
899b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNICODE_NOT_SUPPORTED:
900b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT:
901b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NO_SURROGATES_IN_UTF16:
902b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS:
903b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE:
904b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_STUDY_ERROR:
905b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UTF_IS_DISABLED:
906b5975d6bSopenharmony_ci+    case PCRE2_ERROR_UCP_IS_DISABLED:
907b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS:
908b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED:
909b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_BAD_CODE:
910b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP:
911b5975d6bSopenharmony_ci+      *errcode = G_REGEX_ERROR_INTERNAL;
912b5975d6bSopenharmony_ci+      *errmsg = _("internal error");
913b5975d6bSopenharmony_ci+      break;
914b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INVALID_SUBPATTERN_NAME:
915b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CLASS_INVALID_RANGE:
916b5975d6bSopenharmony_ci+    case PCRE2_ERROR_ZERO_RELATIVE_REFERENCE:
917b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PARENTHESES_STACK_CHECK:
918b5975d6bSopenharmony_ci+    case PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED:
919b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG:
920b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_CALLOUT_CLOSING:
921b5975d6bSopenharmony_ci+    case PCRE2_ERROR_ESCAPE_INVALID_IN_VERB:
922b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NULL_PATTERN:
923b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BAD_OPTIONS:
924b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP:
925b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE:
926b5975d6bSopenharmony_ci+    case PCRE2_ERROR_INVALID_OCTAL:
927b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CALLOUT_STRING_TOO_LONG:
928b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG:
929b5975d6bSopenharmony_ci+    case PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS:
930b5975d6bSopenharmony_ci+    case PCRE2_ERROR_VERSION_CONDITION_SYNTAX:
931b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER:
932b5975d6bSopenharmony_ci+    case PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER:
933b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED:
934b5975d6bSopenharmony_ci+    case PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP:
935b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PATTERN_TOO_COMPLICATED:
936b5975d6bSopenharmony_ci+    case PCRE2_ERROR_LOOKBEHIND_TOO_LONG:
937b5975d6bSopenharmony_ci+    case PCRE2_ERROR_PATTERN_STRING_TOO_LONG:
938b5975d6bSopenharmony_ci+    case PCRE2_ERROR_BAD_LITERAL_OPTIONS:
939b5975d6bSopenharmony_ci     default:
940b5975d6bSopenharmony_ci       *errcode = G_REGEX_ERROR_COMPILE;
941b5975d6bSopenharmony_ci+      *errmsg = _("internal error");
942b5975d6bSopenharmony_ci+      break;
943b5975d6bSopenharmony_ci     }
944b5975d6bSopenharmony_ci+
945b5975d6bSopenharmony_ci+  g_assert (*errcode != 0);
946b5975d6bSopenharmony_ci+  g_assert (*errmsg != NULL);
947b5975d6bSopenharmony_ci }
948b5975d6bSopenharmony_ci 
949b5975d6bSopenharmony_ci /* GMatchInfo */
950b5975d6bSopenharmony_ci@@ -568,12 +747,16 @@ match_info_new (const GRegex *regex,
951b5975d6bSopenharmony_ci   match_info->regex = g_regex_ref ((GRegex *)regex);
952b5975d6bSopenharmony_ci   match_info->string = string;
953b5975d6bSopenharmony_ci   match_info->string_len = string_len;
954b5975d6bSopenharmony_ci-  match_info->matches = PCRE_ERROR_NOMATCH;
955b5975d6bSopenharmony_ci+  match_info->matches = PCRE2_ERROR_NOMATCH;
956b5975d6bSopenharmony_ci   match_info->pos = start_position;
957b5975d6bSopenharmony_ci   match_info->match_opts = match_options;
958b5975d6bSopenharmony_ci 
959b5975d6bSopenharmony_ci-  pcre_fullinfo (regex->pcre_re, regex->extra,
960b5975d6bSopenharmony_ci-                 PCRE_INFO_CAPTURECOUNT, &match_info->n_subpatterns);
961b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_CAPTURECOUNT,
962b5975d6bSopenharmony_ci+                      &match_info->n_subpatterns);
963b5975d6bSopenharmony_ci+
964b5975d6bSopenharmony_ci+  match_info->match_context = pcre2_match_context_create (NULL);
965b5975d6bSopenharmony_ci+  pcre2_set_match_limit (match_info->match_context, 65536); /* should be plenty */
966b5975d6bSopenharmony_ci+  pcre2_set_recursion_limit (match_info->match_context, 64); /* should be plenty */
967b5975d6bSopenharmony_ci 
968b5975d6bSopenharmony_ci   if (is_dfa)
969b5975d6bSopenharmony_ci     {
970b5975d6bSopenharmony_ci@@ -593,9 +776,41 @@ match_info_new (const GRegex *regex,
971b5975d6bSopenharmony_ci   match_info->offsets[0] = -1;
972b5975d6bSopenharmony_ci   match_info->offsets[1] = -1;
973b5975d6bSopenharmony_ci 
974b5975d6bSopenharmony_ci+  match_info->match_data = pcre2_match_data_create_from_pattern (
975b5975d6bSopenharmony_ci+      match_info->regex->pcre_re,
976b5975d6bSopenharmony_ci+      NULL);
977b5975d6bSopenharmony_ci+
978b5975d6bSopenharmony_ci   return match_info;
979b5975d6bSopenharmony_ci }
980b5975d6bSopenharmony_ci 
981b5975d6bSopenharmony_ci+static gboolean
982b5975d6bSopenharmony_ci+recalc_match_offsets (GMatchInfo *match_info,
983b5975d6bSopenharmony_ci+                      GError     **error)
984b5975d6bSopenharmony_ci+{
985b5975d6bSopenharmony_ci+  PCRE2_SIZE *ovector;
986b5975d6bSopenharmony_ci+  gint i;
987b5975d6bSopenharmony_ci+
988b5975d6bSopenharmony_ci+  if (pcre2_get_ovector_count (match_info->match_data) > G_MAXINT / 2)
989b5975d6bSopenharmony_ci+    {
990b5975d6bSopenharmony_ci+      g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
991b5975d6bSopenharmony_ci+                   _("Error while matching regular expression %s: %s"),
992b5975d6bSopenharmony_ci+                   match_info->regex->pattern, _("code overflow"));
993b5975d6bSopenharmony_ci+      return FALSE;
994b5975d6bSopenharmony_ci+    }
995b5975d6bSopenharmony_ci+
996b5975d6bSopenharmony_ci+  match_info->n_offsets = pcre2_get_ovector_count (match_info->match_data) * 2;
997b5975d6bSopenharmony_ci+  ovector = pcre2_get_ovector_pointer (match_info->match_data);
998b5975d6bSopenharmony_ci+  match_info->offsets = g_realloc_n (match_info->offsets,
999b5975d6bSopenharmony_ci+                                     match_info->n_offsets,
1000b5975d6bSopenharmony_ci+                                     sizeof (gint));
1001b5975d6bSopenharmony_ci+  for (i = 0; i < match_info->n_offsets; i++)
1002b5975d6bSopenharmony_ci+    {
1003b5975d6bSopenharmony_ci+      match_info->offsets[i] = (int) ovector[i];
1004b5975d6bSopenharmony_ci+    }
1005b5975d6bSopenharmony_ci+
1006b5975d6bSopenharmony_ci+  return TRUE;
1007b5975d6bSopenharmony_ci+}
1008b5975d6bSopenharmony_ci+
1009b5975d6bSopenharmony_ci /**
1010b5975d6bSopenharmony_ci  * g_match_info_get_regex:
1011b5975d6bSopenharmony_ci  * @match_info: a #GMatchInfo
1012b5975d6bSopenharmony_ci@@ -667,6 +882,10 @@ g_match_info_unref (GMatchInfo *match_info)
1013b5975d6bSopenharmony_ci   if (g_atomic_int_dec_and_test (&match_info->ref_count))
1014b5975d6bSopenharmony_ci     {
1015b5975d6bSopenharmony_ci       g_regex_unref (match_info->regex);
1016b5975d6bSopenharmony_ci+      if (match_info->match_context)
1017b5975d6bSopenharmony_ci+        pcre2_match_context_free (match_info->match_context);
1018b5975d6bSopenharmony_ci+      if (match_info->match_data)
1019b5975d6bSopenharmony_ci+        pcre2_match_data_free (match_info->match_data);
1020b5975d6bSopenharmony_ci       g_free (match_info->offsets);
1021b5975d6bSopenharmony_ci       g_free (match_info->workspace);
1022b5975d6bSopenharmony_ci       g_free (match_info);
1023b5975d6bSopenharmony_ci@@ -713,6 +932,7 @@ g_match_info_next (GMatchInfo  *match_info,
1024b5975d6bSopenharmony_ci {
1025b5975d6bSopenharmony_ci   gint prev_match_start;
1026b5975d6bSopenharmony_ci   gint prev_match_end;
1027b5975d6bSopenharmony_ci+  gint opts;
1028b5975d6bSopenharmony_ci 
1029b5975d6bSopenharmony_ci   g_return_val_if_fail (match_info != NULL, FALSE);
1030b5975d6bSopenharmony_ci   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1031b5975d6bSopenharmony_ci@@ -725,25 +945,29 @@ g_match_info_next (GMatchInfo  *match_info,
1032b5975d6bSopenharmony_ci     {
1033b5975d6bSopenharmony_ci       /* we have reached the end of the string */
1034b5975d6bSopenharmony_ci       match_info->pos = -1;
1035b5975d6bSopenharmony_ci-      match_info->matches = PCRE_ERROR_NOMATCH;
1036b5975d6bSopenharmony_ci+      match_info->matches = PCRE2_ERROR_NOMATCH;
1037b5975d6bSopenharmony_ci       return FALSE;
1038b5975d6bSopenharmony_ci     }
1039b5975d6bSopenharmony_ci 
1040b5975d6bSopenharmony_ci-  match_info->matches = pcre_exec (match_info->regex->pcre_re,
1041b5975d6bSopenharmony_ci-                                   match_info->regex->extra,
1042b5975d6bSopenharmony_ci-                                   match_info->string,
1043b5975d6bSopenharmony_ci-                                   match_info->string_len,
1044b5975d6bSopenharmony_ci-                                   match_info->pos,
1045b5975d6bSopenharmony_ci-                                   match_info->regex->match_opts | match_info->match_opts,
1046b5975d6bSopenharmony_ci-                                   match_info->offsets,
1047b5975d6bSopenharmony_ci-                                   match_info->n_offsets);
1048b5975d6bSopenharmony_ci-  if (IS_PCRE_ERROR (match_info->matches))
1049b5975d6bSopenharmony_ci+  opts = map_to_pcre2_match_flags (match_info->regex->match_opts | match_info->match_opts);
1050b5975d6bSopenharmony_ci+  match_info->matches = pcre2_match (match_info->regex->pcre_re,
1051b5975d6bSopenharmony_ci+                                     (PCRE2_SPTR8) match_info->string,
1052b5975d6bSopenharmony_ci+                                     match_info->string_len,
1053b5975d6bSopenharmony_ci+                                     match_info->pos,
1054b5975d6bSopenharmony_ci+                                     opts & ~G_REGEX_FLAGS_CONVERTED,
1055b5975d6bSopenharmony_ci+                                     match_info->match_data,
1056b5975d6bSopenharmony_ci+                                     match_info->match_context);
1057b5975d6bSopenharmony_ci+
1058b5975d6bSopenharmony_ci+  if (IS_PCRE2_ERROR (match_info->matches))
1059b5975d6bSopenharmony_ci     {
1060b5975d6bSopenharmony_ci       g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
1061b5975d6bSopenharmony_ci                    _("Error while matching regular expression %s: %s"),
1062b5975d6bSopenharmony_ci                    match_info->regex->pattern, match_error (match_info->matches));
1063b5975d6bSopenharmony_ci       return FALSE;
1064b5975d6bSopenharmony_ci     }
1065b5975d6bSopenharmony_ci+  else
1066b5975d6bSopenharmony_ci+    if (!recalc_match_offsets (match_info, error))
1067b5975d6bSopenharmony_ci+      return FALSE;
1068b5975d6bSopenharmony_ci 
1069b5975d6bSopenharmony_ci   /* avoid infinite loops if the pattern is an empty string or something
1070b5975d6bSopenharmony_ci    * equivalent */
1071b5975d6bSopenharmony_ci@@ -753,7 +977,7 @@ g_match_info_next (GMatchInfo  *match_info,
1072b5975d6bSopenharmony_ci         {
1073b5975d6bSopenharmony_ci           /* we have reached the end of the string */
1074b5975d6bSopenharmony_ci           match_info->pos = -1;
1075b5975d6bSopenharmony_ci-          match_info->matches = PCRE_ERROR_NOMATCH;
1076b5975d6bSopenharmony_ci+          match_info->matches = PCRE2_ERROR_NOMATCH;
1077b5975d6bSopenharmony_ci           return FALSE;
1078b5975d6bSopenharmony_ci         }
1079b5975d6bSopenharmony_ci 
1080b5975d6bSopenharmony_ci@@ -831,10 +1055,10 @@ g_match_info_get_match_count (const GMatchInfo *match_info)
1081b5975d6bSopenharmony_ci {
1082b5975d6bSopenharmony_ci   g_return_val_if_fail (match_info, -1);
1083b5975d6bSopenharmony_ci 
1084b5975d6bSopenharmony_ci-  if (match_info->matches == PCRE_ERROR_NOMATCH)
1085b5975d6bSopenharmony_ci+  if (match_info->matches == PCRE2_ERROR_NOMATCH)
1086b5975d6bSopenharmony_ci     /* no match */
1087b5975d6bSopenharmony_ci     return 0;
1088b5975d6bSopenharmony_ci-  else if (match_info->matches < PCRE_ERROR_NOMATCH)
1089b5975d6bSopenharmony_ci+  else if (match_info->matches < PCRE2_ERROR_NOMATCH)
1090b5975d6bSopenharmony_ci     /* error */
1091b5975d6bSopenharmony_ci     return -1;
1092b5975d6bSopenharmony_ci   else
1093b5975d6bSopenharmony_ci@@ -889,7 +1113,7 @@ g_match_info_is_partial_match (const GMatchInfo *match_info)
1094b5975d6bSopenharmony_ci {
1095b5975d6bSopenharmony_ci   g_return_val_if_fail (match_info != NULL, FALSE);
1096b5975d6bSopenharmony_ci 
1097b5975d6bSopenharmony_ci-  return match_info->matches == PCRE_ERROR_PARTIAL;
1098b5975d6bSopenharmony_ci+  return match_info->matches == PCRE2_ERROR_PARTIAL;
1099b5975d6bSopenharmony_ci }
1100b5975d6bSopenharmony_ci 
1101b5975d6bSopenharmony_ci /**
1102b5975d6bSopenharmony_ci@@ -986,8 +1210,6 @@ gchar *
1103b5975d6bSopenharmony_ci g_match_info_fetch (const GMatchInfo *match_info,
1104b5975d6bSopenharmony_ci                     gint              match_num)
1105b5975d6bSopenharmony_ci {
1106b5975d6bSopenharmony_ci-  /* we cannot use pcre_get_substring() because it allocates the
1107b5975d6bSopenharmony_ci-   * string using pcre_malloc(). */
1108b5975d6bSopenharmony_ci   gchar *match = NULL;
1109b5975d6bSopenharmony_ci   gint start, end;
1110b5975d6bSopenharmony_ci 
1111b5975d6bSopenharmony_ci@@ -1067,24 +1289,25 @@ g_match_info_fetch_pos (const GMatchInfo *match_info,
1112b5975d6bSopenharmony_ci  * Returns number of first matched subpattern with name @name.
1113b5975d6bSopenharmony_ci  * There may be more than one in case when DUPNAMES is used,
1114b5975d6bSopenharmony_ci  * and not all subpatterns with that name match;
1115b5975d6bSopenharmony_ci- * pcre_get_stringnumber() does not work in that case.
1116b5975d6bSopenharmony_ci+ * pcre2_substring_number_from_name() does not work in that case.
1117b5975d6bSopenharmony_ci  */
1118b5975d6bSopenharmony_ci static gint
1119b5975d6bSopenharmony_ci get_matched_substring_number (const GMatchInfo *match_info,
1120b5975d6bSopenharmony_ci                               const gchar      *name)
1121b5975d6bSopenharmony_ci {
1122b5975d6bSopenharmony_ci   gint entrysize;
1123b5975d6bSopenharmony_ci-  gchar *first, *last;
1124b5975d6bSopenharmony_ci+  PCRE2_SPTR first, last;
1125b5975d6bSopenharmony_ci   guchar *entry;
1126b5975d6bSopenharmony_ci 
1127b5975d6bSopenharmony_ci-  if (!(match_info->regex->compile_opts & G_REGEX_DUPNAMES))
1128b5975d6bSopenharmony_ci-    return pcre_get_stringnumber (match_info->regex->pcre_re, name);
1129b5975d6bSopenharmony_ci+  if (!(match_info->regex->compile_opts & PCRE2_DUPNAMES))
1130b5975d6bSopenharmony_ci+    return pcre2_substring_number_from_name (match_info->regex->pcre_re, (PCRE2_SPTR8) name);
1131b5975d6bSopenharmony_ci 
1132b5975d6bSopenharmony_ci-  /* This code is copied from pcre_get.c: get_first_set() */
1133b5975d6bSopenharmony_ci-  entrysize = pcre_get_stringtable_entries (match_info->regex->pcre_re,
1134b5975d6bSopenharmony_ci-                                            name,
1135b5975d6bSopenharmony_ci-                                            &first,
1136b5975d6bSopenharmony_ci-                                            &last);
1137b5975d6bSopenharmony_ci+  /* This code is analogous to code from pcre2_substring.c:
1138b5975d6bSopenharmony_ci+   * pcre2_substring_get_byname() */
1139b5975d6bSopenharmony_ci+  entrysize = pcre2_substring_nametable_scan (match_info->regex->pcre_re,
1140b5975d6bSopenharmony_ci+                                              (PCRE2_SPTR8) name,
1141b5975d6bSopenharmony_ci+                                              &first,
1142b5975d6bSopenharmony_ci+                                              &last);
1143b5975d6bSopenharmony_ci 
1144b5975d6bSopenharmony_ci   if (entrysize <= 0)
1145b5975d6bSopenharmony_ci     return entrysize;
1146b5975d6bSopenharmony_ci@@ -1122,8 +1345,6 @@ gchar *
1147b5975d6bSopenharmony_ci g_match_info_fetch_named (const GMatchInfo *match_info,
1148b5975d6bSopenharmony_ci                           const gchar      *name)
1149b5975d6bSopenharmony_ci {
1150b5975d6bSopenharmony_ci-  /* we cannot use pcre_get_named_substring() because it allocates the
1151b5975d6bSopenharmony_ci-   * string using pcre_malloc(). */
1152b5975d6bSopenharmony_ci   gint num;
1153b5975d6bSopenharmony_ci 
1154b5975d6bSopenharmony_ci   g_return_val_if_fail (match_info != NULL, NULL);
1155b5975d6bSopenharmony_ci@@ -1205,8 +1426,6 @@ g_match_info_fetch_named_pos (const GMatchInfo *match_info,
1156b5975d6bSopenharmony_ci gchar **
1157b5975d6bSopenharmony_ci g_match_info_fetch_all (const GMatchInfo *match_info)
1158b5975d6bSopenharmony_ci {
1159b5975d6bSopenharmony_ci-  /* we cannot use pcre_get_substring_list() because the returned value
1160b5975d6bSopenharmony_ci-   * isn't suitable for g_strfreev(). */
1161b5975d6bSopenharmony_ci   gchar **result;
1162b5975d6bSopenharmony_ci   gint i;
1163b5975d6bSopenharmony_ci 
1164b5975d6bSopenharmony_ci@@ -1264,9 +1483,7 @@ g_regex_unref (GRegex *regex)
1165b5975d6bSopenharmony_ci     {
1166b5975d6bSopenharmony_ci       g_free (regex->pattern);
1167b5975d6bSopenharmony_ci       if (regex->pcre_re != NULL)
1168b5975d6bSopenharmony_ci-        pcre_free (regex->pcre_re);
1169b5975d6bSopenharmony_ci-      if (regex->extra != NULL)
1170b5975d6bSopenharmony_ci-        pcre_free (regex->extra);
1171b5975d6bSopenharmony_ci+        pcre2_code_free (regex->pcre_re);
1172b5975d6bSopenharmony_ci       g_free (regex);
1173b5975d6bSopenharmony_ci     }
1174b5975d6bSopenharmony_ci }
1175b5975d6bSopenharmony_ci@@ -1274,11 +1491,11 @@ g_regex_unref (GRegex *regex)
1176b5975d6bSopenharmony_ci /*
1177b5975d6bSopenharmony_ci  * @match_options: (inout) (optional):
1178b5975d6bSopenharmony_ci  */
1179b5975d6bSopenharmony_ci-static pcre *regex_compile (const gchar         *pattern,
1180b5975d6bSopenharmony_ci-                            GRegexCompileFlags   compile_options,
1181b5975d6bSopenharmony_ci-                            GRegexCompileFlags  *compile_options_out,
1182b5975d6bSopenharmony_ci-                            GRegexMatchFlags    *match_options,
1183b5975d6bSopenharmony_ci-                            GError             **error);
1184b5975d6bSopenharmony_ci+static pcre2_code *regex_compile (const gchar *pattern,
1185b5975d6bSopenharmony_ci+                                  GRegexCompileFlags compile_options,
1186b5975d6bSopenharmony_ci+                                  GRegexCompileFlags *compile_options_out,
1187b5975d6bSopenharmony_ci+                                  GRegexMatchFlags *match_options,
1188b5975d6bSopenharmony_ci+                                  GError **error);
1189b5975d6bSopenharmony_ci 
1190b5975d6bSopenharmony_ci /**
1191b5975d6bSopenharmony_ci  * g_regex_new:
1192b5975d6bSopenharmony_ci@@ -1302,10 +1519,13 @@ g_regex_new (const gchar         *pattern,
1193b5975d6bSopenharmony_ci              GError             **error)
1194b5975d6bSopenharmony_ci {
1195b5975d6bSopenharmony_ci   GRegex *regex;
1196b5975d6bSopenharmony_ci-  pcre *re;
1197b5975d6bSopenharmony_ci-  const gchar *errmsg;
1198b5975d6bSopenharmony_ci-  gboolean optimize = FALSE;
1199b5975d6bSopenharmony_ci+  pcre2_code *re;
1200b5975d6bSopenharmony_ci   static gsize initialised = 0;
1201b5975d6bSopenharmony_ci+  GRegexCompileFlags orig_compile_opts;
1202b5975d6bSopenharmony_ci+
1203b5975d6bSopenharmony_ci+  orig_compile_opts = compile_options;
1204b5975d6bSopenharmony_ci+  compile_options = map_to_pcre2_compile_flags (compile_options);
1205b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1206b5975d6bSopenharmony_ci 
1207b5975d6bSopenharmony_ci   g_return_val_if_fail (pattern != NULL, NULL);
1208b5975d6bSopenharmony_ci   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1209b5975d6bSopenharmony_ci@@ -1314,17 +1534,13 @@ g_regex_new (const gchar         *pattern,
1210b5975d6bSopenharmony_ci 
1211b5975d6bSopenharmony_ci   if (g_once_init_enter (&initialised))
1212b5975d6bSopenharmony_ci     {
1213b5975d6bSopenharmony_ci-      int supports_utf8, supports_ucp;
1214b5975d6bSopenharmony_ci+      int supports_utf8;
1215b5975d6bSopenharmony_ci 
1216b5975d6bSopenharmony_ci-      pcre_config (PCRE_CONFIG_UTF8, &supports_utf8);
1217b5975d6bSopenharmony_ci+      pcre2_config (PCRE2_CONFIG_UNICODE, &supports_utf8);
1218b5975d6bSopenharmony_ci       if (!supports_utf8)
1219b5975d6bSopenharmony_ci         g_critical (_("PCRE library is compiled without UTF8 support"));
1220b5975d6bSopenharmony_ci 
1221b5975d6bSopenharmony_ci-      pcre_config (PCRE_CONFIG_UNICODE_PROPERTIES, &supports_ucp);
1222b5975d6bSopenharmony_ci-      if (!supports_ucp)
1223b5975d6bSopenharmony_ci-        g_critical (_("PCRE library is compiled without UTF8 properties support"));
1224b5975d6bSopenharmony_ci-
1225b5975d6bSopenharmony_ci-      g_once_init_leave (&initialised, supports_utf8 && supports_ucp ? 1 : 2);
1226b5975d6bSopenharmony_ci+      g_once_init_leave (&initialised, supports_utf8 ? 1 : 2);
1227b5975d6bSopenharmony_ci     }
1228b5975d6bSopenharmony_ci 
1229b5975d6bSopenharmony_ci   if (G_UNLIKELY (initialised != 1)) 
1230b5975d6bSopenharmony_ci@@ -1334,14 +1550,22 @@ g_regex_new (const gchar         *pattern,
1231b5975d6bSopenharmony_ci       return NULL;
1232b5975d6bSopenharmony_ci     }
1233b5975d6bSopenharmony_ci 
1234b5975d6bSopenharmony_ci-  /* G_REGEX_OPTIMIZE has the same numeric value of PCRE_NO_UTF8_CHECK,
1235b5975d6bSopenharmony_ci-   * as we do not need to wrap PCRE_NO_UTF8_CHECK. */
1236b5975d6bSopenharmony_ci-  if (compile_options & G_REGEX_OPTIMIZE)
1237b5975d6bSopenharmony_ci-    optimize = TRUE;
1238b5975d6bSopenharmony_ci+  switch (compile_options & G_REGEX_NEWLINE_MASK)
1239b5975d6bSopenharmony_ci+    {
1240b5975d6bSopenharmony_ci+    case 0: /* PCRE2_NEWLINE_ANY */
1241b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_CR:
1242b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_LF:
1243b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_CRLF:
1244b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_ANYCRLF:
1245b5975d6bSopenharmony_ci+      break;
1246b5975d6bSopenharmony_ci+    default:
1247b5975d6bSopenharmony_ci+      g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS,
1248b5975d6bSopenharmony_ci+                   "Invalid newline flags");
1249b5975d6bSopenharmony_ci+      return NULL;
1250b5975d6bSopenharmony_ci+    }
1251b5975d6bSopenharmony_ci 
1252b5975d6bSopenharmony_ci   re = regex_compile (pattern, compile_options, &compile_options,
1253b5975d6bSopenharmony_ci                       &match_options, error);
1254b5975d6bSopenharmony_ci-
1255b5975d6bSopenharmony_ci   if (re == NULL)
1256b5975d6bSopenharmony_ci     return NULL;
1257b5975d6bSopenharmony_ci 
1258b5975d6bSopenharmony_ci@@ -1350,80 +1574,85 @@ g_regex_new (const gchar         *pattern,
1259b5975d6bSopenharmony_ci   regex->pattern = g_strdup (pattern);
1260b5975d6bSopenharmony_ci   regex->pcre_re = re;
1261b5975d6bSopenharmony_ci   regex->compile_opts = compile_options;
1262b5975d6bSopenharmony_ci+  regex->orig_compile_opts = orig_compile_opts;
1263b5975d6bSopenharmony_ci   regex->match_opts = match_options;
1264b5975d6bSopenharmony_ci 
1265b5975d6bSopenharmony_ci-  if (optimize)
1266b5975d6bSopenharmony_ci-    {
1267b5975d6bSopenharmony_ci-      regex->extra = pcre_study (regex->pcre_re, 0, &errmsg);
1268b5975d6bSopenharmony_ci-      if (errmsg != NULL)
1269b5975d6bSopenharmony_ci-        {
1270b5975d6bSopenharmony_ci-          GError *tmp_error = g_error_new (G_REGEX_ERROR,
1271b5975d6bSopenharmony_ci-                                           G_REGEX_ERROR_OPTIMIZE,
1272b5975d6bSopenharmony_ci-                                           _("Error while optimizing "
1273b5975d6bSopenharmony_ci-                                             "regular expression %s: %s"),
1274b5975d6bSopenharmony_ci-                                           regex->pattern,
1275b5975d6bSopenharmony_ci-                                           errmsg);
1276b5975d6bSopenharmony_ci-          g_propagate_error (error, tmp_error);
1277b5975d6bSopenharmony_ci-
1278b5975d6bSopenharmony_ci-          g_regex_unref (regex);
1279b5975d6bSopenharmony_ci-          return NULL;
1280b5975d6bSopenharmony_ci-        }
1281b5975d6bSopenharmony_ci-    }
1282b5975d6bSopenharmony_ci-
1283b5975d6bSopenharmony_ci   return regex;
1284b5975d6bSopenharmony_ci }
1285b5975d6bSopenharmony_ci 
1286b5975d6bSopenharmony_ci-static pcre *
1287b5975d6bSopenharmony_ci-regex_compile (const gchar         *pattern,
1288b5975d6bSopenharmony_ci-               GRegexCompileFlags   compile_options,
1289b5975d6bSopenharmony_ci-               GRegexCompileFlags  *compile_options_out,
1290b5975d6bSopenharmony_ci-               GRegexMatchFlags    *match_options,
1291b5975d6bSopenharmony_ci-               GError             **error)
1292b5975d6bSopenharmony_ci+static gint
1293b5975d6bSopenharmony_ci+extract_newline_options (const GRegexCompileFlags compile_options,
1294b5975d6bSopenharmony_ci+                         const GRegexMatchFlags *match_options)
1295b5975d6bSopenharmony_ci+{
1296b5975d6bSopenharmony_ci+  gint newline_options = PCRE2_NEWLINE_ANY;
1297b5975d6bSopenharmony_ci+
1298b5975d6bSopenharmony_ci+  if (compile_options & G_REGEX_NEWLINE_MASK)
1299b5975d6bSopenharmony_ci+    newline_options = compile_options & G_REGEX_NEWLINE_MASK;
1300b5975d6bSopenharmony_ci+  if (match_options && *match_options & G_REGEX_MATCH_NEWLINE_MASK)
1301b5975d6bSopenharmony_ci+    newline_options = *match_options & G_REGEX_MATCH_NEWLINE_MASK;
1302b5975d6bSopenharmony_ci+
1303b5975d6bSopenharmony_ci+  return newline_options;
1304b5975d6bSopenharmony_ci+}
1305b5975d6bSopenharmony_ci+
1306b5975d6bSopenharmony_ci+static gint
1307b5975d6bSopenharmony_ci+extract_bsr_options (const GRegexCompileFlags compile_options,
1308b5975d6bSopenharmony_ci+                     const GRegexMatchFlags *match_options)
1309b5975d6bSopenharmony_ci+{
1310b5975d6bSopenharmony_ci+  gint bsr_options = PCRE2_BSR_UNICODE;
1311b5975d6bSopenharmony_ci+
1312b5975d6bSopenharmony_ci+  if (compile_options & PCRE2_BSR_ANYCRLF)
1313b5975d6bSopenharmony_ci+    bsr_options = PCRE2_BSR_ANYCRLF;
1314b5975d6bSopenharmony_ci+  if (match_options && *match_options & PCRE2_BSR_ANYCRLF)
1315b5975d6bSopenharmony_ci+    bsr_options = PCRE2_BSR_ANYCRLF;
1316b5975d6bSopenharmony_ci+  if (match_options && *match_options & PCRE2_BSR_UNICODE)
1317b5975d6bSopenharmony_ci+    bsr_options = PCRE2_BSR_UNICODE;
1318b5975d6bSopenharmony_ci+
1319b5975d6bSopenharmony_ci+  return bsr_options;
1320b5975d6bSopenharmony_ci+}
1321b5975d6bSopenharmony_ci+
1322b5975d6bSopenharmony_ci+static pcre2_code *
1323b5975d6bSopenharmony_ci+regex_compile (const gchar *pattern,
1324b5975d6bSopenharmony_ci+               GRegexCompileFlags compile_options,
1325b5975d6bSopenharmony_ci+               GRegexCompileFlags *compile_options_out,
1326b5975d6bSopenharmony_ci+               GRegexMatchFlags *match_options,
1327b5975d6bSopenharmony_ci+               GError **error)
1328b5975d6bSopenharmony_ci {
1329b5975d6bSopenharmony_ci-  pcre *re;
1330b5975d6bSopenharmony_ci+  pcre2_code *re;
1331b5975d6bSopenharmony_ci+  pcre2_compile_context *context;
1332b5975d6bSopenharmony_ci   const gchar *errmsg;
1333b5975d6bSopenharmony_ci-  gint erroffset;
1334b5975d6bSopenharmony_ci+  PCRE2_SIZE erroffset;
1335b5975d6bSopenharmony_ci   gint errcode;
1336b5975d6bSopenharmony_ci   GRegexCompileFlags nonpcre_compile_options;
1337b5975d6bSopenharmony_ci   unsigned long int pcre_compile_options;
1338b5975d6bSopenharmony_ci 
1339b5975d6bSopenharmony_ci   nonpcre_compile_options = compile_options & G_REGEX_COMPILE_NONPCRE_MASK;
1340b5975d6bSopenharmony_ci 
1341b5975d6bSopenharmony_ci-  /* In GRegex the string are, by default, UTF-8 encoded. PCRE
1342b5975d6bSopenharmony_ci-   * instead uses UTF-8 only if required with PCRE_UTF8. */
1343b5975d6bSopenharmony_ci-  if (compile_options & G_REGEX_RAW)
1344b5975d6bSopenharmony_ci-    {
1345b5975d6bSopenharmony_ci-      /* disable utf-8 */
1346b5975d6bSopenharmony_ci-      compile_options &= ~G_REGEX_RAW;
1347b5975d6bSopenharmony_ci-    }
1348b5975d6bSopenharmony_ci-  else
1349b5975d6bSopenharmony_ci-    {
1350b5975d6bSopenharmony_ci-      /* enable utf-8 */
1351b5975d6bSopenharmony_ci-      compile_options |= PCRE_UTF8 | PCRE_NO_UTF8_CHECK;
1352b5975d6bSopenharmony_ci+  context = pcre2_compile_context_create (NULL);
1353b5975d6bSopenharmony_ci 
1354b5975d6bSopenharmony_ci-      if (match_options != NULL)
1355b5975d6bSopenharmony_ci-        *match_options |= PCRE_NO_UTF8_CHECK;
1356b5975d6bSopenharmony_ci-    }
1357b5975d6bSopenharmony_ci+  /* set newline options */
1358b5975d6bSopenharmony_ci+  pcre2_set_newline (context, extract_newline_options (compile_options, match_options));
1359b5975d6bSopenharmony_ci+
1360b5975d6bSopenharmony_ci+  /* set bsr options */
1361b5975d6bSopenharmony_ci+  pcre2_set_bsr (context, extract_bsr_options (compile_options, match_options));
1362b5975d6bSopenharmony_ci 
1363b5975d6bSopenharmony_ci-  /* PCRE_NEWLINE_ANY is the default for the internal PCRE but
1364b5975d6bSopenharmony_ci-   * not for the system one. */
1365b5975d6bSopenharmony_ci-  if (!(compile_options & G_REGEX_NEWLINE_CR) &&
1366b5975d6bSopenharmony_ci-      !(compile_options & G_REGEX_NEWLINE_LF))
1367b5975d6bSopenharmony_ci+  /* In case UTF-8 mode is used, also set PCRE2_NO_UTF_CHECK */
1368b5975d6bSopenharmony_ci+  if (compile_options & PCRE2_UTF)
1369b5975d6bSopenharmony_ci     {
1370b5975d6bSopenharmony_ci-      compile_options |= PCRE_NEWLINE_ANY;
1371b5975d6bSopenharmony_ci+      compile_options |= PCRE2_NO_UTF_CHECK;
1372b5975d6bSopenharmony_ci+      if (match_options != NULL)
1373b5975d6bSopenharmony_ci+        *match_options |= PCRE2_NO_UTF_CHECK;
1374b5975d6bSopenharmony_ci     }
1375b5975d6bSopenharmony_ci 
1376b5975d6bSopenharmony_ci-  compile_options |= PCRE_UCP;
1377b5975d6bSopenharmony_ci-
1378b5975d6bSopenharmony_ci-  /* PCRE_BSR_UNICODE is the default for the internal PCRE but
1379b5975d6bSopenharmony_ci-   * possibly not for the system one.
1380b5975d6bSopenharmony_ci-   */
1381b5975d6bSopenharmony_ci-  if (~compile_options & G_REGEX_BSR_ANYCRLF)
1382b5975d6bSopenharmony_ci-    compile_options |= PCRE_BSR_UNICODE;
1383b5975d6bSopenharmony_ci+  compile_options |= PCRE2_UCP;
1384b5975d6bSopenharmony_ci 
1385b5975d6bSopenharmony_ci   /* compile the pattern */
1386b5975d6bSopenharmony_ci-  re = pcre_compile2 (pattern, compile_options, &errcode,
1387b5975d6bSopenharmony_ci-                      &errmsg, &erroffset, NULL);
1388b5975d6bSopenharmony_ci+  re = pcre2_compile ((PCRE2_SPTR8) pattern,
1389b5975d6bSopenharmony_ci+                      PCRE2_ZERO_TERMINATED,
1390b5975d6bSopenharmony_ci+                      compile_options & ~G_REGEX_FLAGS_CONVERTED,
1391b5975d6bSopenharmony_ci+                      &errcode,
1392b5975d6bSopenharmony_ci+                      &erroffset,
1393b5975d6bSopenharmony_ci+                      context);
1394b5975d6bSopenharmony_ci+  pcre2_compile_context_free (context);
1395b5975d6bSopenharmony_ci 
1396b5975d6bSopenharmony_ci   /* if the compilation failed, set the error member and return
1397b5975d6bSopenharmony_ci    * immediately */
1398b5975d6bSopenharmony_ci@@ -1440,7 +1669,7 @@ regex_compile (const gchar         *pattern,
1399b5975d6bSopenharmony_ci 
1400b5975d6bSopenharmony_ci       tmp_error = g_error_new (G_REGEX_ERROR, errcode,
1401b5975d6bSopenharmony_ci                                _("Error while compiling regular "
1402b5975d6bSopenharmony_ci-                                 "expression %s at char %d: %s"),
1403b5975d6bSopenharmony_ci+                                 "expression %s at char %" G_GSIZE_FORMAT ": %s"),
1404b5975d6bSopenharmony_ci                                pattern, erroffset, errmsg);
1405b5975d6bSopenharmony_ci       g_propagate_error (error, tmp_error);
1406b5975d6bSopenharmony_ci 
1407b5975d6bSopenharmony_ci@@ -1449,22 +1678,22 @@ regex_compile (const gchar         *pattern,
1408b5975d6bSopenharmony_ci 
1409b5975d6bSopenharmony_ci   /* For options set at the beginning of the pattern, pcre puts them into
1410b5975d6bSopenharmony_ci    * compile options, e.g. "(?i)foo" will make the pcre structure store
1411b5975d6bSopenharmony_ci-   * PCRE_CASELESS even though it wasn't explicitly given for compilation. */
1412b5975d6bSopenharmony_ci-  pcre_fullinfo (re, NULL, PCRE_INFO_OPTIONS, &pcre_compile_options);
1413b5975d6bSopenharmony_ci+   * PCRE2_CASELESS even though it wasn't explicitly given for compilation. */
1414b5975d6bSopenharmony_ci+  pcre2_pattern_info (re, PCRE2_INFO_ALLOPTIONS, &pcre_compile_options);
1415b5975d6bSopenharmony_ci   compile_options = pcre_compile_options & G_REGEX_COMPILE_PCRE_MASK;
1416b5975d6bSopenharmony_ci 
1417b5975d6bSopenharmony_ci-  /* Don't leak PCRE_NEWLINE_ANY, which is part of PCRE_NEWLINE_ANYCRLF */
1418b5975d6bSopenharmony_ci-  if ((pcre_compile_options & PCRE_NEWLINE_ANYCRLF) != PCRE_NEWLINE_ANYCRLF)
1419b5975d6bSopenharmony_ci-    compile_options &= ~PCRE_NEWLINE_ANY;
1420b5975d6bSopenharmony_ci+  /* Don't leak PCRE2_NEWLINE_ANY, which is part of PCRE2_NEWLINE_ANYCRLF */
1421b5975d6bSopenharmony_ci+  if ((pcre_compile_options & PCRE2_NEWLINE_ANYCRLF) != PCRE2_NEWLINE_ANYCRLF)
1422b5975d6bSopenharmony_ci+    compile_options &= ~PCRE2_NEWLINE_ANY;
1423b5975d6bSopenharmony_ci 
1424b5975d6bSopenharmony_ci   compile_options |= nonpcre_compile_options;
1425b5975d6bSopenharmony_ci 
1426b5975d6bSopenharmony_ci-  if (!(compile_options & G_REGEX_DUPNAMES))
1427b5975d6bSopenharmony_ci+  if (!(compile_options & PCRE2_DUPNAMES))
1428b5975d6bSopenharmony_ci     {
1429b5975d6bSopenharmony_ci       gboolean jchanged = FALSE;
1430b5975d6bSopenharmony_ci-      pcre_fullinfo (re, NULL, PCRE_INFO_JCHANGED, &jchanged);
1431b5975d6bSopenharmony_ci+      pcre2_pattern_info (re, PCRE2_INFO_JCHANGED, &jchanged);
1432b5975d6bSopenharmony_ci       if (jchanged)
1433b5975d6bSopenharmony_ci-        compile_options |= G_REGEX_DUPNAMES;
1434b5975d6bSopenharmony_ci+        compile_options |= PCRE2_DUPNAMES;
1435b5975d6bSopenharmony_ci     }
1436b5975d6bSopenharmony_ci 
1437b5975d6bSopenharmony_ci   if (compile_options_out != 0)
1438b5975d6bSopenharmony_ci@@ -1509,8 +1738,7 @@ g_regex_get_max_backref (const GRegex *regex)
1439b5975d6bSopenharmony_ci {
1440b5975d6bSopenharmony_ci   gint value;
1441b5975d6bSopenharmony_ci 
1442b5975d6bSopenharmony_ci-  pcre_fullinfo (regex->pcre_re, regex->extra,
1443b5975d6bSopenharmony_ci-                 PCRE_INFO_BACKREFMAX, &value);
1444b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_BACKREFMAX, &value);
1445b5975d6bSopenharmony_ci 
1446b5975d6bSopenharmony_ci   return value;
1447b5975d6bSopenharmony_ci }
1448b5975d6bSopenharmony_ci@@ -1530,8 +1758,7 @@ g_regex_get_capture_count (const GRegex *regex)
1449b5975d6bSopenharmony_ci {
1450b5975d6bSopenharmony_ci   gint value;
1451b5975d6bSopenharmony_ci 
1452b5975d6bSopenharmony_ci-  pcre_fullinfo (regex->pcre_re, regex->extra,
1453b5975d6bSopenharmony_ci-                 PCRE_INFO_CAPTURECOUNT, &value);
1454b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_CAPTURECOUNT, &value);
1455b5975d6bSopenharmony_ci 
1456b5975d6bSopenharmony_ci   return value;
1457b5975d6bSopenharmony_ci }
1458b5975d6bSopenharmony_ci@@ -1551,8 +1778,7 @@ g_regex_get_has_cr_or_lf (const GRegex *regex)
1459b5975d6bSopenharmony_ci {
1460b5975d6bSopenharmony_ci   gint value;
1461b5975d6bSopenharmony_ci 
1462b5975d6bSopenharmony_ci-  pcre_fullinfo (regex->pcre_re, regex->extra,
1463b5975d6bSopenharmony_ci-                 PCRE_INFO_HASCRORLF, &value);
1464b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_HASCRORLF, &value);
1465b5975d6bSopenharmony_ci 
1466b5975d6bSopenharmony_ci   return !!value;
1467b5975d6bSopenharmony_ci }
1468b5975d6bSopenharmony_ci@@ -1574,8 +1800,8 @@ g_regex_get_max_lookbehind (const GRegex *regex)
1469b5975d6bSopenharmony_ci {
1470b5975d6bSopenharmony_ci   gint max_lookbehind;
1471b5975d6bSopenharmony_ci 
1472b5975d6bSopenharmony_ci-  pcre_fullinfo (regex->pcre_re, regex->extra,
1473b5975d6bSopenharmony_ci-                 PCRE_INFO_MAXLOOKBEHIND, &max_lookbehind);
1474b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_MAXLOOKBEHIND,
1475b5975d6bSopenharmony_ci+                      &max_lookbehind);
1476b5975d6bSopenharmony_ci 
1477b5975d6bSopenharmony_ci   return max_lookbehind;
1478b5975d6bSopenharmony_ci }
1479b5975d6bSopenharmony_ci@@ -1597,9 +1823,47 @@ g_regex_get_max_lookbehind (const GRegex *regex)
1480b5975d6bSopenharmony_ci GRegexCompileFlags
1481b5975d6bSopenharmony_ci g_regex_get_compile_flags (const GRegex *regex)
1482b5975d6bSopenharmony_ci {
1483b5975d6bSopenharmony_ci+  gint extra_flags, info_value;
1484b5975d6bSopenharmony_ci+
1485b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, 0);
1486b5975d6bSopenharmony_ci 
1487b5975d6bSopenharmony_ci-  return regex->compile_opts;
1488b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1489b5975d6bSopenharmony_ci+  /* Preserve original G_REGEX_OPTIMIZE */
1490b5975d6bSopenharmony_ci+  extra_flags = (regex->orig_compile_opts & G_REGEX_OPTIMIZE);
1491b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
1492b5975d6bSopenharmony_ci+
1493b5975d6bSopenharmony_ci+  /* Also include the newline options */
1494b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_NEWLINE, &info_value);
1495b5975d6bSopenharmony_ci+  switch (info_value)
1496b5975d6bSopenharmony_ci+    {
1497b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_ANYCRLF:
1498b5975d6bSopenharmony_ci+      extra_flags |= G_REGEX_NEWLINE_ANYCRLF;
1499b5975d6bSopenharmony_ci+      break;
1500b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_CRLF:
1501b5975d6bSopenharmony_ci+      extra_flags |= G_REGEX_NEWLINE_CRLF;
1502b5975d6bSopenharmony_ci+      break;
1503b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_LF:
1504b5975d6bSopenharmony_ci+      extra_flags |= G_REGEX_NEWLINE_LF;
1505b5975d6bSopenharmony_ci+      break;
1506b5975d6bSopenharmony_ci+    case PCRE2_NEWLINE_CR:
1507b5975d6bSopenharmony_ci+      extra_flags |= G_REGEX_NEWLINE_CR;
1508b5975d6bSopenharmony_ci+      break;
1509b5975d6bSopenharmony_ci+    default:
1510b5975d6bSopenharmony_ci+      break;
1511b5975d6bSopenharmony_ci+    }
1512b5975d6bSopenharmony_ci+
1513b5975d6bSopenharmony_ci+  /* Also include the bsr options */
1514b5975d6bSopenharmony_ci+  pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_BSR, &info_value);
1515b5975d6bSopenharmony_ci+  switch (info_value)
1516b5975d6bSopenharmony_ci+    {
1517b5975d6bSopenharmony_ci+    case PCRE2_BSR_ANYCRLF:
1518b5975d6bSopenharmony_ci+      extra_flags |= G_REGEX_BSR_ANYCRLF;
1519b5975d6bSopenharmony_ci+      break;
1520b5975d6bSopenharmony_ci+    default:
1521b5975d6bSopenharmony_ci+      break;
1522b5975d6bSopenharmony_ci+    }
1523b5975d6bSopenharmony_ci+
1524b5975d6bSopenharmony_ci+  return map_to_pcre1_compile_flags (regex->compile_opts) | extra_flags;
1525b5975d6bSopenharmony_ci }
1526b5975d6bSopenharmony_ci 
1527b5975d6bSopenharmony_ci /**
1528b5975d6bSopenharmony_ci@@ -1617,7 +1881,7 @@ g_regex_get_match_flags (const GRegex *regex)
1529b5975d6bSopenharmony_ci {
1530b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, 0);
1531b5975d6bSopenharmony_ci 
1532b5975d6bSopenharmony_ci-  return regex->match_opts & G_REGEX_MATCH_MASK;
1533b5975d6bSopenharmony_ci+  return map_to_pcre1_match_flags (regex->match_opts & G_REGEX_MATCH_MASK);
1534b5975d6bSopenharmony_ci }
1535b5975d6bSopenharmony_ci 
1536b5975d6bSopenharmony_ci /**
1537b5975d6bSopenharmony_ci@@ -1651,6 +1915,9 @@ g_regex_match_simple (const gchar        *pattern,
1538b5975d6bSopenharmony_ci   GRegex *regex;
1539b5975d6bSopenharmony_ci   gboolean result;
1540b5975d6bSopenharmony_ci 
1541b5975d6bSopenharmony_ci+  compile_options = map_to_pcre2_compile_flags (compile_options);
1542b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1543b5975d6bSopenharmony_ci+
1544b5975d6bSopenharmony_ci   regex = g_regex_new (pattern, compile_options, G_REGEX_MATCH_DEFAULT, NULL);
1545b5975d6bSopenharmony_ci   if (!regex)
1546b5975d6bSopenharmony_ci     return FALSE;
1547b5975d6bSopenharmony_ci@@ -1718,6 +1985,8 @@ g_regex_match (const GRegex      *regex,
1548b5975d6bSopenharmony_ci                GRegexMatchFlags   match_options,
1549b5975d6bSopenharmony_ci                GMatchInfo       **match_info)
1550b5975d6bSopenharmony_ci {
1551b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1552b5975d6bSopenharmony_ci+
1553b5975d6bSopenharmony_ci   return g_regex_match_full (regex, string, -1, 0, match_options,
1554b5975d6bSopenharmony_ci                              match_info, NULL);
1555b5975d6bSopenharmony_ci }
1556b5975d6bSopenharmony_ci@@ -1801,6 +2070,8 @@ g_regex_match_full (const GRegex      *regex,
1557b5975d6bSopenharmony_ci   GMatchInfo *info;
1558b5975d6bSopenharmony_ci   gboolean match_ok;
1559b5975d6bSopenharmony_ci 
1560b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1561b5975d6bSopenharmony_ci+
1562b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, FALSE);
1563b5975d6bSopenharmony_ci   g_return_val_if_fail (string != NULL, FALSE);
1564b5975d6bSopenharmony_ci   g_return_val_if_fail (start_position >= 0, FALSE);
1565b5975d6bSopenharmony_ci@@ -1851,6 +2122,8 @@ g_regex_match_all (const GRegex      *regex,
1566b5975d6bSopenharmony_ci                    GRegexMatchFlags   match_options,
1567b5975d6bSopenharmony_ci                    GMatchInfo       **match_info)
1568b5975d6bSopenharmony_ci {
1569b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1570b5975d6bSopenharmony_ci+
1571b5975d6bSopenharmony_ci   return g_regex_match_all_full (regex, string, -1, 0, match_options,
1572b5975d6bSopenharmony_ci                                  match_info, NULL);
1573b5975d6bSopenharmony_ci }
1574b5975d6bSopenharmony_ci@@ -1920,39 +2193,29 @@ g_regex_match_all_full (const GRegex      *regex,
1575b5975d6bSopenharmony_ci {
1576b5975d6bSopenharmony_ci   GMatchInfo *info;
1577b5975d6bSopenharmony_ci   gboolean done;
1578b5975d6bSopenharmony_ci-  pcre *pcre_re;
1579b5975d6bSopenharmony_ci-  pcre_extra *extra;
1580b5975d6bSopenharmony_ci+  pcre2_code *pcre_re;
1581b5975d6bSopenharmony_ci   gboolean retval;
1582b5975d6bSopenharmony_ci 
1583b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1584b5975d6bSopenharmony_ci+
1585b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, FALSE);
1586b5975d6bSopenharmony_ci   g_return_val_if_fail (string != NULL, FALSE);
1587b5975d6bSopenharmony_ci   g_return_val_if_fail (start_position >= 0, FALSE);
1588b5975d6bSopenharmony_ci   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1589b5975d6bSopenharmony_ci   g_return_val_if_fail ((match_options & ~G_REGEX_MATCH_MASK) == 0, FALSE);
1590b5975d6bSopenharmony_ci 
1591b5975d6bSopenharmony_ci-#ifdef PCRE_NO_AUTO_POSSESS
1592b5975d6bSopenharmony_ci-  /* For PCRE >= 8.34 we need to turn off PCRE_NO_AUTO_POSSESS, which
1593b5975d6bSopenharmony_ci-   * is an optimization for normal regex matching, but results in omitting
1594b5975d6bSopenharmony_ci-   * some shorter matches here, and an observable behaviour change.
1595b5975d6bSopenharmony_ci+  /* For PCRE2 we need to turn off PCRE2_NO_AUTO_POSSESS, which is an
1596b5975d6bSopenharmony_ci+   * optimization for normal regex matching, but results in omitting some
1597b5975d6bSopenharmony_ci+   * shorter matches here, and an observable behaviour change.
1598b5975d6bSopenharmony_ci    *
1599b5975d6bSopenharmony_ci    * DFA matching is rather niche, and very rarely used according to
1600b5975d6bSopenharmony_ci    * codesearch.debian.net, so don't bother caching the recompiled RE. */
1601b5975d6bSopenharmony_ci   pcre_re = regex_compile (regex->pattern,
1602b5975d6bSopenharmony_ci-                           regex->compile_opts | PCRE_NO_AUTO_POSSESS,
1603b5975d6bSopenharmony_ci+                           regex->compile_opts | PCRE2_NO_AUTO_POSSESS,
1604b5975d6bSopenharmony_ci                            NULL, NULL, error);
1605b5975d6bSopenharmony_ci-
1606b5975d6bSopenharmony_ci   if (pcre_re == NULL)
1607b5975d6bSopenharmony_ci     return FALSE;
1608b5975d6bSopenharmony_ci 
1609b5975d6bSopenharmony_ci-  /* Not bothering to cache the optimization data either, with similar
1610b5975d6bSopenharmony_ci-   * reasoning */
1611b5975d6bSopenharmony_ci-  extra = NULL;
1612b5975d6bSopenharmony_ci-#else
1613b5975d6bSopenharmony_ci-  /* For PCRE < 8.33 the precompiled regex is fine. */
1614b5975d6bSopenharmony_ci-  pcre_re = regex->pcre_re;
1615b5975d6bSopenharmony_ci-  extra = regex->extra;
1616b5975d6bSopenharmony_ci-#endif
1617b5975d6bSopenharmony_ci-
1618b5975d6bSopenharmony_ci   info = match_info_new (regex, string, string_len, start_position,
1619b5975d6bSopenharmony_ci                          match_options, TRUE);
1620b5975d6bSopenharmony_ci 
1621b5975d6bSopenharmony_ci@@ -1960,29 +2223,38 @@ g_regex_match_all_full (const GRegex      *regex,
1622b5975d6bSopenharmony_ci   while (!done)
1623b5975d6bSopenharmony_ci     {
1624b5975d6bSopenharmony_ci       done = TRUE;
1625b5975d6bSopenharmony_ci-      info->matches = pcre_dfa_exec (pcre_re, extra,
1626b5975d6bSopenharmony_ci-                                     info->string, info->string_len,
1627b5975d6bSopenharmony_ci-                                     info->pos,
1628b5975d6bSopenharmony_ci-                                     regex->match_opts | match_options,
1629b5975d6bSopenharmony_ci-                                     info->offsets, info->n_offsets,
1630b5975d6bSopenharmony_ci-                                     info->workspace, info->n_workspace);
1631b5975d6bSopenharmony_ci-      if (info->matches == PCRE_ERROR_DFA_WSSIZE)
1632b5975d6bSopenharmony_ci+      info->matches = pcre2_dfa_match (pcre_re,
1633b5975d6bSopenharmony_ci+                                       (PCRE2_SPTR8) info->string, info->string_len,
1634b5975d6bSopenharmony_ci+                                       info->pos,
1635b5975d6bSopenharmony_ci+                                       (regex->match_opts | match_options | PCRE2_NO_UTF_CHECK) & ~G_REGEX_FLAGS_CONVERTED,
1636b5975d6bSopenharmony_ci+                                       info->match_data,
1637b5975d6bSopenharmony_ci+                                       info->match_context,
1638b5975d6bSopenharmony_ci+                                       info->workspace, info->n_workspace);
1639b5975d6bSopenharmony_ci+
1640b5975d6bSopenharmony_ci+      if (!recalc_match_offsets (info, error))
1641b5975d6bSopenharmony_ci+        return FALSE;
1642b5975d6bSopenharmony_ci+
1643b5975d6bSopenharmony_ci+      if (info->matches == PCRE2_ERROR_DFA_WSSIZE)
1644b5975d6bSopenharmony_ci         {
1645b5975d6bSopenharmony_ci           /* info->workspace is too small. */
1646b5975d6bSopenharmony_ci           info->n_workspace *= 2;
1647b5975d6bSopenharmony_ci-          info->workspace = g_realloc (info->workspace,
1648b5975d6bSopenharmony_ci-                                       info->n_workspace * sizeof (gint));
1649b5975d6bSopenharmony_ci+          info->workspace = g_realloc_n (info->workspace,
1650b5975d6bSopenharmony_ci+                                         info->n_workspace,
1651b5975d6bSopenharmony_ci+                                         sizeof (gint));
1652b5975d6bSopenharmony_ci           done = FALSE;
1653b5975d6bSopenharmony_ci         }
1654b5975d6bSopenharmony_ci       else if (info->matches == 0)
1655b5975d6bSopenharmony_ci         {
1656b5975d6bSopenharmony_ci           /* info->offsets is too small. */
1657b5975d6bSopenharmony_ci           info->n_offsets *= 2;
1658b5975d6bSopenharmony_ci-          info->offsets = g_realloc (info->offsets,
1659b5975d6bSopenharmony_ci-                                     info->n_offsets * sizeof (gint));
1660b5975d6bSopenharmony_ci+          info->offsets = g_realloc_n (info->offsets,
1661b5975d6bSopenharmony_ci+                                       info->n_offsets,
1662b5975d6bSopenharmony_ci+                                       sizeof (gint));
1663b5975d6bSopenharmony_ci+          pcre2_match_data_free (info->match_data);
1664b5975d6bSopenharmony_ci+          info->match_data = pcre2_match_data_create (info->n_offsets, NULL);
1665b5975d6bSopenharmony_ci           done = FALSE;
1666b5975d6bSopenharmony_ci         }
1667b5975d6bSopenharmony_ci-      else if (IS_PCRE_ERROR (info->matches))
1668b5975d6bSopenharmony_ci+      else if (IS_PCRE2_ERROR (info->matches))
1669b5975d6bSopenharmony_ci         {
1670b5975d6bSopenharmony_ci           g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
1671b5975d6bSopenharmony_ci                        _("Error while matching regular expression %s: %s"),
1672b5975d6bSopenharmony_ci@@ -1990,9 +2262,7 @@ g_regex_match_all_full (const GRegex      *regex,
1673b5975d6bSopenharmony_ci         }
1674b5975d6bSopenharmony_ci     }
1675b5975d6bSopenharmony_ci 
1676b5975d6bSopenharmony_ci-#ifdef PCRE_NO_AUTO_POSSESS
1677b5975d6bSopenharmony_ci-  pcre_free (pcre_re);
1678b5975d6bSopenharmony_ci-#endif
1679b5975d6bSopenharmony_ci+  pcre2_code_free (pcre_re);
1680b5975d6bSopenharmony_ci 
1681b5975d6bSopenharmony_ci   /* don’t assert that (info->matches <= info->n_subpatterns + 1) as that only
1682b5975d6bSopenharmony_ci    * holds true for a single match, rather than matching all */
1683b5975d6bSopenharmony_ci@@ -2030,8 +2300,8 @@ g_regex_get_string_number (const GRegex *regex,
1684b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, -1);
1685b5975d6bSopenharmony_ci   g_return_val_if_fail (name != NULL, -1);
1686b5975d6bSopenharmony_ci 
1687b5975d6bSopenharmony_ci-  num = pcre_get_stringnumber (regex->pcre_re, name);
1688b5975d6bSopenharmony_ci-  if (num == PCRE_ERROR_NOSUBSTRING)
1689b5975d6bSopenharmony_ci+  num = pcre2_substring_number_from_name (regex->pcre_re, (PCRE2_SPTR8) name);
1690b5975d6bSopenharmony_ci+  if (num == PCRE2_ERROR_NOSUBSTRING)
1691b5975d6bSopenharmony_ci     num = -1;
1692b5975d6bSopenharmony_ci 
1693b5975d6bSopenharmony_ci   return num;
1694b5975d6bSopenharmony_ci@@ -2086,6 +2356,9 @@ g_regex_split_simple (const gchar        *pattern,
1695b5975d6bSopenharmony_ci   GRegex *regex;
1696b5975d6bSopenharmony_ci   gchar **result;
1697b5975d6bSopenharmony_ci 
1698b5975d6bSopenharmony_ci+  compile_options = map_to_pcre2_compile_flags (compile_options);
1699b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1700b5975d6bSopenharmony_ci+
1701b5975d6bSopenharmony_ci   regex = g_regex_new (pattern, compile_options, 0, NULL);
1702b5975d6bSopenharmony_ci   if (!regex)
1703b5975d6bSopenharmony_ci     return NULL;
1704b5975d6bSopenharmony_ci@@ -2129,6 +2402,8 @@ g_regex_split (const GRegex     *regex,
1705b5975d6bSopenharmony_ci                const gchar      *string,
1706b5975d6bSopenharmony_ci                GRegexMatchFlags  match_options)
1707b5975d6bSopenharmony_ci {
1708b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1709b5975d6bSopenharmony_ci+
1710b5975d6bSopenharmony_ci   return g_regex_split_full (regex, string, -1, 0,
1711b5975d6bSopenharmony_ci                              match_options, 0, NULL);
1712b5975d6bSopenharmony_ci }
1713b5975d6bSopenharmony_ci@@ -2193,6 +2468,8 @@ g_regex_split_full (const GRegex      *regex,
1714b5975d6bSopenharmony_ci   /* the returned array of char **s */
1715b5975d6bSopenharmony_ci   gchar **string_list;
1716b5975d6bSopenharmony_ci 
1717b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1718b5975d6bSopenharmony_ci+
1719b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, NULL);
1720b5975d6bSopenharmony_ci   g_return_val_if_fail (string != NULL, NULL);
1721b5975d6bSopenharmony_ci   g_return_val_if_fail (start_position >= 0, NULL);
1722b5975d6bSopenharmony_ci@@ -2817,6 +3094,8 @@ g_regex_replace (const GRegex      *regex,
1723b5975d6bSopenharmony_ci   GList *list;
1724b5975d6bSopenharmony_ci   GError *tmp_error = NULL;
1725b5975d6bSopenharmony_ci 
1726b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1727b5975d6bSopenharmony_ci+
1728b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, NULL);
1729b5975d6bSopenharmony_ci   g_return_val_if_fail (string != NULL, NULL);
1730b5975d6bSopenharmony_ci   g_return_val_if_fail (start_position >= 0, NULL);
1731b5975d6bSopenharmony_ci@@ -2886,6 +3165,8 @@ g_regex_replace_literal (const GRegex      *regex,
1732b5975d6bSopenharmony_ci                          GRegexMatchFlags   match_options,
1733b5975d6bSopenharmony_ci                          GError           **error)
1734b5975d6bSopenharmony_ci {
1735b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1736b5975d6bSopenharmony_ci+
1737b5975d6bSopenharmony_ci   g_return_val_if_fail (replacement != NULL, NULL);
1738b5975d6bSopenharmony_ci   g_return_val_if_fail ((match_options & ~G_REGEX_MATCH_MASK) == 0, NULL);
1739b5975d6bSopenharmony_ci 
1740b5975d6bSopenharmony_ci@@ -2974,6 +3255,8 @@ g_regex_replace_eval (const GRegex        *regex,
1741b5975d6bSopenharmony_ci   gboolean done = FALSE;
1742b5975d6bSopenharmony_ci   GError *tmp_error = NULL;
1743b5975d6bSopenharmony_ci 
1744b5975d6bSopenharmony_ci+  match_options = map_to_pcre2_match_flags (match_options);
1745b5975d6bSopenharmony_ci+
1746b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, NULL);
1747b5975d6bSopenharmony_ci   g_return_val_if_fail (string != NULL, NULL);
1748b5975d6bSopenharmony_ci   g_return_val_if_fail (start_position >= 0, NULL);
1749b5975d6bSopenharmony_cidiff --git a/glib/gregex.h b/glib/gregex.h
1750b5975d6bSopenharmony_ciindex 817f667..11b419d 100644
1751b5975d6bSopenharmony_ci--- a/glib/gregex.h
1752b5975d6bSopenharmony_ci+++ b/glib/gregex.h
1753b5975d6bSopenharmony_ci@@ -262,7 +262,9 @@ GQuark g_regex_error_quark (void);
1754b5975d6bSopenharmony_ci  *     in the usual way).
1755b5975d6bSopenharmony_ci  * @G_REGEX_OPTIMIZE: Optimize the regular expression. If the pattern will
1756b5975d6bSopenharmony_ci  *     be used many times, then it may be worth the effort to optimize it
1757b5975d6bSopenharmony_ci- *     to improve the speed of matches.
1758b5975d6bSopenharmony_ci+ *     to improve the speed of matches. Deprecated in GLib 2.74 which now uses
1759b5975d6bSopenharmony_ci+ *     libpcre2, which doesn’t require separate optimization of queries. This
1760b5975d6bSopenharmony_ci+ *     option is now a no-op. Deprecated: 2.74
1761b5975d6bSopenharmony_ci  * @G_REGEX_FIRSTLINE: Limits an unanchored pattern to match before (or at) the
1762b5975d6bSopenharmony_ci  *     first newline. Since: 2.34
1763b5975d6bSopenharmony_ci  * @G_REGEX_DUPNAMES: Names used to identify capturing subpatterns need not
1764b5975d6bSopenharmony_ci@@ -285,7 +287,8 @@ GQuark g_regex_error_quark (void);
1765b5975d6bSopenharmony_ci  *     is recognised. If this option is set, then "\R" only recognizes the newline
1766b5975d6bSopenharmony_ci  *    characters '\r', '\n' and '\r\n'. Since: 2.34
1767b5975d6bSopenharmony_ci  * @G_REGEX_JAVASCRIPT_COMPAT: Changes behaviour so that it is compatible with
1768b5975d6bSopenharmony_ci- *     JavaScript rather than PCRE. Since: 2.34
1769b5975d6bSopenharmony_ci+ *     JavaScript rather than PCRE. Since GLib 2.74 this is no longer supported,
1770b5975d6bSopenharmony_ci+ *     as libpcre2 does not support it. Since: 2.34 Deprecated: 2.74
1771b5975d6bSopenharmony_ci  *
1772b5975d6bSopenharmony_ci  * Flags specifying compile-time options.
1773b5975d6bSopenharmony_ci  *
1774b5975d6bSopenharmony_ci@@ -306,7 +309,7 @@ typedef enum
1775b5975d6bSopenharmony_ci   G_REGEX_UNGREEDY          = 1 << 9,
1776b5975d6bSopenharmony_ci   G_REGEX_RAW               = 1 << 11,
1777b5975d6bSopenharmony_ci   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
1778b5975d6bSopenharmony_ci-  G_REGEX_OPTIMIZE          = 1 << 13,
1779b5975d6bSopenharmony_ci+  G_REGEX_OPTIMIZE GLIB_DEPRECATED_ENUMERATOR_IN_2_74 = 1 << 13,
1780b5975d6bSopenharmony_ci   G_REGEX_FIRSTLINE         = 1 << 18,
1781b5975d6bSopenharmony_ci   G_REGEX_DUPNAMES          = 1 << 19,
1782b5975d6bSopenharmony_ci   G_REGEX_NEWLINE_CR        = 1 << 20,
1783b5975d6bSopenharmony_ci@@ -314,7 +317,7 @@ typedef enum
1784b5975d6bSopenharmony_ci   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF,
1785b5975d6bSopenharmony_ci   G_REGEX_NEWLINE_ANYCRLF   = G_REGEX_NEWLINE_CR | 1 << 22,
1786b5975d6bSopenharmony_ci   G_REGEX_BSR_ANYCRLF       = 1 << 23,
1787b5975d6bSopenharmony_ci-  G_REGEX_JAVASCRIPT_COMPAT = 1 << 25
1788b5975d6bSopenharmony_ci+  G_REGEX_JAVASCRIPT_COMPAT GLIB_DEPRECATED_ENUMERATOR_IN_2_74 = 1 << 25
1789b5975d6bSopenharmony_ci } GRegexCompileFlags;
1790b5975d6bSopenharmony_ci 
1791b5975d6bSopenharmony_ci /**
1792b5975d6bSopenharmony_cidiff --git a/glib/meson.build b/glib/meson.build
1793b5975d6bSopenharmony_ciindex 93fa504..5bf82da 100644
1794b5975d6bSopenharmony_ci--- a/glib/meson.build
1795b5975d6bSopenharmony_ci+++ b/glib/meson.build
1796b5975d6bSopenharmony_ci@@ -357,13 +357,13 @@ else
1797b5975d6bSopenharmony_ci   glib_dtrace_hdr = []
1798b5975d6bSopenharmony_ci endif
1799b5975d6bSopenharmony_ci 
1800b5975d6bSopenharmony_ci-pcre_static_args = []
1801b5975d6bSopenharmony_ci+pcre2_static_args = []
1802b5975d6bSopenharmony_ci 
1803b5975d6bSopenharmony_ci-if use_pcre_static_flag
1804b5975d6bSopenharmony_ci-  pcre_static_args = ['-DPCRE_STATIC']
1805b5975d6bSopenharmony_ci+if use_pcre2_static_flag
1806b5975d6bSopenharmony_ci+  pcre2_static_args = ['-DPCRE2_STATIC']
1807b5975d6bSopenharmony_ci endif
1808b5975d6bSopenharmony_ci 
1809b5975d6bSopenharmony_ci-glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + pcre_static_args + glib_hidden_visibility_args
1810b5975d6bSopenharmony_ci+glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + pcre2_static_args + glib_hidden_visibility_args
1811b5975d6bSopenharmony_ci libglib = library('glib-2.0',
1812b5975d6bSopenharmony_ci   glib_dtrace_obj, glib_dtrace_hdr,
1813b5975d6bSopenharmony_ci   sources : [deprecated_sources, glib_sources],
1814b5975d6bSopenharmony_ci@@ -375,7 +375,7 @@ libglib = library('glib-2.0',
1815b5975d6bSopenharmony_ci   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
1816b5975d6bSopenharmony_ci   include_directories : configinc,
1817b5975d6bSopenharmony_ci   link_with: [charset_lib, gnulib_lib],
1818b5975d6bSopenharmony_ci-  dependencies : [pcre, thread_dep, librt] + libintl_deps + libiconv + platform_deps + [gnulib_libm_dependency, libm] + [libsysprof_capture_dep],
1819b5975d6bSopenharmony_ci+  dependencies : [pcre2, thread_dep, librt] + libintl_deps + libiconv + platform_deps + [gnulib_libm_dependency, libm] + [libsysprof_capture_dep],
1820b5975d6bSopenharmony_ci   c_args : glib_c_args,
1821b5975d6bSopenharmony_ci   objc_args : glib_c_args,
1822b5975d6bSopenharmony_ci )
1823b5975d6bSopenharmony_cidiff --git a/glib/tests/meson.build b/glib/tests/meson.build
1824b5975d6bSopenharmony_ciindex 301158e..c1a9ceb 100644
1825b5975d6bSopenharmony_ci--- a/glib/tests/meson.build
1826b5975d6bSopenharmony_ci+++ b/glib/tests/meson.build
1827b5975d6bSopenharmony_ci@@ -86,8 +86,8 @@ glib_tests = {
1828b5975d6bSopenharmony_ci   },
1829b5975d6bSopenharmony_ci   'refstring' : {},
1830b5975d6bSopenharmony_ci   'regex' : {
1831b5975d6bSopenharmony_ci-    'dependencies' : [pcre],
1832b5975d6bSopenharmony_ci-    'c_args' : use_pcre_static_flag ? ['-DPCRE_STATIC'] : [],
1833b5975d6bSopenharmony_ci+    'dependencies' : [pcre2],
1834b5975d6bSopenharmony_ci+    'c_args' : use_pcre2_static_flag ? ['-DPCRE2_STATIC'] : [],
1835b5975d6bSopenharmony_ci   },
1836b5975d6bSopenharmony_ci   'relation' : {},
1837b5975d6bSopenharmony_ci   'rwlock' : {},
1838b5975d6bSopenharmony_cidiff --git a/glib/tests/regex.c b/glib/tests/regex.c
1839b5975d6bSopenharmony_ciindex 50fd9c6..36982fb 100644
1840b5975d6bSopenharmony_ci--- a/glib/tests/regex.c
1841b5975d6bSopenharmony_ci+++ b/glib/tests/regex.c
1842b5975d6bSopenharmony_ci@@ -25,7 +25,8 @@
1843b5975d6bSopenharmony_ci #include <locale.h>
1844b5975d6bSopenharmony_ci #include "glib.h"
1845b5975d6bSopenharmony_ci 
1846b5975d6bSopenharmony_ci-#include <pcre.h>
1847b5975d6bSopenharmony_ci+#define PCRE2_CODE_UNIT_WIDTH 8
1848b5975d6bSopenharmony_ci+#include <pcre2.h>
1849b5975d6bSopenharmony_ci 
1850b5975d6bSopenharmony_ci /* U+20AC EURO SIGN (symbol, currency) */
1851b5975d6bSopenharmony_ci #define EURO "\xe2\x82\xac"
1852b5975d6bSopenharmony_ci@@ -1501,7 +1502,7 @@ test_properties (void)
1853b5975d6bSopenharmony_ci   gchar *str;
1854b5975d6bSopenharmony_ci 
1855b5975d6bSopenharmony_ci   error = NULL;
1856b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1857b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1858b5975d6bSopenharmony_ci   res = g_regex_match (regex, "ppPP01", 0, &match);
1859b5975d6bSopenharmony_ci   g_assert (res);
1860b5975d6bSopenharmony_ci   str = g_match_info_fetch (match, 0);
1861b5975d6bSopenharmony_ci@@ -1522,7 +1523,7 @@ test_class (void)
1862b5975d6bSopenharmony_ci   gchar *str;
1863b5975d6bSopenharmony_ci 
1864b5975d6bSopenharmony_ci   error = NULL;
1865b5975d6bSopenharmony_ci-  regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1866b5975d6bSopenharmony_ci+  regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1867b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a:b:\340\254\236:\333\253:\316\240", 0, &match);
1868b5975d6bSopenharmony_ci   g_assert (res);
1869b5975d6bSopenharmony_ci   str = g_match_info_fetch (match, 0);
1870b5975d6bSopenharmony_ci@@ -1568,7 +1569,7 @@ test_lookahead (void)
1871b5975d6bSopenharmony_ci   gint start, end;
1872b5975d6bSopenharmony_ci 
1873b5975d6bSopenharmony_ci   error = NULL;
1874b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\w+(?=;)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1875b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\w+(?=;)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1876b5975d6bSopenharmony_ci   g_assert (regex);
1877b5975d6bSopenharmony_ci   g_assert_no_error (error);
1878b5975d6bSopenharmony_ci   res = g_regex_match (regex, "word1 word2: word3;", 0, &match);
1879b5975d6bSopenharmony_ci@@ -1582,7 +1583,7 @@ test_lookahead (void)
1880b5975d6bSopenharmony_ci   g_regex_unref (regex);
1881b5975d6bSopenharmony_ci 
1882b5975d6bSopenharmony_ci   error = NULL;
1883b5975d6bSopenharmony_ci-  regex = g_regex_new ("foo(?!bar)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1884b5975d6bSopenharmony_ci+  regex = g_regex_new ("foo(?!bar)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1885b5975d6bSopenharmony_ci   g_assert (regex);
1886b5975d6bSopenharmony_ci   g_assert_no_error (error);
1887b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar foobaz", 0, &match);
1888b5975d6bSopenharmony_ci@@ -1597,7 +1598,7 @@ test_lookahead (void)
1889b5975d6bSopenharmony_ci   g_regex_unref (regex);
1890b5975d6bSopenharmony_ci 
1891b5975d6bSopenharmony_ci   error = NULL;
1892b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?!bar)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1893b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?!bar)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1894b5975d6bSopenharmony_ci   g_assert (regex);
1895b5975d6bSopenharmony_ci   g_assert_no_error (error);
1896b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar foobaz", 0, &match);
1897b5975d6bSopenharmony_ci@@ -1630,7 +1631,7 @@ test_lookbehind (void)
1898b5975d6bSopenharmony_ci   gint start, end;
1899b5975d6bSopenharmony_ci 
1900b5975d6bSopenharmony_ci   error = NULL;
1901b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<!foo)bar", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1902b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<!foo)bar", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1903b5975d6bSopenharmony_ci   g_assert (regex);
1904b5975d6bSopenharmony_ci   g_assert_no_error (error);
1905b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar boobar", 0, &match);
1906b5975d6bSopenharmony_ci@@ -1645,7 +1646,7 @@ test_lookbehind (void)
1907b5975d6bSopenharmony_ci   g_regex_unref (regex);
1908b5975d6bSopenharmony_ci 
1909b5975d6bSopenharmony_ci   error = NULL;
1910b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1911b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1912b5975d6bSopenharmony_ci   g_assert (regex);
1913b5975d6bSopenharmony_ci   g_assert_no_error (error);
1914b5975d6bSopenharmony_ci   res = g_regex_match (regex, "don poo, and bullock poo", 0, &match);
1915b5975d6bSopenharmony_ci@@ -1658,17 +1659,17 @@ test_lookbehind (void)
1916b5975d6bSopenharmony_ci   g_match_info_free (match);
1917b5975d6bSopenharmony_ci   g_regex_unref (regex);
1918b5975d6bSopenharmony_ci 
1919b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1920b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1921b5975d6bSopenharmony_ci   g_assert (regex == NULL);
1922b5975d6bSopenharmony_ci   g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND);
1923b5975d6bSopenharmony_ci   g_clear_error (&error);
1924b5975d6bSopenharmony_ci 
1925b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1926b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1927b5975d6bSopenharmony_ci   g_assert (regex == NULL);
1928b5975d6bSopenharmony_ci   g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND);
1929b5975d6bSopenharmony_ci   g_clear_error (&error);
1930b5975d6bSopenharmony_ci 
1931b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1932b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1933b5975d6bSopenharmony_ci   g_assert (regex);
1934b5975d6bSopenharmony_ci   g_assert_no_error (error);
1935b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abfoo, abdfoo, abcfoo", 0, &match);
1936b5975d6bSopenharmony_ci@@ -1680,7 +1681,7 @@ test_lookbehind (void)
1937b5975d6bSopenharmony_ci   g_match_info_free (match);
1938b5975d6bSopenharmony_ci   g_regex_unref (regex);
1939b5975d6bSopenharmony_ci 
1940b5975d6bSopenharmony_ci-  regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1941b5975d6bSopenharmony_ci+  regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1942b5975d6bSopenharmony_ci   g_assert (regex);
1943b5975d6bSopenharmony_ci   g_assert_no_error (error);
1944b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcabcabcabcabcabcabcabcabcd", 0, &match);
1945b5975d6bSopenharmony_ci@@ -1689,7 +1690,7 @@ test_lookbehind (void)
1946b5975d6bSopenharmony_ci   g_match_info_free (match);
1947b5975d6bSopenharmony_ci   g_regex_unref (regex);
1948b5975d6bSopenharmony_ci 
1949b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1950b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1951b5975d6bSopenharmony_ci   g_assert (regex);
1952b5975d6bSopenharmony_ci   g_assert_no_error (error);
1953b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
1954b5975d6bSopenharmony_ci@@ -1701,7 +1702,7 @@ test_lookbehind (void)
1955b5975d6bSopenharmony_ci   g_match_info_free (match);
1956b5975d6bSopenharmony_ci   g_regex_unref (regex);
1957b5975d6bSopenharmony_ci 
1958b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1959b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1960b5975d6bSopenharmony_ci   g_assert (regex);
1961b5975d6bSopenharmony_ci   g_assert_no_error (error);
1962b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
1963b5975d6bSopenharmony_ci@@ -1713,7 +1714,7 @@ test_lookbehind (void)
1964b5975d6bSopenharmony_ci   g_match_info_free (match);
1965b5975d6bSopenharmony_ci   g_regex_unref (regex);
1966b5975d6bSopenharmony_ci 
1967b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1968b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1969b5975d6bSopenharmony_ci   g_assert (regex);
1970b5975d6bSopenharmony_ci   g_assert_no_error (error);
1971b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
1972b5975d6bSopenharmony_ci@@ -1725,7 +1726,7 @@ test_lookbehind (void)
1973b5975d6bSopenharmony_ci   g_match_info_free (match);
1974b5975d6bSopenharmony_ci   g_regex_unref (regex);
1975b5975d6bSopenharmony_ci 
1976b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1977b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1978b5975d6bSopenharmony_ci   g_assert (regex);
1979b5975d6bSopenharmony_ci   g_assert_no_error (error);
1980b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobarbaz barfoobaz barbarbaz", 0, &match);
1981b5975d6bSopenharmony_ci@@ -1750,7 +1751,7 @@ test_subpattern (void)
1982b5975d6bSopenharmony_ci   gint start;
1983b5975d6bSopenharmony_ci 
1984b5975d6bSopenharmony_ci   error = NULL;
1985b5975d6bSopenharmony_ci-  regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1986b5975d6bSopenharmony_ci+  regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1987b5975d6bSopenharmony_ci   g_assert (regex);
1988b5975d6bSopenharmony_ci   g_assert_no_error (error);
1989b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 1);
1990b5975d6bSopenharmony_ci@@ -1768,7 +1769,7 @@ test_subpattern (void)
1991b5975d6bSopenharmony_ci   g_match_info_free (match);
1992b5975d6bSopenharmony_ci   g_regex_unref (regex);
1993b5975d6bSopenharmony_ci 
1994b5975d6bSopenharmony_ci-  regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
1995b5975d6bSopenharmony_ci+  regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
1996b5975d6bSopenharmony_ci   g_assert (regex);
1997b5975d6bSopenharmony_ci   g_assert_no_error (error);
1998b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
1999b5975d6bSopenharmony_ci@@ -1792,7 +1793,7 @@ test_subpattern (void)
2000b5975d6bSopenharmony_ci   g_match_info_free (match);
2001b5975d6bSopenharmony_ci   g_regex_unref (regex);
2002b5975d6bSopenharmony_ci 
2003b5975d6bSopenharmony_ci-  regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2004b5975d6bSopenharmony_ci+  regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2005b5975d6bSopenharmony_ci   g_assert (regex);
2006b5975d6bSopenharmony_ci   g_assert_no_error (error);
2007b5975d6bSopenharmony_ci   res = g_regex_match (regex, "the white queen", 0, &match);
2008b5975d6bSopenharmony_ci@@ -1812,7 +1813,7 @@ test_subpattern (void)
2009b5975d6bSopenharmony_ci   g_match_info_free (match);
2010b5975d6bSopenharmony_ci   g_regex_unref (regex);
2011b5975d6bSopenharmony_ci 
2012b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2013b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2014b5975d6bSopenharmony_ci   g_assert (regex);
2015b5975d6bSopenharmony_ci   g_assert_no_error (error);
2016b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
2017b5975d6bSopenharmony_ci@@ -1832,7 +1833,7 @@ test_subpattern (void)
2018b5975d6bSopenharmony_ci   g_match_info_free (match);
2019b5975d6bSopenharmony_ci   g_regex_unref (regex);
2020b5975d6bSopenharmony_ci 
2021b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2022b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2023b5975d6bSopenharmony_ci   g_assert (regex);
2024b5975d6bSopenharmony_ci   g_assert_no_error (error);
2025b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_max_backref (regex), ==, 1);
2026b5975d6bSopenharmony_ci@@ -1850,7 +1851,7 @@ test_subpattern (void)
2027b5975d6bSopenharmony_ci   g_match_info_free (match);
2028b5975d6bSopenharmony_ci   g_regex_unref (regex);
2029b5975d6bSopenharmony_ci 
2030b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2031b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2032b5975d6bSopenharmony_ci   g_assert (regex);
2033b5975d6bSopenharmony_ci   g_assert_no_error (error);
2034b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcabc abcdef defabc defdef", 0, &match);
2035b5975d6bSopenharmony_ci@@ -1867,7 +1868,7 @@ test_subpattern (void)
2036b5975d6bSopenharmony_ci   g_match_info_free (match);
2037b5975d6bSopenharmony_ci   g_regex_unref (regex);
2038b5975d6bSopenharmony_ci 
2039b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN>Thu)(?:rsday)?|(?<DN>Sat)(?:urday)?", G_REGEX_OPTIMIZE|G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
2040b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN>Thu)(?:rsday)?|(?<DN>Sat)(?:urday)?", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
2041b5975d6bSopenharmony_ci   g_assert (regex);
2042b5975d6bSopenharmony_ci   g_assert_no_error (error);
2043b5975d6bSopenharmony_ci   res = g_regex_match (regex, "Mon Tuesday Wed Saturday", 0, &match);
2044b5975d6bSopenharmony_ci@@ -1894,7 +1895,7 @@ test_subpattern (void)
2045b5975d6bSopenharmony_ci   g_match_info_free (match);
2046b5975d6bSopenharmony_ci   g_regex_unref (regex);
2047b5975d6bSopenharmony_ci 
2048b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_OPTIMIZE|G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
2049b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
2050b5975d6bSopenharmony_ci   g_assert (regex);
2051b5975d6bSopenharmony_ci   g_assert_no_error (error);
2052b5975d6bSopenharmony_ci   res = g_regex_match (regex, "aaaaaaaaaaaaaaaa", 0, &match);
2053b5975d6bSopenharmony_ci@@ -1918,7 +1919,7 @@ test_condition (void)
2054b5975d6bSopenharmony_ci   gboolean res;
2055b5975d6bSopenharmony_ci 
2056b5975d6bSopenharmony_ci   error = NULL;
2057b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2058b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2059b5975d6bSopenharmony_ci   g_assert (regex);
2060b5975d6bSopenharmony_ci   g_assert_no_error (error);
2061b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
2062b5975d6bSopenharmony_ci@@ -1932,7 +1933,7 @@ test_condition (void)
2063b5975d6bSopenharmony_ci   g_regex_unref (regex);
2064b5975d6bSopenharmony_ci 
2065b5975d6bSopenharmony_ci   error = NULL;
2066b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2067b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2068b5975d6bSopenharmony_ci   g_assert (regex);
2069b5975d6bSopenharmony_ci   g_assert_no_error (error);
2070b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
2071b5975d6bSopenharmony_ci@@ -1945,7 +1946,7 @@ test_condition (void)
2072b5975d6bSopenharmony_ci   g_match_info_free (match);
2073b5975d6bSopenharmony_ci   g_regex_unref (regex);
2074b5975d6bSopenharmony_ci 
2075b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2076b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2077b5975d6bSopenharmony_ci   g_assert (regex);
2078b5975d6bSopenharmony_ci   g_assert_no_error (error);
2079b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a[zzzzzz]b", 0, &match);
2080b5975d6bSopenharmony_ci@@ -1960,7 +1961,7 @@ test_condition (void)
2081b5975d6bSopenharmony_ci 
2082b5975d6bSopenharmony_ci   regex = g_regex_new ("(?(DEFINE) (?<byte> 2[0-4]\\d | 25[0-5] | 1\\d\\d | [1-9]?\\d) )"
2083b5975d6bSopenharmony_ci                        "\\b (?&byte) (\\.(?&byte)){3} \\b",
2084b5975d6bSopenharmony_ci-                       G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, 0, &error);
2085b5975d6bSopenharmony_ci+                       G_REGEX_EXTENDED, 0, &error);
2086b5975d6bSopenharmony_ci   g_assert (regex);
2087b5975d6bSopenharmony_ci   g_assert_no_error (error);
2088b5975d6bSopenharmony_ci   res = g_regex_match (regex, "128.0.0.1", 0, &match);
2089b5975d6bSopenharmony_ci@@ -1979,7 +1980,7 @@ test_condition (void)
2090b5975d6bSopenharmony_ci 
2091b5975d6bSopenharmony_ci   regex = g_regex_new ("^(?(?=[^a-z]*[a-z])"
2092b5975d6bSopenharmony_ci                        "\\d{2}-[a-z]{3}-\\d{2} | \\d{2}-\\d{2}-\\d{2} )$",
2093b5975d6bSopenharmony_ci-                       G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, 0, &error);
2094b5975d6bSopenharmony_ci+                       G_REGEX_EXTENDED, 0, &error);
2095b5975d6bSopenharmony_ci   g_assert (regex);
2096b5975d6bSopenharmony_ci   g_assert_no_error (error);
2097b5975d6bSopenharmony_ci   res = g_regex_match (regex, "01-abc-24", 0, &match);
2098b5975d6bSopenharmony_ci@@ -2012,7 +2013,7 @@ test_recursion (void)
2099b5975d6bSopenharmony_ci   gint start;
2100b5975d6bSopenharmony_ci 
2101b5975d6bSopenharmony_ci   error = NULL;
2102b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2103b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2104b5975d6bSopenharmony_ci   g_assert (regex);
2105b5975d6bSopenharmony_ci   g_assert_no_error (error);
2106b5975d6bSopenharmony_ci   res = g_regex_match (regex, "(middle)", 0, &match);
2107b5975d6bSopenharmony_ci@@ -2029,7 +2030,7 @@ test_recursion (void)
2108b5975d6bSopenharmony_ci   g_match_info_free (match);
2109b5975d6bSopenharmony_ci   g_regex_unref (regex);
2110b5975d6bSopenharmony_ci 
2111b5975d6bSopenharmony_ci-  regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2112b5975d6bSopenharmony_ci+  regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2113b5975d6bSopenharmony_ci   g_assert (regex);
2114b5975d6bSopenharmony_ci   g_assert_no_error (error);
2115b5975d6bSopenharmony_ci   res = g_regex_match (regex, "((((((((((((((((middle))))))))))))))))", 0, &match);
2116b5975d6bSopenharmony_ci@@ -2042,7 +2043,7 @@ test_recursion (void)
2117b5975d6bSopenharmony_ci   g_match_info_free (match);
2118b5975d6bSopenharmony_ci   g_regex_unref (regex);
2119b5975d6bSopenharmony_ci 
2120b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2121b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2122b5975d6bSopenharmony_ci   g_assert (regex);
2123b5975d6bSopenharmony_ci   g_assert_no_error (error);
2124b5975d6bSopenharmony_ci   g_regex_match (regex, "(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()", 0, &match);
2125b5975d6bSopenharmony_ci@@ -2051,7 +2052,7 @@ test_recursion (void)
2126b5975d6bSopenharmony_ci   g_match_info_free (match);
2127b5975d6bSopenharmony_ci   g_regex_unref (regex);
2128b5975d6bSopenharmony_ci 
2129b5975d6bSopenharmony_ci-  regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2130b5975d6bSopenharmony_ci+  regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
2131b5975d6bSopenharmony_ci   g_assert (regex);
2132b5975d6bSopenharmony_ci   g_assert_no_error (error);
2133b5975d6bSopenharmony_ci   res = g_regex_match (regex, "<ab<01<23<4>>>>", 0, &match);
2134b5975d6bSopenharmony_ci@@ -2070,7 +2071,7 @@ test_recursion (void)
2135b5975d6bSopenharmony_ci   g_match_info_free (match);
2136b5975d6bSopenharmony_ci   g_regex_unref (regex);
2137b5975d6bSopenharmony_ci 
2138b5975d6bSopenharmony_ci-  regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2139b5975d6bSopenharmony_ci+  regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2140b5975d6bSopenharmony_ci   g_assert (regex);
2141b5975d6bSopenharmony_ci   g_assert_no_error (error);
2142b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
2143b5975d6bSopenharmony_ci@@ -2083,7 +2084,7 @@ test_recursion (void)
2144b5975d6bSopenharmony_ci   g_match_info_free (match);
2145b5975d6bSopenharmony_ci   g_regex_unref (regex);
2146b5975d6bSopenharmony_ci 
2147b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
2148b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
2149b5975d6bSopenharmony_ci   g_assert (regex);
2150b5975d6bSopenharmony_ci   g_assert_no_error (error);
2151b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
2152b5975d6bSopenharmony_ci@@ -2096,7 +2097,7 @@ test_recursion (void)
2153b5975d6bSopenharmony_ci   g_match_info_free (match);
2154b5975d6bSopenharmony_ci   g_regex_unref (regex);
2155b5975d6bSopenharmony_ci 
2156b5975d6bSopenharmony_ci-  regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$", G_REGEX_OPTIMIZE|G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &error);
2157b5975d6bSopenharmony_ci+  regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &error);
2158b5975d6bSopenharmony_ci   g_assert (regex);
2159b5975d6bSopenharmony_ci   g_assert_no_error (error);
2160b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
2161b5975d6bSopenharmony_ci@@ -2167,21 +2168,21 @@ test_max_lookbehind (void)
2162b5975d6bSopenharmony_ci }
2163b5975d6bSopenharmony_ci 
2164b5975d6bSopenharmony_ci static gboolean
2165b5975d6bSopenharmony_ci-pcre_ge (guint64 major, guint64 minor)
2166b5975d6bSopenharmony_ci+pcre2_ge (guint64 major, guint64 minor)
2167b5975d6bSopenharmony_ci {
2168b5975d6bSopenharmony_ci-    const char *version;
2169b5975d6bSopenharmony_ci-    gchar *ptr;
2170b5975d6bSopenharmony_ci-    guint64 pcre_major, pcre_minor;
2171b5975d6bSopenharmony_ci+    gchar version[32];
2172b5975d6bSopenharmony_ci+    const gchar *ptr;
2173b5975d6bSopenharmony_ci+    guint64 pcre2_major, pcre2_minor;
2174b5975d6bSopenharmony_ci 
2175b5975d6bSopenharmony_ci-    /* e.g. 8.35 2014-04-04 */
2176b5975d6bSopenharmony_ci-    version = pcre_version ();
2177b5975d6bSopenharmony_ci+    /* e.g. 10.36 2020-12-04 */
2178b5975d6bSopenharmony_ci+    pcre2_config (PCRE2_CONFIG_VERSION, version);
2179b5975d6bSopenharmony_ci 
2180b5975d6bSopenharmony_ci-    pcre_major = g_ascii_strtoull (version, &ptr, 10);
2181b5975d6bSopenharmony_ci+    pcre2_major = g_ascii_strtoull (version, (gchar **) &ptr, 10);
2182b5975d6bSopenharmony_ci     /* ptr points to ".MINOR (release date)" */
2183b5975d6bSopenharmony_ci     g_assert (ptr[0] == '.');
2184b5975d6bSopenharmony_ci-    pcre_minor = g_ascii_strtoull (ptr + 1, NULL, 10);
2185b5975d6bSopenharmony_ci+    pcre2_minor = g_ascii_strtoull (ptr + 1, NULL, 10);
2186b5975d6bSopenharmony_ci 
2187b5975d6bSopenharmony_ci-    return (pcre_major > major) || (pcre_major == major && pcre_minor >= minor);
2188b5975d6bSopenharmony_ci+    return (pcre2_major > major) || (pcre2_major == major && pcre2_minor >= minor);
2189b5975d6bSopenharmony_ci }
2190b5975d6bSopenharmony_ci 
2191b5975d6bSopenharmony_ci int
2192b5975d6bSopenharmony_ci@@ -2203,18 +2204,26 @@ main (int argc, char *argv[])
2193b5975d6bSopenharmony_ci   g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
2194b5975d6bSopenharmony_ci 
2195b5975d6bSopenharmony_ci   /* TEST_NEW(pattern, compile_opts, match_opts) */
2196b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2197b5975d6bSopenharmony_ci   TEST_NEW("[A-Z]+", G_REGEX_CASELESS | G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTBOL | G_REGEX_MATCH_PARTIAL);
2198b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
2199b5975d6bSopenharmony_ci   TEST_NEW("", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2200b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2201b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2202b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
2203b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
2204b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_MULTILINE, G_REGEX_MATCH_DEFAULT);
2205b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DOTALL, G_REGEX_MATCH_DEFAULT);
2206b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DOTALL, G_REGEX_MATCH_NOTBOL);
2207b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2208b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT);
2209b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2210b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS | G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
2211b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
2212b5975d6bSopenharmony_ci   TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT);
2213b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2214b5975d6bSopenharmony_ci   TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES | G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
2215b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
2216b5975d6bSopenharmony_ci   /* This gives "internal error: code overflow" with pcre 6.0 */
2217b5975d6bSopenharmony_ci   TEST_NEW("(?i)(?-i)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2218b5975d6bSopenharmony_ci   TEST_NEW ("(?i)a", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2219b5975d6bSopenharmony_ci@@ -2225,9 +2234,10 @@ main (int argc, char *argv[])
2220b5975d6bSopenharmony_ci   TEST_NEW ("(?U)[a-z]+", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
2221b5975d6bSopenharmony_ci 
2222b5975d6bSopenharmony_ci   /* TEST_NEW_CHECK_FLAGS(pattern, compile_opts, match_ops, real_compile_opts, real_match_opts) */
2223b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2224b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("a", G_REGEX_OPTIMIZE, 0, G_REGEX_OPTIMIZE, 0);
2225b5975d6bSopenharmony_ci+G_GNUC_END_IGNORE_DEPRECATIONS
2226b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("a", G_REGEX_RAW, 0, G_REGEX_RAW, 0);
2227b5975d6bSopenharmony_ci-  TEST_NEW_CHECK_FLAGS ("(?X)a", 0, 0, 0 /* not exposed by GRegex */, 0);
2228b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("^.*", 0, 0, G_REGEX_ANCHORED, 0);
2229b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("(*UTF8)a", 0, 0, 0 /* this is the default in GRegex */, 0);
2230b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("(*UCP)a", 0, 0, 0 /* this always on in GRegex */, 0);
2231b5975d6bSopenharmony_ci@@ -2255,16 +2265,16 @@ main (int argc, char *argv[])
2232b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a{4,2}", 0, G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER);
2233b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a{999999,}", 0, G_REGEX_ERROR_QUANTIFIER_TOO_BIG);
2234b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("[a-z", 0, G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS);
2235b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("(?X)[\\B]", 0, G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS);
2236b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("[\\B]", 0, G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS);
2237b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("[z-a]", 0, G_REGEX_ERROR_RANGE_OUT_OF_ORDER);
2238b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("{2,4}", 0, G_REGEX_ERROR_NOTHING_TO_REPEAT);
2239b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(?u)", 0, G_REGEX_ERROR_UNRECOGNIZED_CHARACTER);
2240b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("a(?<$foo)bar", 0, G_REGEX_ERROR_UNRECOGNIZED_CHARACTER);
2241b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("a(?<$foo)bar", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME);
2242b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a[:alpha:]b", 0, G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS);
2243b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(b", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
2244b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a)b", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
2245b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(?R", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
2246b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("a(?-54", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
2247b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("a(?-54", 0, G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE);
2248b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(ab\\2)", 0, G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE);
2249b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(?#abc", 0, G_REGEX_ERROR_UNTERMINATED_COMMENT);
2250b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(?<=a+)b", 0, G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND);
2251b5975d6bSopenharmony_ci@@ -2274,51 +2284,31 @@ main (int argc, char *argv[])
2252b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a[[:fubar:]]b", 0, G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME);
2253b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("[[.ch.]]", 0, G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED);
2254b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("\\x{110000}", 0, G_REGEX_ERROR_HEX_CODE_TOO_LARGE);
2255b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("^(?(0)f|b)oo", 0, G_REGEX_ERROR_INVALID_CONDITION);
2256b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("^(?(0)f|b)oo", 0, G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE);
2257b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(?<=\\C)X", 0, G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND);
2258b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("(?!\\w)(?R)", 0, G_REGEX_ERROR_INFINITE_LOOP);
2259b5975d6bSopenharmony_ci-  if (pcre_ge (8, 37))
2260b5975d6bSopenharmony_ci-    {
2261b5975d6bSopenharmony_ci-      /* The expected errors changed here. */
2262b5975d6bSopenharmony_ci-      TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_ASSERTION_EXPECTED);
2263b5975d6bSopenharmony_ci-    }
2264b5975d6bSopenharmony_ci-  else
2265b5975d6bSopenharmony_ci-    {
2266b5975d6bSopenharmony_ci-      TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
2267b5975d6bSopenharmony_ci-    }
2268b5975d6bSopenharmony_ci-
2269b5975d6bSopenharmony_ci-  if (pcre_ge (8, 35))
2270b5975d6bSopenharmony_ci-    {
2271b5975d6bSopenharmony_ci-      /* The expected errors changed here. */
2272b5975d6bSopenharmony_ci-      TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
2273b5975d6bSopenharmony_ci-    }
2274b5975d6bSopenharmony_ci-  else
2275b5975d6bSopenharmony_ci-    {
2276b5975d6bSopenharmony_ci-      TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_BACK_REFERENCE);
2277b5975d6bSopenharmony_ci-    }
2278b5975d6bSopenharmony_ci+  TEST_NEW ("(?!\\w)(?R)", 0, 0);
2279b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_ASSERTION_EXPECTED);
2280b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
2281b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(?P<x>eks)(?P<x>eccs)", 0, G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME);
2282b5975d6bSopenharmony_ci-#if 0
2283b5975d6bSopenharmony_ci-  TEST_NEW_FAIL (?, 0, G_REGEX_ERROR_MALFORMED_PROPERTY);
2284b5975d6bSopenharmony_ci-  TEST_NEW_FAIL (?, 0, G_REGEX_ERROR_UNKNOWN_PROPERTY);
2285b5975d6bSopenharmony_ci-#endif
2286b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("\\666", G_REGEX_RAW, G_REGEX_ERROR_INVALID_OCTAL_VALUE);
2287b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("^(?(DEFINE) abc | xyz ) ", 0, G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE);
2288b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a", G_REGEX_NEWLINE_CRLF | G_REGEX_NEWLINE_ANYCRLF, G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS);
2289b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("^(a)\\g{3", 0, G_REGEX_ERROR_MISSING_BACK_REFERENCE);
2290b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("^(a)\\g{0}", 0, G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE);
2291b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("abc(*FAIL:123)xyz", 0, G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN);
2292b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("^(a)\\g{0}", 0, G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE);
2293b5975d6bSopenharmony_ci+  TEST_NEW ("abc(*FAIL:123)xyz", 0, 0);
2294b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(*FOOBAR)b", 0, G_REGEX_ERROR_UNKNOWN_BACKTRACKING_CONTROL_VERB);
2295b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("(?i:A{1,}\\6666666666)", 0, G_REGEX_ERROR_NUMBER_TOO_BIG);
2296b5975d6bSopenharmony_ci+  if (pcre2_ge (10, 37))
2297b5975d6bSopenharmony_ci+    {
2298b5975d6bSopenharmony_ci+      TEST_NEW ("(?i:A{1,}\\6666666666)", 0, 0);
2299b5975d6bSopenharmony_ci+    }
2300b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(?<a>)(?&)", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME);
2301b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("(?+-a)", 0, G_REGEX_ERROR_MISSING_DIGIT);
2302b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("TA]", G_REGEX_JAVASCRIPT_COMPAT, G_REGEX_ERROR_INVALID_DATA_CHARACTER);
2303b5975d6bSopenharmony_ci+  TEST_NEW_FAIL ("(?+-a)", 0, G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE);
2304b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(?|(?<a>A)|(?<b>B))", 0, G_REGEX_ERROR_EXTRA_SUBPATTERN_NAME);
2305b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a(*MARK)b", 0, G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED);
2306b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("^\\c€", 0, G_REGEX_ERROR_INVALID_CONTROL_CHAR);
2307b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("\\k", 0, G_REGEX_ERROR_MISSING_NAME);
2308b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("a[\\NB]c", 0, G_REGEX_ERROR_NOT_SUPPORTED_IN_CLASS);
2309b5975d6bSopenharmony_ci   TEST_NEW_FAIL ("(*:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEFG)XX", 0, G_REGEX_ERROR_NAME_TOO_LONG);
2310b5975d6bSopenharmony_ci-  TEST_NEW_FAIL ("\\u0100", G_REGEX_RAW | G_REGEX_JAVASCRIPT_COMPAT, G_REGEX_ERROR_CHARACTER_VALUE_TOO_LARGE);
2311b5975d6bSopenharmony_ci 
2312b5975d6bSopenharmony_ci   /* These errors can't really be tested easily:
2313b5975d6bSopenharmony_ci    * G_REGEX_ERROR_EXPRESSION_TOO_LARGE
2314b5975d6bSopenharmony_ci@@ -2474,7 +2464,15 @@ main (int argc, char *argv[])
2315b5975d6bSopenharmony_ci   TEST_MATCH("a#\nb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
2316b5975d6bSopenharmony_ci   TEST_MATCH("a#\r\nb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
2317b5975d6bSopenharmony_ci   TEST_MATCH("a#\rb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
2318b5975d6bSopenharmony_ci-  TEST_MATCH("a#\nb", G_REGEX_EXTENDED, G_REGEX_MATCH_NEWLINE_CR, "a", -1, 0, 0, FALSE);
2319b5975d6bSopenharmony_ci+  /* Due to PCRE2 only supporting newline settings passed to pcre2_compile (and
2320b5975d6bSopenharmony_ci+   * not to pcre2_match also), we have to compile the pattern with the
2321b5975d6bSopenharmony_ci+   * effective (combined from compile and match options) newline setting.
2322b5975d6bSopenharmony_ci+   * However, this setting also affects how newlines are interpreted *inside*
2323b5975d6bSopenharmony_ci+   * the pattern. With G_REGEX_EXTENDED, this changes where the comment
2324b5975d6bSopenharmony_ci+   * (started with `#`) ends.
2325b5975d6bSopenharmony_ci+   */
2326b5975d6bSopenharmony_ci+  /* On PCRE1, this test expected no match; on PCRE2 it matches because of the above. */
2327b5975d6bSopenharmony_ci+  TEST_MATCH("a#\nb", G_REGEX_EXTENDED, G_REGEX_MATCH_NEWLINE_CR, "a", -1, 0, 0, TRUE /*FALSE*/);
2328b5975d6bSopenharmony_ci   TEST_MATCH("a#\nb", G_REGEX_EXTENDED | G_REGEX_NEWLINE_CR, 0, "a", -1, 0, 0, TRUE);
2329b5975d6bSopenharmony_ci 
2330b5975d6bSopenharmony_ci   TEST_MATCH("line\nbreak", G_REGEX_MULTILINE, 0, "this is a line\nbreak", -1, 0, 0, TRUE);
2331b5975d6bSopenharmony_ci@@ -2487,21 +2485,19 @@ main (int argc, char *argv[])
2332b5975d6bSopenharmony_ci    * with pcre's internal tables. Bug #678273 */
2333b5975d6bSopenharmony_ci   TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "DŽ", -1, 0, 0, TRUE);
2334b5975d6bSopenharmony_ci   TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "dž", -1, 0, 0, TRUE);
2335b5975d6bSopenharmony_ci-#if PCRE_MAJOR > 8 || (PCRE_MAJOR == 8 && PCRE_MINOR >= 32)
2336b5975d6bSopenharmony_ci-  /* This would incorrectly fail to match in pcre < 8.32, so only assert
2337b5975d6bSopenharmony_ci-   * this for known-good pcre. */
2338b5975d6bSopenharmony_ci   TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "Dž", -1, 0, 0, TRUE);
2339b5975d6bSopenharmony_ci-#endif
2340b5975d6bSopenharmony_ci 
2341b5975d6bSopenharmony_ci   /* TEST_MATCH_NEXT#(pattern, string, string_len, start_position, ...) */
2342b5975d6bSopenharmony_ci   TEST_MATCH_NEXT0("a", "x", -1, 0);
2343b5975d6bSopenharmony_ci   TEST_MATCH_NEXT0("a", "ax", -1, 1);
2344b5975d6bSopenharmony_ci   TEST_MATCH_NEXT0("a", "xa", 1, 0);
2345b5975d6bSopenharmony_ci   TEST_MATCH_NEXT0("a", "axa", 1, 2);
2346b5975d6bSopenharmony_ci+  TEST_MATCH_NEXT1("", "", -1, 0, "", 0, 0);
2347b5975d6bSopenharmony_ci   TEST_MATCH_NEXT1("a", "a", -1, 0, "a", 0, 1);
2348b5975d6bSopenharmony_ci   TEST_MATCH_NEXT1("a", "xax", -1, 0, "a", 1, 2);
2349b5975d6bSopenharmony_ci   TEST_MATCH_NEXT1(EURO, ENG EURO, -1, 0, EURO, 2, 5);
2350b5975d6bSopenharmony_ci   TEST_MATCH_NEXT1("a*", "", -1, 0, "", 0, 0);
2351b5975d6bSopenharmony_ci+  TEST_MATCH_NEXT2("", "a", -1, 0, "", 0, 0, "", 1, 1);
2352b5975d6bSopenharmony_ci   TEST_MATCH_NEXT2("a*", "aa", -1, 0, "aa", 0, 2, "", 2, 2);
2353b5975d6bSopenharmony_ci   TEST_MATCH_NEXT2(EURO "*", EURO EURO, -1, 0, EURO EURO, 0, 6, "", 6, 6);
2354b5975d6bSopenharmony_ci   TEST_MATCH_NEXT2("a", "axa", -1, 0, "a", 0, 1, "a", 2, 3);
2355b5975d6bSopenharmony_ci@@ -2675,11 +2671,6 @@ main (int argc, char *argv[])
2356b5975d6bSopenharmony_ci   TEST_EXPAND("a", "a", "\\0130", FALSE, "X");
2357b5975d6bSopenharmony_ci   TEST_EXPAND("a", "a", "\\\\\\0", FALSE, "\\a");
2358b5975d6bSopenharmony_ci   TEST_EXPAND("a(?P<G>.)c", "xabcy", "X\\g<G>X", FALSE, "XbX");
2359b5975d6bSopenharmony_ci-#if !(PCRE_MAJOR > 8 || (PCRE_MAJOR == 8 && PCRE_MINOR >= 34))
2360b5975d6bSopenharmony_ci-  /* PCRE >= 8.34 no longer allows this usage. */
2361b5975d6bSopenharmony_ci-  TEST_EXPAND("(.)(?P<1>.)", "ab", "\\1", FALSE, "a");
2362b5975d6bSopenharmony_ci-  TEST_EXPAND("(.)(?P<1>.)", "ab", "\\g<1>", FALSE, "a");
2363b5975d6bSopenharmony_ci-#endif
2364b5975d6bSopenharmony_ci   TEST_EXPAND(".", EURO, "\\0", FALSE, EURO);
2365b5975d6bSopenharmony_ci   TEST_EXPAND("(.)", EURO, "\\1", FALSE, EURO);
2366b5975d6bSopenharmony_ci   TEST_EXPAND("(?P<G>.)", EURO, "\\g<G>", FALSE, EURO);
2367b5975d6bSopenharmony_ci@@ -2798,6 +2789,10 @@ main (int argc, char *argv[])
2368b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "A", 1);
2369b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "B", 2);
2370b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "C", -1);
2371b5975d6bSopenharmony_ci+  TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)(?P<C>b)", "A", 1);
2372b5975d6bSopenharmony_ci+  TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)(?P<C>b)", "B", 2);
2373b5975d6bSopenharmony_ci+  TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)(?P<C>b)", "C", 3);
2374b5975d6bSopenharmony_ci+  TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)(?P<C>b)", "D", -1);
2375b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "A", 1);
2376b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "B", 3);
2377b5975d6bSopenharmony_ci   TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "C", -1);
2378b5975d6bSopenharmony_cidiff --git a/meson.build b/meson.build
2379b5975d6bSopenharmony_ciindex 882049c..657e9f6 100644
2380b5975d6bSopenharmony_ci--- a/meson.build
2381b5975d6bSopenharmony_ci+++ b/meson.build
2382b5975d6bSopenharmony_ci@@ -2024,37 +2024,38 @@ else
2383b5975d6bSopenharmony_ci   endif
2384b5975d6bSopenharmony_ci endif
2385b5975d6bSopenharmony_ci 
2386b5975d6bSopenharmony_ci-pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
2387b5975d6bSopenharmony_ci-if not pcre.found()
2388b5975d6bSopenharmony_ci+pcre2 = dependency('libpcre2-8', version: '>= 10.32', required : false)
2389b5975d6bSopenharmony_ci+if not pcre2.found()
2390b5975d6bSopenharmony_ci   if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
2391b5975d6bSopenharmony_ci-  # MSVC: Search for the PCRE library by the configuration, which corresponds
2392b5975d6bSopenharmony_ci-  # to the output of CMake builds of PCRE.  Note that debugoptimized
2393b5975d6bSopenharmony_ci+  # MSVC: Search for the PCRE2 library by the configuration, which corresponds
2394b5975d6bSopenharmony_ci+  # to the output of CMake builds of PCRE2.  Note that debugoptimized
2395b5975d6bSopenharmony_ci   # is really a Release build with .PDB files.
2396b5975d6bSopenharmony_ci     if vs_crt == 'debug'
2397b5975d6bSopenharmony_ci-      pcre = cc.find_library('pcred', required : false)
2398b5975d6bSopenharmony_ci+      pcre2 = cc.find_library('pcre2d-8', required : false)
2399b5975d6bSopenharmony_ci     else
2400b5975d6bSopenharmony_ci-      pcre = cc.find_library('pcre', required : false)
2401b5975d6bSopenharmony_ci+      pcre2 = cc.find_library('pcre2-8', required : false)
2402b5975d6bSopenharmony_ci     endif
2403b5975d6bSopenharmony_ci   endif
2404b5975d6bSopenharmony_ci endif
2405b5975d6bSopenharmony_ci 
2406b5975d6bSopenharmony_ci # Try again with the fallback
2407b5975d6bSopenharmony_ci-if not pcre.found()
2408b5975d6bSopenharmony_ci-  pcre = dependency('libpcre', required : true, fallback : ['pcre', 'pcre_dep'])
2409b5975d6bSopenharmony_ci-  use_pcre_static_flag = true
2410b5975d6bSopenharmony_ci+if not pcre2.found()
2411b5975d6bSopenharmony_ci+  pcre2 = dependency('libpcre2-8', required : true, fallback : ['pcre2', 'libpcre2_8'])
2412b5975d6bSopenharmony_ci+  use_pcre2_static_flag = true
2413b5975d6bSopenharmony_ci elif host_system == 'windows'
2414b5975d6bSopenharmony_ci-  pcre_static = cc.links('''#define PCRE_STATIC
2415b5975d6bSopenharmony_ci-                            #include <pcre.h>
2416b5975d6bSopenharmony_ci-                            int main() {
2417b5975d6bSopenharmony_ci-                              void *p = NULL;
2418b5975d6bSopenharmony_ci-                              pcre_free(p);
2419b5975d6bSopenharmony_ci-                              return 0;
2420b5975d6bSopenharmony_ci-                            }''',
2421b5975d6bSopenharmony_ci-                         dependencies: pcre,
2422b5975d6bSopenharmony_ci-                         name : 'Windows system PCRE is a static build')
2423b5975d6bSopenharmony_ci-  use_pcre_static_flag = pcre_static
2424b5975d6bSopenharmony_ci+  pcre2_static = cc.links('''#define PCRE2_STATIC
2425b5975d6bSopenharmony_ci+                             #define PCRE2_CODE_UNIT_WIDTH 8
2426b5975d6bSopenharmony_ci+                             #include <pcre2.h>
2427b5975d6bSopenharmony_ci+                             int main() {
2428b5975d6bSopenharmony_ci+                               void *p = NULL;
2429b5975d6bSopenharmony_ci+                               pcre2_code_free(p);
2430b5975d6bSopenharmony_ci+                               return 0;
2431b5975d6bSopenharmony_ci+                             }''',
2432b5975d6bSopenharmony_ci+                         dependencies: pcre2,
2433b5975d6bSopenharmony_ci+                         name : 'Windows system PCRE2 is a static build')
2434b5975d6bSopenharmony_ci+  use_pcre2_static_flag = pcre2_static
2435b5975d6bSopenharmony_ci else
2436b5975d6bSopenharmony_ci-  use_pcre_static_flag = false
2437b5975d6bSopenharmony_ci+  use_pcre2_static_flag = false
2438b5975d6bSopenharmony_ci endif
2439b5975d6bSopenharmony_ci 
2440b5975d6bSopenharmony_ci libm = cc.find_library('m', required : false)
2441b5975d6bSopenharmony_cidiff --git a/po/sk.po b/po/sk.po
2442b5975d6bSopenharmony_ciindex 8d6a1ce..747ad27 100644
2443b5975d6bSopenharmony_ci--- a/po/sk.po
2444b5975d6bSopenharmony_ci+++ b/po/sk.po
2445b5975d6bSopenharmony_ci@@ -5630,7 +5630,7 @@ msgstr "zlý ofset"
2446b5975d6bSopenharmony_ci msgid "short utf8"
2447b5975d6bSopenharmony_ci msgstr "krátke utf8"
2448b5975d6bSopenharmony_ci 
2449b5975d6bSopenharmony_ci-# Ide o omyl programátora: case PCRE_ERROR_RECURSELOOP: return _("recursion loop");
2450b5975d6bSopenharmony_ci+# Ide o omyl programátora: case PCRE2_ERROR_RECURSELOOP: return _("recursion loop");
2451b5975d6bSopenharmony_ci #: glib/gregex.c:303
2452b5975d6bSopenharmony_ci msgid "recursion loop"
2453b5975d6bSopenharmony_ci msgstr "rekurzívna slučka"
2454b5975d6bSopenharmony_cidiff --git a/subprojects/pcre.wrap b/subprojects/pcre.wrap
2455b5975d6bSopenharmony_cideleted file mode 100644
2456b5975d6bSopenharmony_ciindex a6b07b9..0000000
2457b5975d6bSopenharmony_ci--- a/subprojects/pcre.wrap
2458b5975d6bSopenharmony_ci+++ /dev/null
2459b5975d6bSopenharmony_ci@@ -1,11 +0,0 @@
2460b5975d6bSopenharmony_ci-[wrap-file]
2461b5975d6bSopenharmony_ci-directory = pcre-8.37
2462b5975d6bSopenharmony_ci-source_url = https://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.bz2
2463b5975d6bSopenharmony_ci-source_filename = pcre-8.37.tar.bz2
2464b5975d6bSopenharmony_ci-source_hash = 51679ea8006ce31379fb0860e46dd86665d864b5020fc9cd19e71260eef4789d
2465b5975d6bSopenharmony_ci-patch_filename = pcre_8.37-4_patch.zip
2466b5975d6bSopenharmony_ci-patch_url = https://wrapdb.mesonbuild.com/v2/pcre_8.37-4/get_patch
2467b5975d6bSopenharmony_ci-patch_hash = c957f42da6f6378300eb8a18f4a5cccdb8e2aada51a703cac842982f9f785399
2468b5975d6bSopenharmony_ci-
2469b5975d6bSopenharmony_ci-[provide]
2470b5975d6bSopenharmony_ci-libpcre = pcre_dep
2471b5975d6bSopenharmony_ci-- 
2472b5975d6bSopenharmony_ci2.33.0
2473b5975d6bSopenharmony_ci
2474