From: K.Kosako Date: Mon, 26 Mar 2018 02:12:03 +0000 (+0900) Subject: add an optional argument of counter type into (*MAX) X-Git-Tag: v6.8.2^2~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da9d4f6c5baeb873ed95e820cb27b83c437094b8;p=onig add an optional argument of counter type into (*MAX) --- diff --git a/src/ascii.c b/src/ascii.c index 97ea57b..622e963 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -47,7 +47,9 @@ init(void) name = "MAX"; args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; - BC_B(name, max, 1, args); + args[1] = ONIG_TYPE_CHAR; + opts[0].c = 'X'; + BC_B_O(name, max, 2, args, 1, opts); name = "ERROR"; args[0] = ONIG_TYPE_LONG; opts[0].l = ONIG_ABORT; diff --git a/src/regexec.c b/src/regexec.c index d9e3df8..e24ba9f 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -5394,6 +5394,7 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) int r; int slot; long max_val; + OnigCodePoint count_type; OnigType type; OnigValue val; OnigValue aval; @@ -5424,12 +5425,26 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) max_val = aval.l; } + r = onig_get_arg_by_callout_args(args, 1, &type, &aval); + if (r != ONIG_NORMAL) return r; + + count_type = aval.c; + if (count_type != '>' && count_type != 'X' && count_type != '<') + return ONIGERR_INVALID_CALLOUT_ARG; + if (args->in == ONIG_CALLOUT_IN_RETRACTION) { - val.l--; + if (count_type == '<') { + if (val.l >= max_val) return ONIG_CALLOUT_FAIL; + val.l++; + } + else if (count_type == 'X') + val.l--; } else { - if (val.l >= max_val) return ONIG_CALLOUT_FAIL; - val.l++; + if (count_type != '<') { + if (val.l >= max_val) return ONIG_CALLOUT_FAIL; + val.l++; + } } r = onig_set_callout_data_by_callout_args_self(args, slot, ONIG_TYPE_LONG, &val); diff --git a/src/utf16_be.c b/src/utf16_be.c index 1ddead7..05a5d25 100644 --- a/src/utf16_be.c +++ b/src/utf16_be.c @@ -45,9 +45,12 @@ init(void) name = "\000F\000A\000I\000L\000\000"; BC0_P(name, fail); name = "\000M\000I\000S\000M\000A\000T\000C\000H\000\000"; BC0_P(name, mismatch); + name = "\000M\000A\000X\000\000"; args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; - BC_B(name, max, 1, args); + args[1] = ONIG_TYPE_CHAR; + opts[0].c = 'X'; + BC_B_O(name, max, 2, args, 1, opts); name = "\000E\000R\000R\000O\000R\000\000"; args[0] = ONIG_TYPE_LONG; opts[0].l = ONIG_ABORT; diff --git a/src/utf16_le.c b/src/utf16_le.c index 82ba383..2d2e61b 100644 --- a/src/utf16_le.c +++ b/src/utf16_le.c @@ -46,7 +46,9 @@ init(void) name = "M\000A\000X\000\000\000"; args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; - BC_B(name, max, 1, args); + args[1] = ONIG_TYPE_CHAR; + opts[0].c = 'X'; + BC_B_O(name, max, 2, args, 1, opts); name = "E\000R\000R\000O\000R\000\000\000"; args[0] = ONIG_TYPE_LONG; opts[0].l = ONIG_ABORT;