1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <sys/types.h>
22: #include <mcheck.h>
23: #include <regex.h>
24: #include <stdio.h>
25: #include <stdlib.h>
26: #include <locale.h>
27:
28:
29: struct
30: {
31: const char *pattern;
32: const char *string;
33: int flags, nmatch;
34: regmatch_t rm[5];
35: } tests[] = {
36:
37:
38:
39: { "\xc4\xb0I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
40: { { 2, 8 }, { -1, -1 } } },
41: { "[\xc4\xb0x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
42: { { 2, 8 }, { -1, -1 } } },
43: { "[^x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
44: { { 2, 8 }, { -1, -1 } } },
45: { "([[:alpha:]]i[[:xdigit:]])(\xc4\xb1*)(\xc4\xb0{2})",
46: "\xe2\x80\x94\xc4\xb1\xc4\xb0""fIi\xc4\xb0ii", REG_ICASE | REG_EXTENDED,
47: 4, { { 3, 12 }, { 3, 8 }, { 8, 9 }, { 9, 12 } } },
48: { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "SIi\xc4\xb0\xc4\xb0 is",
49: REG_ICASE | REG_EXTENDED, 4, { { 1, 9 }, { 5, 7 }, { 7, 7 }, { 7, 9 } } },
50: { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "\xc4\xb1\xc4\xb0\xc4\xb0iJ\xc4\xb1",
51: REG_ICASE | REG_EXTENDED, 4,
52: { { 0, 10 }, { 6, 7 }, { 7, 7 }, { 7, 10 } } },
53: };
54:
55: int
56: main (void)
57: {
58: regex_t re;
59: regmatch_t rm[5];
60: size_t i;
61: int n, ret = 0;
62:
63: setlocale (LC_ALL, "tr_TR.UTF-8");
64: for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
65: {
66: n = regcomp (&re, tests[i].pattern, tests[i].flags);
67: if (n != 0)
68: {
69: char buf[500];
70: regerror (n, &re, buf, sizeof (buf));
71: printf ("regcomp %zd failed: %s\n", i, buf);
72: ret = 1;
73: continue;
74: }
75:
76: if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0))
77: {
78: printf ("regexec %zd failed\n", i);
79: ret = 1;
80: regfree (&re);
81: continue;
82: }
83:
84: for (n = 0; n < tests[i].nmatch; ++n)
85: if (rm[n].rm_so != tests[i].rm[n].rm_so
86: || rm[n].rm_eo != tests[i].rm[n].rm_eo)
87: {
88: if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
89: break;
90: printf ("regexec match failure rm[%d] %d..%d\n",
91: n, rm[n].rm_so, rm[n].rm_eo);
92: ret = 1;
93: break;
94: }
95:
96: regfree (&re);
97: }
98:
99: return ret;
100: }