aboutsummaryrefslogtreecommitdiff
path: root/src/tests/regex.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-04-13 23:25:17 +0000
committerMike Buland <eichlan@xagasoft.com>2011-04-13 23:25:17 +0000
commitf254b23578a9a53a56e6cea980ba588e5f830314 (patch)
tree70def8958fa0f21c80aa5ef29cde7d6eba245213 /src/tests/regex.cpp
parentbc6d543210a9df6f578229c6050371ced665fd69 (diff)
downloadlibbu++-f254b23578a9a53a56e6cea980ba588e5f830314.tar.gz
libbu++-f254b23578a9a53a56e6cea980ba588e5f830314.tar.bz2
libbu++-f254b23578a9a53a56e6cea980ba588e5f830314.tar.xz
libbu++-f254b23578a9a53a56e6cea980ba588e5f830314.zip
Regular expression engine is started, it's...tricky, but I think I can get it.
Diffstat (limited to 'src/tests/regex.cpp')
-rw-r--r--src/tests/regex.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/tests/regex.cpp b/src/tests/regex.cpp
new file mode 100644
index 0000000..82c3466
--- /dev/null
+++ b/src/tests/regex.cpp
@@ -0,0 +1,40 @@
1#include <bu/string.h>
2#include <bu/regexengine.h>
3#include <bu/sio.h>
4
5using namespace Bu;
6
7void compile( const Bu::String &s, Bu::RegExEngine<char> &ree )
8{
9 int iRoot = ree.addState();
10 int iCur = iRoot;
11 for( Bu::String::const_iterator i = s.begin(); i; i++ )
12 {
13 int iNext = -1;
14 if( i+1 )
15 iNext = ree.addState();
16 ree.addCompletion( iCur, *i, *i, iNext );
17 iCur = iNext;
18 }
19}
20
21int main()
22{
23 Bu::String sRegEx("abcd");
24 Bu::String sMatch("abcdefg");
25
26 Bu::RegExEngine<char> ree;
27
28 compile( sRegEx, ree );
29
30 bool bRet;
31 int iSize, iCompletion;
32 bRet = ree.match( sMatch, iSize, iCompletion );
33
34 sio << "Matched: " << bRet << sio.nl
35 << "Size: " << iSize << sio.nl
36 << "Completion: " << iCompletion << sio.nl;
37
38 return 0;
39}
40