RegexExt* ext = (RegexExt* )xmalloc(sizeof(*ext));
if (IS_NULL(ext)) return 0;
- ext->pattern = 0;
- ext->pattern_end = 0;
- ext->tag_table = 0;
- ext->max_tag_num = 0;
- ext->tag_list = 0;
+ ext->pattern = 0;
+ ext->pattern_end = 0;
+#ifdef USE_CALLOUT
+ ext->tag_table = 0;
+ ext->max_tag_num = 0;
+ ext->callout_list = 0;
+#endif
REG_EXTPL(reg) = (void* )ext;
}
if (IS_NOT_NULL(ext->tag_table))
onig_callout_tag_table_free(ext->tag_table);
- if (IS_NOT_NULL(ext->tag_list))
- xfree(ext->tag_list);
+ if (IS_NOT_NULL(ext->callout_list))
+ xfree(ext->callout_list);
#endif
xfree(ext);
#endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
+
+#ifdef USE_CALLOUT
+
+typedef enum {
+ CALLOUT_TYPE_SINGLE = 0,
+ CALLOUT_TYPE_START_CALL = 1,
+ CALLOUT_TYPE_BOTH_CALL = 2,
+ CALLOUT_TYPE_START_MARK_END_CALL = 3,
+} CalloutType;
+
+typedef struct {
+ int flag;
+ OnigCalloutOf of;
+ int in;
+ CalloutType type;
+ union {
+ struct {
+ UChar* start;
+ UChar* end;
+ } content;
+ struct {
+ int num; /* real passed num */
+ OnigValue vals[ONIG_CALLOUT_MAX_ARG_NUM];
+ } arg;
+ } u;
+} CalloutListEntry;
+
+#endif
+
typedef struct {
UChar* pattern;
UChar* pattern_end;
+#ifdef USE_CALLOUT
void* tag_table;
int max_tag_num;
- int* tag_list; /* index: from 0 to max_tag_num */
+ CalloutListEntry* callout_list; /* index: callout num */
+#endif
} RegexExt;
#define REG_EXTP(reg) ((RegexExt* )((reg)->chain))
#ifdef USE_CALLOUT
-typedef enum {
- CALLOUT_TYPE_SINGLE = 0,
- CALLOUT_TYPE_START_CALL = 1,
- CALLOUT_TYPE_BOTH_CALL = 2,
- CALLOUT_TYPE_START_MARK_END_CALL = 3,
-} CalloutType;
-
extern CalloutType onig_get_callout_type_from_name_id(int name_id);
extern OnigCalloutFunc onig_get_callout_start_func_from_name_id(int id);
extern OnigCalloutFunc onig_get_callout_end_func_from_name_id(int id);
#define CALLOUT_TAG_LIST_FLAG_TAG_EXIST (1<<0)
static int
-i_callout_tag_list_set(UChar* key, CalloutTagVal e, void* arg)
+i_callout_callout_list_set(UChar* key, CalloutTagVal e, void* arg)
{
RegexExt* ext = (RegexExt* )arg;
- ext->tag_list[e] |= CALLOUT_TAG_LIST_FLAG_TAG_EXIST;
+ ext->callout_list[e].flag |= CALLOUT_TAG_LIST_FLAG_TAG_EXIST;
return ST_CONTINUE;
}
static void
-set_callout_tag_list_values(RegexExt* ext)
+set_callout_callout_list_values(RegexExt* ext)
{
- onig_st_foreach((CalloutTagTable *)ext->tag_table, i_callout_tag_list_set,
- (st_data_t )ext);
+ if (IS_NOT_NULL(ext->tag_table)) {
+ onig_st_foreach((CalloutTagTable *)ext->tag_table, i_callout_callout_list_set,
+ (st_data_t )ext);
+ }
}
extern int
{
RegexExt* ext = REG_EXTP(reg);
- if (IS_NULL(ext) || IS_NULL(ext->tag_list)) return 0;
+ if (IS_NULL(ext) || IS_NULL(ext->callout_list)) return 0;
if (callout_num > ext->max_tag_num) return 0;
- return (ext->tag_list[callout_num] & CALLOUT_TAG_LIST_FLAG_TAG_EXIST) != 0 ? 1 : 0;
+ return (ext->callout_list[callout_num].flag &
+ CALLOUT_TAG_LIST_FLAG_TAG_EXIST) != 0 ? 1 : 0;
}
static int
reg->num_mem = env->num_mem;
#ifdef USE_CALLOUT
- if (env->max_tag_num > 0) {
+ if (env->callout_num > 0) {
ext = onig_get_regex_ext(env->reg);
CHECK_NULL_RETURN_MEMERR(ext);
ext->max_tag_num = env->max_tag_num;
- size_t n = sizeof(*(ext->tag_list)) * (ext->max_tag_num + 1);
- ext->tag_list = xmalloc(n);
- CHECK_NULL_RETURN_MEMERR(ext->tag_list);
- xmemset(ext->tag_list, 0, n);
- set_callout_tag_list_values(ext);
+ size_t n = sizeof(*(ext->callout_list)) * (env->callout_num + 1);
+ ext->callout_list = xmalloc(n);
+ CHECK_NULL_RETURN_MEMERR(ext->callout_list);
+ xmemset(ext->callout_list, 0, n);
+ set_callout_callout_list_values(ext);
}
#endif