1 | #include <locale.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <string.h> |
4 | #include <regex.h> |
5 | #include <wchar.h> |
6 | |
7 | int |
8 | main (void) |
9 | { |
10 | struct re_pattern_buffer regex; |
11 | struct re_registers regs; |
12 | const char *s; |
13 | int match; |
14 | int result = 0; |
15 | |
16 | memset (®ex, '\0', sizeof (regex)); |
17 | |
18 | setlocale (LC_ALL, "de_DE.ISO-8859-1"); |
19 | fwide (stdout, mode: -1); |
20 | |
21 | re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_DEBUG); |
22 | |
23 | puts (s: "in C locale"); |
24 | setlocale (LC_ALL, "C"); |
25 | s = re_compile_pattern (pattern: "[an\371]*n", length: 7, buffer: ®ex); |
26 | if (s != NULL) |
27 | { |
28 | puts (s: "re_compile_pattern return non-NULL value"); |
29 | result = 1; |
30 | } |
31 | else |
32 | { |
33 | match = re_match (buffer: ®ex, String: "an", length: 2, start: 0, regs: ®s); |
34 | if (match != 2) |
35 | { |
36 | printf (format: "re_match returned %d, expected 2\n", match); |
37 | result = 1; |
38 | } |
39 | else |
40 | puts (s: " -> OK"); |
41 | } |
42 | |
43 | puts (s: "in C.UTF-8 locale"); |
44 | setlocale (LC_ALL, "C.UTF-8"); |
45 | s = re_compile_pattern (pattern: "[an\371]*n", length: 7, buffer: ®ex); |
46 | if (s != NULL) |
47 | { |
48 | puts (s: "re_compile_pattern return non-NULL value"); |
49 | result = 1; |
50 | } |
51 | else |
52 | { |
53 | match = re_match (buffer: ®ex, String: "an", length: 2, start: 0, regs: ®s); |
54 | if (match != 2) |
55 | { |
56 | printf (format: "re_match returned %d, expected 2\n", match); |
57 | result = 1; |
58 | } |
59 | else |
60 | puts (s: " -> OK"); |
61 | } |
62 | |
63 | puts (s: "in de_DE.ISO-8859-1 locale"); |
64 | setlocale (LC_ALL, "de_DE.ISO-8859-1"); |
65 | s = re_compile_pattern (pattern: "[an\371]*n", length: 7, buffer: ®ex); |
66 | if (s != NULL) |
67 | { |
68 | puts (s: "re_compile_pattern return non-NULL value"); |
69 | result = 1; |
70 | } |
71 | else |
72 | { |
73 | match = re_match (buffer: ®ex, String: "an", length: 2, start: 0, regs: ®s); |
74 | if (match != 2) |
75 | { |
76 | printf (format: "re_match returned %d, expected 2\n", match); |
77 | result = 1; |
78 | } |
79 | else |
80 | puts (s: " -> OK"); |
81 | } |
82 | |
83 | return result; |
84 | } |
85 |