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