int id;
OnigType t_int;
+ OnigType t_long;
OnigEncoding enc;
char* name;
enc = ONIG_ENCODING_ASCII;
- t_int = ONIG_TYPE_INT;
+ t_int = ONIG_TYPE_INT;
+ t_long = ONIG_TYPE_LONG;
name = "FAIL"; BC0_P(name, fail);
name = "SUCCESS"; BC0_P(name, success);
name = "ERROR"; BC1_P(name, error, &t_int);
name = "COUNT"; BC0_P(name, count);
name = "FAIL_COUNT"; BC0_R(name, count);
+ name = "ONLY"; BC1_B(name, only, &t_long);
+
#endif /* USE_CALLOUT */
inited = 1;
int onig_builtin_error P_((OnigCalloutArgs* args, void* user_data));
ONIG_EXTERN
int onig_builtin_count P_((OnigCalloutArgs* args, void* user_data));
+ONIG_EXTERN
+int onig_builtin_only P_((OnigCalloutArgs* args, void* user_data));
#ifdef __cplusplus
}
return ONIG_CALLOUT_SUCCESS;
}
+extern int
+onig_builtin_only(OnigCalloutArgs* args, void* user_data ARG_UNUSED)
+{
+ int r;
+ int num;
+ int slot;
+ OnigType type;
+ OnigValue val;
+ OnigValue aval;
+
+ num = args->num;
+ slot = 0;
+ r = onig_get_callout_data_by_callout_num(args->regex, args->msa->mp, num, slot,
+ &type, &val);
+ if (r != ONIG_NORMAL) return r;
+
+ /* initial state */
+ if (type == ONIG_TYPE_VOID) {
+ type = ONIG_TYPE_LONG;
+ val.l = 0;
+ }
+
+ r = onig_get_arg_of_callout_args(args, 0, &type, &aval);
+ if (r != ONIG_NORMAL) return r;
+
+ if (args->in == ONIG_CALLOUT_IN_RETRACTION) {
+ val.l--;
+ }
+ else {
+ if (val.l >= aval.l) return ONIG_CALLOUT_FAIL;
+ val.l++;
+ }
+
+ r = onig_set_callout_data_by_callout_num(args->regex, args->msa->mp, num, slot,
+ ONIG_TYPE_LONG, &val);
+ if (r != ONIG_NORMAL) return r;
+
+ return ONIG_CALLOUT_SUCCESS;
+}
+
#endif /* USE_CALLOUT */
if (id < 0) return id;\
} while(0)
+#define BC1_B(name, func, ts) do {\
+ int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
+ id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
+ (UChar* )(name), (UChar* )((name) + len),\
+ ONIG_CALLOUT_IN_BOTH,\
+ onig_builtin_ ## func, 0, 1, (ts), 0, 0);\
+ if (id < 0) return id;\
+} while(0)
+
#endif /* USE_CALLOUT */