diff options
Diffstat (limited to 'sample')
-rw-r--r-- | sample/Makefile.am | 6 | ||||
-rw-r--r-- | sample/scan.c | 24 |
2 files changed, 22 insertions, 8 deletions
diff --git a/sample/Makefile.am b/sample/Makefile.am index 2bf4697..c2c4596 100644 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -8,9 +8,9 @@ AM_LDFLAGS = -L$(prefix)/lib AM_CPPFLAGS = -I$(top_srcdir)/src if ENABLE_POSIX_API -TESTS = encode listcap names posix simple sql syntax user_property callout echo count bug_fix regset +TESTS = encode listcap names posix simple sql syntax user_property callout echo count bug_fix regset scan else -TESTS = encode listcap names simple sql syntax user_property callout echo count bug_fix regset +TESTS = encode listcap names simple sql syntax user_property callout echo count bug_fix regset scan endif check_PROGRAMS = $(TESTS) @@ -28,6 +28,7 @@ echo_SOURCES = echo.c count_SOURCES = count.c bug_fix = bug_fix.c regset_SOURCES = regset.c +scan_SOURCES = scan.c sampledir = . @@ -47,3 +48,4 @@ endif $(sampledir)/count $(sampledir)/bug_fix $(sampledir)/regset + $(sampledir)/scan diff --git a/sample/scan.c b/sample/scan.c index 4039e46..fe1bac1 100644 --- a/sample/scan.c +++ b/sample/scan.c @@ -21,14 +21,14 @@ scan_callback(int n, int r, OnigRegion* region, void* arg) } static int -scan(regex_t* reg, unsigned char* str, unsigned char* end) +scan(regex_t* reg, OnigOptionType options, unsigned char* str, unsigned char* end) { int r; OnigRegion *region; region = onig_region_new(); - r = onig_scan(reg, str, end, region, ONIG_OPTION_NONE, scan_callback, NULL); + r = onig_scan(reg, str, end, region, options, scan_callback, NULL); if (r >= 0) { fprintf(stdout, "total: %d match\n", r); } @@ -45,7 +45,7 @@ scan(regex_t* reg, unsigned char* str, unsigned char* end) } static int -exec(OnigEncoding enc, OnigOptionType options, char* apattern, char* astr) +exec(OnigEncoding enc, OnigOptionType options, OnigOptionType runtime_options, char* apattern, char* astr) { int r; unsigned char *end; @@ -69,7 +69,7 @@ exec(OnigEncoding enc, OnigOptionType options, char* apattern, char* astr) } end = str + onigenc_str_bytelen_null(enc, str); - r = scan(reg, str, end); + r = scan(reg, runtime_options, str, end); onig_free(reg); onig_end(); @@ -79,11 +79,23 @@ exec(OnigEncoding enc, OnigOptionType options, char* apattern, char* astr) extern int main(int argc, char* argv[]) { - exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, + exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, ONIG_OPTION_NONE, "\\Ga+\\s*", "a aa aaa baaa"); + fprintf(stdout, "\n"); + + exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, ONIG_OPTION_NOT_BEGIN_POSITION, + "\\Ga+\\s*", "a aa aaa baaa"); + fprintf(stdout, "\n"); + exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, ONIG_OPTION_NONE, + "(?!\\G)a+\\s*", "a aa aaa baaa"); fprintf(stdout, "\n"); - exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, + + exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, ONIG_OPTION_NOT_BEGIN_POSITION, + "(?!\\G)a+\\s*", "a aa aaa baaa"); + fprintf(stdout, "\n"); + + exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE, ONIG_OPTION_NONE, "a+\\s*", "a aa aaa baaa"); return 0; |