1 /* Test re.translate != NULL.
2 Copyright (C) 2004-2024 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/>. */
28 struct re_pattern_buffer re
;
33 setlocale (LC_ALL
, "de_DE.ISO-8859-1");
35 for (i
= 0; i
< 256; ++i
)
36 trans
[i
] = tolower (i
);
38 re_set_syntax (RE_SYNTAX_POSIX_EGREP
);
40 memset (&re
, 0, sizeof (re
));
41 re
.translate
= (unsigned char *) trans
;
42 s
= re_compile_pattern ("\\W", 2, &re
);
46 printf ("failed to compile pattern \"\\W\": %s\n", s
);
51 int ret
= re_search (&re
, "abc.de", 6, 0, 6, NULL
);
54 printf ("1st re_search returned %d\n", ret
);
58 ret
= re_search (&re
, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL
);
61 printf ("2nd re_search returned %d\n", ret
);
68 memset (&re
, 0, sizeof (re
));
69 re
.translate
= (unsigned char *) trans
;
70 s
= re_compile_pattern ("\\w", 2, &re
);
74 printf ("failed to compile pattern \"\\w\": %s\n", s
);
79 int ret
= re_search (&re
, ".,!abc", 6, 0, 6, NULL
);
82 printf ("3rd re_search returned %d\n", ret
);
86 ret
= re_search (&re
, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL
);
89 printf ("4th re_search returned %d\n", ret
);
96 memset (&re
, 0, sizeof (re
));
97 re
.translate
= (unsigned char *) trans
;
98 s
= re_compile_pattern ("[[:DIGIT:]]", 11, &re
);
101 puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: "
106 memset (&re
, 0, sizeof (re
));
107 re
.translate
= (unsigned char *) trans
;
108 s
= re_compile_pattern ("[[:DIGIT:]]", 2, &re
);
111 puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: "