5 int main(int argc, char **argv)
7 SilcBool success = FALSE;
9 SilcRegexMatchStruct match[10];
10 int i, num_match = 10;
11 char *regex, *string, *sub;
13 if (argc > 1 && !strcmp(argv[1], "-d")) {
16 silc_log_debug_hexdump(TRUE);
17 silc_log_set_debug_string("*regex*,*errno*");
21 SILC_LOG_DEBUG(("Regex %s", regex));
22 if (!silc_regex_compile(®, regex, 0))
26 SILC_LOG_DEBUG(("Match %s", string));
27 if (!silc_regex_match(®, string, 0, NULL, 0))
31 SILC_LOG_DEBUG(("Match %s", string));
32 if (!silc_regex_match(®, string, 0, NULL, 0))
35 string = "foo20, bar, foo100, foo";
36 SILC_LOG_DEBUG(("Match all substrings in %s", string));
37 while (silc_regex_match(®, string, 1, match, 0)) {
38 SILC_LOG_DEBUG(("Match start %d", match[0].start));
39 sub = silc_memdup(string + match[0].start, match[0].end - match[0].start);
40 SILC_LOG_DEBUG(("Match substring '%s'", sub));
42 string += match[0].end;
45 string = "foo20, bar, foo100, Foo, foo0";
46 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
47 if (!silc_regex_match(®, string, num_match, match, 0))
50 for (i = 0; i < num_match; i++) {
51 if (match[i].start != -1) {
52 SILC_LOG_DEBUG(("Match start %d", match[i].start));
53 sub = silc_memdup(string + match[i].start, match[i].end -
55 SILC_LOG_DEBUG(("Match substring '%s'", sub));
60 silc_regex_free(®);
62 regex = "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)";
63 SILC_LOG_DEBUG(("Regex %s", regex));
64 if (!silc_regex_compile(®, regex, 0))
67 string = "http://silcnet.org:443/foobar/pelle.html";
68 SILC_LOG_DEBUG(("Parse URI"));
69 if (!silc_regex_match(®, string, num_match, match, 0))
72 for (i = 0; i < num_match; i++) {
73 if (match[i].start != -1) {
74 SILC_LOG_DEBUG(("Match start %d", match[i].start));
75 sub = silc_memdup(string + match[i].start, match[i].end -
77 SILC_LOG_DEBUG(("Match substring '%s'", sub));
82 string = "http://silcnet.org/";
83 SILC_LOG_DEBUG(("Parse URI"));
84 if (!silc_regex_match(®, string, num_match, match, 0))
87 for (i = 0; i < num_match; i++) {
88 if (match[i].start != -1) {
89 SILC_LOG_DEBUG(("Match start %d", match[i].start));
90 sub = silc_memdup(string + match[i].start, match[i].end -
92 SILC_LOG_DEBUG(("Match substring '%s'", sub));
97 silc_regex_free(®);
100 SILC_LOG_DEBUG(("Regex %s", regex));
101 if (!silc_regex_compile(®, regex, 0))
105 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
106 if (!silc_regex_match(®, string, num_match, match, 0))
109 for (i = 0; i < num_match; i++) {
110 if (match[i].start != -1) {
111 SILC_LOG_DEBUG(("Match start %d", match[i].start));
112 sub = silc_memdup(string + match[i].start, match[i].end -
114 SILC_LOG_DEBUG(("Match substring '%s'", sub));
119 silc_regex_free(®);
124 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
125 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");