extern int re_compile_pattern(const char* pattern, int size, regex_t* reg, char* ebuf) { int r; OnigErrorInfo einfo; r = onig_compile(reg, (UChar* )pattern, (UChar* )(pattern + size), &einfo); if (r != ONIG_NORMAL) { if (IS_NOT_NULL(ebuf)) (void )onig_error_code_to_str((UChar* )ebuf, r, &einfo); } return r; }
extern int onig_new_deluxe(regex_t** reg, const UChar* pattern, const UChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo) { int r; UChar *cpat, *cpat_end; if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL; if (ci->pattern_enc != ci->target_enc) { r = conv_encoding(ci->pattern_enc, ci->target_enc, pattern, pattern_end, &cpat, &cpat_end); if (r) return r; } else { cpat = (UChar* )pattern; cpat_end = (UChar* )pattern_end; } *reg = (regex_t* )xmalloc(sizeof(regex_t)); if (IS_NULL(*reg)) { r = ONIGERR_MEMORY; goto err2; } r = onig_reg_init(*reg, ci->option, ci->case_fold_flag, ci->target_enc, ci->syntax); if (r) goto err; r = onig_compile(*reg, cpat, cpat_end, einfo); if (r) { err: onig_free(*reg); *reg = NULL; } err2: if (cpat != pattern) xfree(cpat); return r; }