1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
3 // UNSUPPORTED: darwin, target={{.*solaris.*}}
11 #define __arraycount(a) ((sizeof(a) / sizeof(a[0])))
14 void test_matched(const regex_t
*preg
, const char *string
) {
15 int rv
= regexec(preg
, string
, 0, NULL
, 0);
17 printf("%s: matched\n", string
);
18 else if (rv
== REG_NOMATCH
)
19 printf("%s: not-matched\n", string
);
24 void test_print_matches(const regex_t
*preg
, const char *string
) {
26 int rv
= regexec(preg
, string
, __arraycount(rm
), rm
, 0);
28 for (size_t i
= 0; i
< __arraycount(rm
); i
++) {
29 // This condition shall be simplified, but verify that the data fields
31 if (rm
[i
].rm_so
== -1 && rm
[i
].rm_eo
== -1)
33 printf("matched[%zu]='%.*s'\n", i
, (int)(rm
[i
].rm_eo
- rm
[i
].rm_so
),
34 string
+ rm
[i
].rm_so
);
36 } else if (rv
== REG_NOMATCH
)
37 printf("%s: not-matched\n", string
);
47 int rv
= regcomp(®ex
, "[[:upper:]]\\([[:upper:]]\\)", 0);
50 test_matched(®ex
, "abc");
51 test_matched(®ex
, "ABC");
53 test_print_matches(®ex
, "ABC");
60 int rv
= regcomp(®ex
, "[[:upp:]]", 0);
64 regerror(rv
, ®ex
, errbuf
, sizeof errbuf
);
65 printf("error: %s\n", errbuf
);
71 // CHECK: abc: not-matched
72 // CHECK: ABC: matched
73 // CHECK: matched[0]='AB'
74 // CHECK: matched[1]='B'
75 // CHECK: error:{{.*}}