summaryrefslogtreecommitdiff
path: root/src/tests/regex.cpp
blob: 82c346630f2a7c4845b2c2c9205f4214684ec636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bu/string.h>
#include <bu/regexengine.h>
#include <bu/sio.h>

using namespace Bu;

void compile( const Bu::String &s, Bu::RegExEngine<char> &ree )
{
	int iRoot = ree.addState();
	int iCur = iRoot;
	for( Bu::String::const_iterator i = s.begin(); i; i++ )
	{
		int iNext = -1;
		if( i+1 )
			iNext = ree.addState();
		ree.addCompletion( iCur, *i, *i, iNext );
		iCur = iNext;
	}
}

int main()
{
	Bu::String sRegEx("abcd");
	Bu::String sMatch("abcdefg");

	Bu::RegExEngine<char> ree;

	compile( sRegEx, ree );

	bool bRet;
	int iSize, iCompletion;
	bRet = ree.match( sMatch, iSize, iCompletion );

	sio << "Matched: " << bRet << sio.nl
		<< "Size: " << iSize << sio.nl
		<< "Completion: " << iCompletion << sio.nl;

	return 0;
}