static void tre_compile_regex(regex_t* preg, VALUE pattern, VALUE ignore_case, VALUE multi_line) { Check_Type(pattern, T_STRING); int cflags = REG_EXTENDED; if (ignore_case == Qtrue) cflags = cflags | REG_ICASE; if (multi_line == Qfalse) cflags = cflags | REG_NEWLINE; reg_errcode_t result = tre_regncomp(preg, StringValuePtr(pattern), RSTRING_LEN(pattern), cflags); if (result == REG_OK) return; switch (result) { case REG_NOMATCH: rb_raise(rb_eRuntimeError, "No match."); break; case REG_BADPAT: rb_raise(rb_eRuntimeError, "Invalid regexp."); break; case REG_ECOLLATE: rb_raise(rb_eRuntimeError, "Unknown collating element."); break; case REG_ECTYPE: rb_raise(rb_eRuntimeError, "Unknown character class name."); break; case REG_EESCAPE: rb_raise(rb_eRuntimeError, "Trailing backslash."); break; case REG_ESUBREG: rb_raise(rb_eRuntimeError, "Invalid back reference."); break; case REG_EBRACK: rb_raise(rb_eRuntimeError, "\"[]\" imbalance"); break; case REG_EPAREN: rb_raise(rb_eRuntimeError, "\"\\(\\)\" or \"()\" imbalance"); break; case REG_EBRACE: rb_raise(rb_eRuntimeError, "\"\\{\\}\" or \"{}\" imbalance"); break; case REG_BADBR: rb_raise(rb_eRuntimeError, "Invalid content of {}"); break; case REG_ERANGE: rb_raise(rb_eRuntimeError, "Invalid use of range operator"); break; case REG_ESPACE: rb_raise(rb_eRuntimeError, "Out of memory."); break; case REG_BADRPT: rb_raise(rb_eRuntimeError, "Invalid use of repetition operators."); break; default: rb_raise(rb_eRuntimeError, "Unknown Error"); break; } }
static int compile_regex (lua_State *L, const TArgComp *argC, TPosix **pud) { int res; TPosix *ud; ud = (TPosix *)lua_newuserdata (L, sizeof (TPosix)); memset (ud, 0, sizeof (TPosix)); /* initialize all members to 0 */ res = tre_regncomp (&ud->r, argC->pattern, argC->patlen, argC->cflags); if (res != 0) return generate_error (L, ud, res); if (argC->cflags & REG_NOSUB) ud->r.re_nsub = 0; ud->match = (regmatch_t *) Lmalloc (L, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t)); lua_pushvalue (L, LUA_ENVIRONINDEX); lua_setmetatable (L, -2); if (pud) *pud = ud; return 1; }
int crm114__regncomp(regex_t *preg, const char *regex, long regex_len, int cflags) { return tre_regncomp(preg, regex, regex_len, cflags); }