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