From e631db51721fecae1a10421c1132b003d983913d Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Thu, 22 Mar 2018 10:45:47 +0900 Subject: [PATCH] builtin MAX allows tag argument as max value (*MAX{LONG/TAG}) --- src/ascii.c | 7 ++++--- src/regexec.c | 14 +++++++++++++- src/utf16_be.c | 6 +++--- src/utf16_le.c | 7 ++++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/ascii.c b/src/ascii.c index 7efaa26..97ea57b 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -37,16 +37,17 @@ init(void) int id; OnigEncoding enc; char* name; - unsigned int t_long; unsigned int args[4]; OnigValue opts[4]; enc = ONIG_ENCODING_ASCII; - t_long = ONIG_TYPE_LONG; name = "FAIL"; BC0_P(name, fail); name = "MISMATCH"; BC0_P(name, mismatch); - name = "MAX"; BC_B(name, max, 1, &t_long); + + name = "MAX"; + args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; + BC_B(name, max, 1, args); name = "ERROR"; args[0] = ONIG_TYPE_LONG; opts[0].l = ONIG_ABORT; diff --git a/src/regexec.c b/src/regexec.c index 35e3698..d9e3df8 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -5393,6 +5393,7 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) { int r; int slot; + long max_val; OnigType type; OnigValue val; OnigValue aval; @@ -5411,12 +5412,23 @@ onig_builtin_max(OnigCalloutArgs* args, void* user_data ARG_UNUSED) r = onig_get_arg_by_callout_args(args, 0, &type, &aval); if (r != ONIG_NORMAL) return r; + if (type == ONIG_TYPE_TAG) { + r = onig_get_callout_data_by_callout_args(args, aval.tag, 0, &type, &aval); + if (r < ONIG_NORMAL) return r; + else if (r > ONIG_NORMAL) + max_val = 0L; + else + max_val = aval.l; + } + else { /* LONG */ + max_val = aval.l; + } if (args->in == ONIG_CALLOUT_IN_RETRACTION) { val.l--; } else { - if (val.l >= aval.l) return ONIG_CALLOUT_FAIL; + if (val.l >= max_val) return ONIG_CALLOUT_FAIL; val.l++; } diff --git a/src/utf16_be.c b/src/utf16_be.c index 079986b..1ddead7 100644 --- a/src/utf16_be.c +++ b/src/utf16_be.c @@ -38,16 +38,16 @@ init(void) int id; OnigEncoding enc; char* name; - unsigned int t_long; unsigned int args[4]; OnigValue opts[4]; enc = ONIG_ENCODING_UTF16_BE; - t_long = ONIG_TYPE_LONG; 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"; BC_B(name, max, 1, &t_long); + name = "\000M\000A\000X\000\000"; + args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; + BC_B(name, max, 1, args); 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 e258185..82ba383 100644 --- a/src/utf16_le.c +++ b/src/utf16_le.c @@ -36,16 +36,17 @@ init(void) int id; OnigEncoding enc; char* name; - unsigned int t_long; unsigned int args[4]; OnigValue opts[4]; enc = ONIG_ENCODING_UTF16_LE; - t_long = ONIG_TYPE_LONG; name = "F\000A\000I\000L\000\000\000"; BC0_P(name, fail); name = "M\000I\000S\000M\000A\000T\000C\000H\000\000\000"; BC0_P(name, mismatch); - name = "M\000A\000X\000\000\000"; BC_B(name, max, 1, &t_long); + + name = "M\000A\000X\000\000\000"; + args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG; + BC_B(name, max, 1, args); name = "E\000R\000R\000O\000R\000\000\000"; args[0] = ONIG_TYPE_LONG; opts[0].l = ONIG_ABORT; -- 2.40.0