2 Copyright (C) 2002-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <sys/types.h>
27 main (int argc
, char *argv
[])
32 const char *locales
[] = { "C", "C.UTF-8", "de_DE.UTF-8" };
33 const char *string
= "http://www.regex.com/pattern/matching.html#intro";
34 regmatch_t expect
[10] = {
35 { 0, 48 }, { 0, 5 }, { 0, 4 }, { 5, 20 }, { 7, 20 }, { 20, 42 },
36 { -1, -1 }, { -1, -1 }, { 42, 48 }, { 43, 48 } };
38 for (i
= 0; i
< sizeof (locales
) / sizeof (locales
[0]); ++i
)
40 if (setlocale (LC_ALL
, locales
[i
]) == NULL
)
42 puts ("cannot set locale");
45 else if (regcomp (&re
,
46 "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?",
47 REG_EXTENDED
) != REG_NOERROR
)
49 puts ("cannot compile the regular expression");
52 else if (regexec (&re
, string
, 10, mat
, 0) == REG_NOMATCH
)
59 if (! memcmp (mat
, expect
, sizeof (mat
)))
60 printf ("matching ok for %s locale\n", locales
[i
]);
63 printf ("matching failed for %s locale:\n", locales
[i
]);
65 for (j
= 0; j
< 9; ++j
)
66 if (mat
[j
].rm_so
!= -1)
67 printf ("%d: %.*s\n", j
, mat
[j
].rm_eo
- mat
[j
].rm_so
,
68 string
+ mat
[j
].rm_so
);