5 #include <AD/strings/bm.h> // Boyer Moore
6 #include <AD/strings/kmp.h> // Knuth Morris Pratt
7 #include <AD/strings/kr.h> // Karp Rabin
8 #include <AD/strings/quark.h> // Atomic strings
9 #include <AD/strings/regexp.h> // Regular expression search
10 #include <AD/strings/string.h> // Dynamic strings
11 #include <AD/strings/twoway.h> // Two way string matcher
13 int main(int argc
, char * argv
[])
15 if (RegExp("[a-z]+").Match("The quick brown fox jumps over the lazy dog")
19 printf("unmatched\n");
21 const char * a
= "The quick brown fox";
22 const char * b
= "The lazy dog";
23 const char * c
= "The quick brown fox";
25 assert(kmp
.Match(a
) == 0);
27 assert(kmp
.Match(a
) == 16);
29 assert(kmp
.Match(b
) == 9);
30 assert(kmp
.Match(c
) == -1);
32 assert(kmp
.Match("abcdeXYXYXYYXYXYZXXY") == 12);
37 assert(bm
.Match("abcdeXYXYXYYXYXYZXXY") == 12);
39 assert(bm
.Match("abcdWXYWYXYWXYXYWXYZ") == 16);
41 assert(bm
.Match("abcdWXYWYZYWXZXYWXYZXYXYZ") == 19);
42 bm
= "variable length";
44 "Description: TeX macros for drawing variable length wiggily lines.")
49 assert(kr
.Match("abcdeXYXYXYYXYXYZXXY") == 12);
51 assert(kr
.Match("abcdWXYWYXYWXYXYWXYZ") == 16);
53 assert(kr
.Match("abcdWXYWYZYWXZXYWXYZXYXYZ") == 19);
55 Quark q
= "The quick brown fox";
56 Quark s
= "The lazy dog";
57 Quark r
= "The quick brown fox";
61 assert(q
!= s
&& q
== r
&& t
== s
);
65 assert(re
.Match("The quick brown fox") == 16);
66 assert(re
.Match("The quick brown fofox") == 18);
68 assert(re2
.Match("The quick brown fofox") == 18);
69 assert(re2
.Match("The lazy dog f") == -1);
72 assert(re
.Match("The quick brown fox") == 16);
74 RegExp dirname
= "^((\\w*/)*)([^/]+)$";
76 printf("%d\n",dirname
.Match("/usr/etc/net/spool/worm.hack\n"));
77 assert(dirname
.Match("/usr/etc/net/spool/worm.hack\n") >= 0);
78 assert(dirname
.Match("/usr/etc/net/spool/worm.hack") >= 0);
80 printf("dir = %*.*s, base = %*.*s\n",
81 dirname
.len(0), dirname
.len(0), dirname
[0],
82 dirname
.len(2), dirname
.len(2), dirname
[2]);
84 printf("start(0) = %d\n", dirname
.start(0));
85 printf("len(0) = %d\n", dirname
.len(0));
86 printf("start(2) = %d\n", dirname
.start(2));
87 printf("len(2) = %d\n", dirname
.len(2));
89 assert(dirname
.start(0) == 0);
90 assert(dirname
.len(0) == 19);
91 assert(dirname
.start(2) == 19);
92 assert(dirname
.len(2) == 9);