]> git.ipfire.org Git - thirdparty/glibc.git/blob - posix/bug-regex22.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / posix / bug-regex22.c
1 /* Test re.translate != NULL.
2 Copyright (C) 2004-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
5
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.
10
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.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <ctype.h>
21 #include <locale.h>
22 #include <regex.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 int
27 main (void)
28 {
29 struct re_pattern_buffer re;
30 char trans[256];
31 int i, result = 0;
32 const char *s;
33
34 setlocale (LC_ALL, "de_DE.ISO-8859-1");
35
36 for (i = 0; i < 256; ++i)
37 trans[i] = tolower (i);
38
39 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
40
41 memset (&re, 0, sizeof (re));
42 re.translate = (unsigned char *) trans;
43 s = re_compile_pattern ("\\W", 2, &re);
44
45 if (s != NULL)
46 {
47 printf ("failed to compile pattern \"\\W\": %s\n", s);
48 result = 1;
49 }
50 else
51 {
52 int ret = re_search (&re, "abc.de", 6, 0, 6, NULL);
53 if (ret != 3)
54 {
55 printf ("1st re_search returned %d\n", ret);
56 result = 1;
57 }
58
59 ret = re_search (&re, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL);
60 if (ret != 2)
61 {
62 printf ("2nd re_search returned %d\n", ret);
63 result = 1;
64 }
65 re.translate = NULL;
66 regfree (&re);
67 }
68
69 memset (&re, 0, sizeof (re));
70 re.translate = (unsigned char *) trans;
71 s = re_compile_pattern ("\\w", 2, &re);
72
73 if (s != NULL)
74 {
75 printf ("failed to compile pattern \"\\w\": %s\n", s);
76 result = 1;
77 }
78 else
79 {
80 int ret = re_search (&re, ".,!abc", 6, 0, 6, NULL);
81 if (ret != 3)
82 {
83 printf ("3rd re_search returned %d\n", ret);
84 result = 1;
85 }
86
87 ret = re_search (&re, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL);
88 if (ret != 2)
89 {
90 printf ("4th re_search returned %d\n", ret);
91 result = 1;
92 }
93 re.translate = NULL;
94 regfree (&re);
95 }
96
97 memset (&re, 0, sizeof (re));
98 re.translate = (unsigned char *) trans;
99 s = re_compile_pattern ("[[:DIGIT:]]", 11, &re);
100 if (s == NULL)
101 {
102 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
103 s);
104 result = 1;
105 }
106
107 memset (&re, 0, sizeof (re));
108 re.translate = (unsigned char *) trans;
109 s = re_compile_pattern ("[[:DIGIT:]]", 2, &re);
110 if (s == NULL)
111 {
112 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
113 s);
114 result = 1;
115 }
116
117 return result;
118 }