diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2014-01-07 14:43:47 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2014-01-07 14:43:47 +0200 |
| commit | 0fd92fe3ad425d87c3647a3b51fbd2204e1fb1d2 (patch) | |
| tree | 40923754a7f967a69454b88214f4e9b48186ff0a /test.c | |
| download | tiny-rex-0fd92fe3ad425d87c3647a3b51fbd2204e1fb1d2.tar.gz tiny-rex-0fd92fe3ad425d87c3647a3b51fbd2204e1fb1d2.zip | |
initial commit
Diffstat (limited to 'test.c')
| -rw-r--r-- | test.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +#include "trex.h" +#include <stdio.h> +#include <string.h> + +#ifdef _UNICODE +#define trex_sprintf swprintf +#else +#define trex_sprintf sprintf +#endif + +int main(int argc, char* argv[]) +{ + const TRexChar *begin,*end; + TRexChar sTemp[200]; + const TRexChar *error = NULL; + TRex *x = trex_compile(_TREXC("(x{1,5})xx"),&error); + if(x) { + trex_sprintf(sTemp,_TREXC("xxxxxxx")); + if(trex_search(x,sTemp,&begin,&end)) + { + int i,n = trex_getsubexpcount(x); + TRexMatch match; + for(i = 0; i < n; i++) + { + TRexChar t[200]; + trex_getsubexp(x,i,&match); + trex_sprintf(t,_TREXC("[%%d]%%.%ds\n"),match.len); + trex_printf(t,i,match.begin); + } + trex_printf(_TREXC("match! %d sub matches\n"),trex_getsubexpcount(x)); + } + else { + trex_printf(_TREXC("no match!\n")); + } + trex_free(x); + } + else { + trex_printf(_TREXC("compilation error [%s]!\n"),error?error:_TREXC("undefined")); + } + return 0; +} |
