summaryrefslogtreecommitdiff
path: root/sample/callout.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-05-04 18:26:00 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-05-04 18:26:00 +0200
commita7c6cf32519f775b01975b104a0c8da3c76beab5 (patch)
treece8bdf27499179198a1f264a29d34a93c3c92902 /sample/callout.c
parentfd4ff4e58174679784d7698880717eefc9399ba7 (diff)
parent0ad6ddc1cbc5b0f36547798994b352a09ae5cf1c (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'sample/callout.c')
-rw-r--r--sample/callout.c64
1 files changed, 39 insertions, 25 deletions
diff --git a/sample/callout.c b/sample/callout.c
index ab89543..b5e3d91 100644
--- a/sample/callout.c
+++ b/sample/callout.c
@@ -13,7 +13,6 @@ callout_body(OnigCalloutArgs* args, void* user_data)
int i;
int n;
int begin, end;
- int len;
int used_num;
int used_bytes;
OnigCalloutIn in;
@@ -41,6 +40,8 @@ callout_body(OnigCalloutArgs* args, void* user_data)
in == ONIG_CALLOUT_IN_PROGRESS ? "PROGRESS" : "RETRACTION",
contents, start, current);
+ fprintf(stdout, "user_data: %s\n", (char* )user_data);
+
(void )onig_get_used_stack_size_in_callout(args, &used_num, &used_bytes);
fprintf(stdout, "stack: used_num: %d, used_bytes: %d\n", used_num, used_bytes);
@@ -119,7 +120,7 @@ bar(OnigCalloutArgs* args, void* user_data)
}
static int
-test(OnigEncoding enc, char* in_pattern, char* in_str)
+test(OnigEncoding enc, OnigMatchParam* mp, char* in_pattern, char* in_str)
{
int r;
unsigned char *start, *range, *end;
@@ -146,7 +147,8 @@ test(OnigEncoding enc, char* in_pattern, char* in_str)
end = str + strlen((char* )str);
start = str;
range = end;
- r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
+ r = onig_search_with_param(reg, str, end, start, range, region,
+ ONIG_OPTION_NONE, mp);
if (r >= 0) {
int i;
@@ -173,11 +175,13 @@ extern int main(int argc, char* argv[])
{
int r;
int id;
+ void* user_data;
UChar* name;
OnigEncoding use_encs[1];
unsigned int arg_types[4];
OnigValue opt_defaults[4];
OnigEncoding enc;
+ OnigMatchParam* mp;
enc = ONIG_ENCODING_UTF8;
use_encs[0] = enc;
@@ -219,36 +223,46 @@ extern int main(int argc, char* argv[])
(void)onig_set_progress_callout(progress_callout_func);
(void)onig_set_retraction_callout(retraction_callout_func);
+ mp = onig_new_match_param();
+
+ user_data = (void* )"something data";
+ r = onig_set_callout_user_data_of_match_param(mp, user_data);
+ if (r != ONIG_NORMAL) {
+ fprintf(stderr, "ERROR: fail onig_set_callout_user_data_of_match_param(): %d\n", r);
+ }
+
/* callout of contents */
- test(enc, "a+(?{foo bar baz...}X)$", "aaab");
- test(enc, "(?{{!{}#$%&'()=-~^|[_]`@*:+;<>?/.\\,}}[symbols])c", "abc");
- test(enc, "\\A(...)(?{{{booooooooooooo{{ooo}}ooooooooooz}}}<)", "aaab");
- test(enc, "\\A(?!a(?{in prec-read-not}[xxx]X)b)", "ac");
- test(enc, "(?<!a(?{in look-behind-not}X)c)c", "abc");
+ test(enc, mp, "a+(?{foo bar baz...}X)$", "aaab");
+ test(enc, mp, "(?{{!{}#$%&'()=-~^|[_]`@*:+;<>?/.\\,}}[symbols])c", "abc");
+ test(enc, mp, "\\A(...)(?{{{booooooooooooo{{ooo}}ooooooooooz}}}<)", "aaab");
+ test(enc, mp, "\\A(?!a(?{in prec-read-not}[xxx]X)b)", "ac");
+ test(enc, mp, "(?<!a(?{in look-behind-not}X)c)c", "abc");
// callout of name
- test(enc, "\\A(*foo)abc", "abc");
- test(enc, "abc(?:(*FAIL)|$)", "abcabc");
- test(enc, "abc(?:$|(*MISMATCH)|abc$)", "abcabc");
- test(enc, "abc(?:(*ERROR)|$)", "abcabc");
- test(enc, "ab(*foo{})(*FAIL)", "abc");
- test(enc, "abc(d|(*ERROR{-999}))", "abc");
- test(enc, "ab(*bar{372,I am a bar's argument,あ})c(*FAIL)", "abc");
- test(enc, "ab(*bar{1234567890})", "abc");
- test(enc, "(?:a(*MAX{2})|b)*", "abbabbabbabb");
- test(enc, "(?:(*MAX{2})a|b)*", "abbabbabbabb");
- test(enc, "(?:(*MAX{1})a|b)*", "bbbbbabbbbbabbbbb");
- test(enc, "(?:(*MAX{3})a|(*MAX{4})b)*", "bbbaabbab");
- test(enc, "(?:(*MAX[A]{3})a|(*MAX[B]{5})b)*(*CMP{A,<,B})", "abababc");
- test(enc, "(?:(*MAX[A]{7})a|(*MAX[B]{5})b)*(*CMP{A,>=,4})", "abababcabababaa");
+ test(enc, mp, "\\A(*foo)abc", "abc");
+ test(enc, mp, "abc(?:(*FAIL)|$)", "abcabc");
+ test(enc, mp, "abc(?:$|(*MISMATCH)|abc$)", "abcabc");
+ test(enc, mp, "abc(?:(*ERROR)|$)", "abcabc");
+ test(enc, mp, "ab(*foo{})(*FAIL)", "abc");
+ test(enc, mp, "abc(d|(*ERROR{-999}))", "abc");
+ test(enc, mp, "ab(*bar{372,I am a bar's argument,あ})c(*FAIL)", "abc");
+ test(enc, mp, "ab(*bar{1234567890})", "abc");
+ test(enc, mp, "(?:a(*MAX{2})|b)*", "abbabbabbabb");
+ test(enc, mp, "(?:(*MAX{2})a|b)*", "abbabbabbabb");
+ test(enc, mp, "(?:(*MAX{1})a|b)*", "bbbbbabbbbbabbbbb");
+ test(enc, mp, "(?:(*MAX{3})a|(*MAX{4})b)*", "bbbaabbab");
+ test(enc, mp, "(?:(*MAX[A]{3})a|(*MAX[B]{5})b)*(*CMP{A,<,B})", "abababc");
+ test(enc, mp, "(?:(*MAX[A]{7})a|(*MAX[B]{5})b)*(*CMP{A,>=,4})", "abababcabababaa");
+ test(enc, mp, "(?:(*MAX[T]{3})a)*(?:(*MAX{T})c)*", "aaccc");
/* callouts in condition */
- test(enc, "\\A(?(?{in condition})then|else)\\z", "then");
- test(enc, "\\A(?(*FAIL)then|else)\\z", "else");
+ test(enc, mp, "\\A(?(?{in condition})then|else)\\z", "then");
+ test(enc, mp, "\\A(?(*FAIL)then|else)\\z", "else");
/* monitor test */
- test(enc, "(?:(*MON{X})(*FAIL)|.{,3}(*MON[FOO])k)", "abcdefghijk");
+ test(enc, mp, "(?:(*MON{X})(*FAIL)|.{,3}(*MON[FOO])k)", "abcdefghijk");
+ onig_free_match_param(mp);
onig_end();
return 0;
}