From c6ed757eb918979e31f4a37fd64bbb441a05c9df Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Tue, 6 Mar 2018 16:32:39 +0900 Subject: [PATCH] add onig_get/set_callout_data_by_callout_args() etc.. --- src/oniguruma.h | 11 +++++++- src/regexec.c | 72 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/oniguruma.h b/src/oniguruma.h index 46df9cd..55d3af6 100644 --- a/src/oniguruma.h +++ b/src/oniguruma.h @@ -991,10 +991,19 @@ const UChar* onig_get_tag_end P_((OnigRegex reg, int callout_num)); ONIG_EXTERN int onig_get_callout_data_dont_clear_old P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val)); ONIG_EXTERN +int onig_get_callout_data_by_callout_args_self_dont_clear_old P_((OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val)); +ONIG_EXTERN int onig_get_callout_data P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val)); ONIG_EXTERN +int onig_get_callout_data_by_callout_args P_((OnigCalloutArgs* args, int callout_num, int slot, OnigType* type, OnigValue* val)); +ONIG_EXTERN +int onig_get_callout_data_by_callout_args_self P_((OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val)); +ONIG_EXTERN int onig_set_callout_data P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType type, OnigValue* val)); - +ONIG_EXTERN +int onig_set_callout_data_by_callout_args P_((OnigCalloutArgs* args, int callout_num, int slot, OnigType type, OnigValue* val)); +ONIG_EXTERN +int onig_set_callout_data_by_callout_args_self P_((OnigCalloutArgs* args, int slot, OnigType type, OnigValue* val)); ONIG_EXTERN int onig_get_capture_range_in_callout P_((OnigCalloutArgs* args, int mem_num, int* begin, int* end)); ONIG_EXTERN diff --git a/src/regexec.c b/src/regexec.c index ba58933..35f9830 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -1274,6 +1274,15 @@ onig_get_callout_data_dont_clear_old(regex_t* reg, OnigMatchParam* mp, return (t == ONIG_TYPE_VOID ? 1 : ONIG_NORMAL); } +extern int +onig_get_callout_data_by_callout_args_self_dont_clear_old(OnigCalloutArgs* args, + int slot, OnigType* type, + OnigValue* val) +{ + return onig_get_callout_data_dont_clear_old(args->regex, args->msa->mp, + args->num, slot, type, val); +} + extern int onig_get_callout_data(regex_t* reg, OnigMatchParam* mp, int callout_num, int slot, @@ -1310,6 +1319,23 @@ onig_get_callout_data_by_tag(regex_t* reg, OnigMatchParam* mp, return onig_get_callout_data(reg, mp, num, slot, type, val); } +extern int +onig_get_callout_data_by_callout_args(OnigCalloutArgs* args, + int callout_num, int slot, + OnigType* type, OnigValue* val) +{ + return onig_get_callout_data(args->regex, args->msa->mp, callout_num, slot, + type, val); +} + +extern int +onig_get_callout_data_by_callout_args_self(OnigCalloutArgs* args, + int slot, OnigType* type, OnigValue* val) +{ + return onig_get_callout_data(args->regex, args->msa->mp, args->num, slot, + type, val); +} + extern int onig_set_callout_data(regex_t* reg, OnigMatchParam* mp, int callout_num, int slot, @@ -1340,6 +1366,24 @@ onig_set_callout_data_by_tag(regex_t* reg, OnigMatchParam* mp, return onig_set_callout_data(reg, mp, num, slot, type, val); } + +extern int +onig_set_callout_data_by_callout_args(OnigCalloutArgs* args, + int callout_num, int slot, + OnigType type, OnigValue* val) +{ + return onig_set_callout_data(args->regex, args->msa->mp, callout_num, slot, + type, val); +} + +extern int +onig_set_callout_data_by_callout_args_self(OnigCalloutArgs* args, + int slot, OnigType type, OnigValue* val) +{ + return onig_set_callout_data(args->regex, args->msa->mp, args->num, slot, + type, val); +} + #else #define ADJUST_MATCH_PARAM(reg, mp) #endif /* USE_CALLOUT */ @@ -5294,15 +5338,12 @@ extern int onig_builtin_total_count(OnigCalloutArgs* args, void* user_data ARG_UNUSED) { int r; - int num; int slot; OnigType type; OnigValue val; OnigValue aval; OnigCodePoint count_type; - num = onig_get_callout_num_by_callout_args(args); - r = onig_get_arg_by_callout_args(args, 0, &type, &aval); if (r != ONIG_NORMAL) return r; @@ -5311,8 +5352,8 @@ onig_builtin_total_count(OnigCalloutArgs* args, void* user_data ARG_UNUSED) return ONIGERR_INVALID_CALLOUT_ARG; slot = 0; - r = onig_get_callout_data_dont_clear_old(args->regex, args->msa->mp, - num, slot, &type, &val); + r = onig_get_callout_data_by_callout_args_self_dont_clear_old(args, slot, + &type, &val); if (r < ONIG_NORMAL) return r; else if (r > ONIG_NORMAL) { @@ -5332,8 +5373,7 @@ onig_builtin_total_count(OnigCalloutArgs* args, void* user_data ARG_UNUSED) val.l++; } - r = onig_set_callout_data(args->regex, args->msa->mp, num, slot, - ONIG_TYPE_LONG, &val); + r = onig_set_callout_data_by_callout_args_self(args, slot, ONIG_TYPE_LONG, &val); if (r != ONIG_NORMAL) return r; return ONIG_CALLOUT_SUCCESS; @@ -5343,7 +5383,6 @@ extern int onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) { int r; - int num; int slot; OnigType type; OnigValue val; @@ -5351,9 +5390,8 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) (void )onig_check_callout_data_and_clear_old_values(args); - num = onig_get_callout_num_by_callout_args(args); slot = 0; - r = onig_get_callout_data(args->regex, args->msa->mp, num, slot, &type, &val); + r = onig_get_callout_data_by_callout_args_self(args, slot, &type, &val); if (r < ONIG_NORMAL) return r; else if (r > ONIG_NORMAL) { @@ -5373,8 +5411,7 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) val.l++; } - r = onig_set_callout_data(args->regex, args->msa->mp, num, slot, - ONIG_TYPE_LONG, &val); + r = onig_set_callout_data_by_callout_args_self(args, slot, ONIG_TYPE_LONG, &val); if (r != ONIG_NORMAL) return r; return ONIG_CALLOUT_SUCCESS; @@ -5393,7 +5430,6 @@ extern int onig_builtin_cmp(OnigCalloutArgs* args, void* user_data ARG_UNUSED) { int r; - int num; int slot; long lv; long rv; @@ -5408,7 +5444,7 @@ onig_builtin_cmp(OnigCalloutArgs* args, void* user_data ARG_UNUSED) if (r != ONIG_NORMAL) return r; if (type == ONIG_TYPE_TAG) { - r = onig_get_callout_data(reg, args->msa->mp, val.tag, 0, &type, &val); + r = onig_get_callout_data_by_callout_args(args, val.tag, 0, &type, &val); if (r < ONIG_NORMAL) return r; else if (r > ONIG_NORMAL) lv = 0L; @@ -5423,7 +5459,7 @@ onig_builtin_cmp(OnigCalloutArgs* args, void* user_data ARG_UNUSED) if (r != ONIG_NORMAL) return r; if (type == ONIG_TYPE_TAG) { - r = onig_get_callout_data(reg, args->msa->mp, val.tag, 0, &type, &val); + r = onig_get_callout_data_by_callout_args(args, val.tag, 0, &type, &val); if (r < ONIG_NORMAL) return r; else if (r > ONIG_NORMAL) rv = 0L; @@ -5434,9 +5470,8 @@ onig_builtin_cmp(OnigCalloutArgs* args, void* user_data ARG_UNUSED) rv = val.l; } - num = onig_get_callout_num_by_callout_args(args); slot = 0; - r = onig_get_callout_data(reg, args->msa->mp, num, slot, &type, &val); + r = onig_get_callout_data_by_callout_args_self(args, slot, &type, &val); if (r < ONIG_NORMAL) return r; else if (r > ONIG_NORMAL) { @@ -5482,8 +5517,7 @@ onig_builtin_cmp(OnigCalloutArgs* args, void* user_data ARG_UNUSED) break; } val.l = (long )op; - r = onig_set_callout_data(reg, args->msa->mp, num, slot, - ONIG_TYPE_LONG, &val); + r = onig_set_callout_data_by_callout_args_self(args, slot, ONIG_TYPE_LONG, &val); if (r != ONIG_NORMAL) return r; } else { -- 2.40.0