1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
27 #include <AD/strings/bm.h> // Boyer Moore
28 #include <AD/strings/kmp.h> // Knuth Morris Pratt
29 #include <AD/strings/kr.h> // Karp Rabin
30 #include <AD/strings/quark.h> // Atomic strings
31 #include <AD/strings/regexp.h> // Regular expression search
32 #include <AD/strings/string.h> // Dynamic strings
33 #include <AD/strings/twoway.h> // Two way string matcher
35 int main(int argc
, char * argv
[])
37 if (RegExp("[a-z]+").match("The quick brown fox jumps over the lazy dog")
41 printf("unmatched\n");
43 const char * a
= "The quick brown fox";
44 const char * b
= "The lazy dog";
45 const char * c
= "The quick brown fox";
47 assert(kmp
.match(a
) == 0);
49 assert(kmp
.match(a
) == 16);
51 assert(kmp
.match(b
) == 9);
52 assert(kmp
.match(c
) == -1);
54 assert(kmp
.match("abcdeXYXYXYYXYXYZXXY") == 12);
59 assert(bm
.match("abcdeXYXYXYYXYXYZXXY") == 12);
61 assert(bm
.match("abcdWXYWYXYWXYXYWXYZ") == 16);
63 assert(bm
.match("abcdWXYWYZYWXZXYWXYZXYXYZ") == 19);
64 bm
= "variable length";
66 "Description: TeX macros for drawing variable length wiggily lines.")
71 assert(kr
.match("abcdeXYXYXYYXYXYZXXY") == 12);
73 assert(kr
.match("abcdWXYWYXYWXYXYWXYZ") == 16);
75 assert(kr
.match("abcdWXYWYZYWXZXYWXYZXYXYZ") == 19);
77 Quark q
= "The quick brown fox";
78 Quark s
= "The lazy dog";
79 Quark r
= "The quick brown fox";
83 assert(q
!= s
&& q
== r
&& t
== s
);
87 assert(re
.match("The quick brown fox") == 16);
88 assert(re
.match("The quick brown fofox") == 18);
90 assert(re2
.match("The quick brown fofox") == 18);
91 assert(re2
.match("The lazy dog f") == -1);
94 assert(re
.match("The quick brown fox") == 16);
96 RegExp dirname
= "^((\\w*/)*)([^/]+)$";
98 printf("%d\n",dirname
.match("/usr/etc/net/spool/worm.hack\n"));
99 assert(dirname
.match("/usr/etc/net/spool/worm.hack\n") >= 0);
100 assert(dirname
.match("/usr/etc/net/spool/worm.hack") >= 0);
102 printf("dir = %*.*s, base = %*.*s\n",
103 dirname
.len(0), dirname
.len(0), dirname
[0],
104 dirname
.len(2), dirname
.len(2), dirname
[2]);
106 printf("start(0) = %d\n", dirname
.start(0));
107 printf("len(0) = %d\n", dirname
.len(0));
108 printf("start(2) = %d\n", dirname
.start(2));
109 printf("len(2) = %d\n", dirname
.len(2));
111 assert(dirname
.start(0) == 0);
112 assert(dirname
.len(0) == 19);
113 assert(dirname
.start(2) == 19);
114 assert(dirname
.len(2) == 9);