]> granicus.if.org Git - onig/commitdiff
add an optional argument of counter type into (*MAX)
authorK.Kosako <kosako@sofnec.co.jp>
Mon, 26 Mar 2018 02:12:03 +0000 (11:12 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Mon, 26 Mar 2018 02:12:03 +0000 (11:12 +0900)
src/ascii.c
src/regexec.c
src/utf16_be.c
src/utf16_le.c

index 97ea57b94b09ac68356c2294ec6add01216d565a..622e963b42933e5f1ae7d7439da6222e9fc05968 100644 (file)
@@ -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;
index d9e3df84e17391cf15e9bcfee685b605d1e50e01..e24ba9f2dae82dc39e0dce5cca2411e9a980ae4e 100644 (file)
@@ -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);
index 1ddead7f8bcd8d8ad7892fd9061b1ab0056020ac..05a5d25fa05881b9942c46e7ebf76ed708c17d6e 100644 (file)
@@ -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;
index 82ba383f3f00103a209ea9ea473be6ae0260d97c..2d2e61bbaeb5452687bd9f34625a90f00de30a05 100644 (file)
@@ -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;