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*");
20 regex = "(H..).(o..)";
21 SILC_LOG_DEBUG(("Regex %s", regex));
22 if (!silc_regex_compile(®, regex, 0))
25 string = "Hello World";
26 SILC_LOG_DEBUG(("Match %s", string));
27 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
29 for (i = 0; i < num_match; i++) {
30 if (match[i].start != -1) {
31 SILC_LOG_DEBUG(("Match start %d, end %d", match[i].start,
33 sub = silc_memdup(string + match[i].start, match[i].end -
35 SILC_LOG_DEBUG(("Match substring '%s'", sub));
40 silc_regex_free(®);
43 SILC_LOG_DEBUG(("Regex %s", regex));
44 if (!silc_regex_compile(®, regex, 0))
48 SILC_LOG_DEBUG(("Match %s", string));
49 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
53 SILC_LOG_DEBUG(("Match %s", string));
54 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
57 string = "foo20, bar, foo100, foo";
58 SILC_LOG_DEBUG(("Match all substrings in %s", string));
59 while (silc_regex_match(®, string, strlen(string), 1, match, 0)) {
60 SILC_LOG_DEBUG(("Match start %d", match[0].start));
61 sub = silc_memdup(string + match[0].start, match[0].end - match[0].start);
62 SILC_LOG_DEBUG(("Match substring '%s'", sub));
64 string += match[0].end;
67 string = "foo20, bar, foo100, Foo, foo0";
68 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
69 if (!silc_regex_match(®, string, strlen(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 silc_regex_free(®);
84 regex = "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)";
85 SILC_LOG_DEBUG(("Regex %s", regex));
86 if (!silc_regex_compile(®, regex, 0))
89 string = "http://silcnet.org:443/foobar/pelle.html";
90 SILC_LOG_DEBUG(("Parse URI"));
91 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
94 for (i = 0; i < num_match; i++) {
95 if (match[i].start != -1) {
96 SILC_LOG_DEBUG(("Match start %d", match[i].start));
97 sub = silc_memdup(string + match[i].start, match[i].end -
99 SILC_LOG_DEBUG(("Match substring '%s'", sub));
104 string = "http://silcnet.org/";
105 SILC_LOG_DEBUG(("Parse URI"));
106 if (!silc_regex_match(®, string, strlen(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(®);
122 SILC_LOG_DEBUG(("Regex %s", regex));
123 if (!silc_regex_compile(®, regex, 0))
127 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
128 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
131 for (i = 0; i < num_match; i++) {
132 if (match[i].start != -1) {
133 SILC_LOG_DEBUG(("Match start %d", match[i].start));
134 sub = silc_memdup(string + match[i].start, match[i].end -
136 SILC_LOG_DEBUG(("Match substring '%s'", sub));
141 silc_regex_free(®);
144 SILC_LOG_DEBUG(("Regex %s", regex));
145 if (!silc_regex_compile(®, regex, 0))
149 SILC_LOG_DEBUG(("Test NOTBOL flag", string));
150 if (silc_regex_match(®, string, strlen(string), 0, NULL,
153 if (silc_errno != SILC_ERR_NOT_FOUND)
155 SILC_LOG_DEBUG(("Did not match (OK)"));
157 silc_regex_free(®);
160 SILC_LOG_DEBUG(("Regex %s", regex));
161 if (!silc_regex_compile(®, regex, 0))
165 SILC_LOG_DEBUG(("Test NOTEOL flag", string));
166 if (silc_regex_match(®, string, strlen(string), 0, NULL,
169 if (silc_errno != SILC_ERR_NOT_FOUND)
171 SILC_LOG_DEBUG(("Did not match (OK)"));
173 silc_regex_free(®);
178 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
179 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");