static void testRegexp(xmlRegexpPtr comp, const char *value) { int ret; ret = xmlRegexpExec(comp, (const xmlChar *) value); if (ret == 1) printf("%s: Ok\n", value); else if (ret == 0) printf("%s: Fail\n", value); else printf("%s: Error: %d\n", value, ret); if (repeat) { int j; for (j = 0;j < 999999;j++) xmlRegexpExec(comp, (const xmlChar *) value); } }
bool validateString (const char *regexp, const char *str) { xmlRegexpPtr x = xmlRegexpCompile ((const xmlChar *) regexp); if (!x) return 0; int r = xmlRegexpExec (x, (const xmlChar *) str); xmlRegFreeRegexp (x); return r == 1; }
static ERL_NIF_TERM run(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { struct regexp *rp = NULL; struct regexp r; ErlNifBinary strbin; ERL_NIF_TERM ret; if (!enif_get_resource(env, argv[1], regexp_type, (void **)&rp)) { ErlNifBinary patternbin; if (enif_inspect_iolist_as_binary(env, argv[1], &patternbin)) { char patternstr[patternbin.size + 1]; xmlRegexpPtr xre; patternstr[patternbin.size] = 0; memcpy(patternstr, patternbin.data, patternbin.size); if ((xre = xmlRegexpCompile((xmlChar *)patternstr)) != NULL) { r.xre = xre; r.string = NULL; rp = &r; } else { return last_error(env, "Bad Pattern"); } } else { return enif_make_badarg(env); } } if (enif_inspect_iolist_as_binary(env, argv[0], &strbin)) { char string[strbin.size + 1]; string[strbin.size] = 0; memcpy(string, strbin.data, strbin.size); switch (xmlRegexpExec(rp->xre, (xmlChar *)string)) { case 1: /* FIXME NYI */ ret = enif_make_tuple2(env, am_match(env), enif_make_list(env, 0)); break; case 0: ret = am_nomatch(env); break; default: ret = last_error(env, NULL); } } else { ret = enif_make_badarg(env); } if (rp == &r) { xmlRegFreeRegexp(r.xre); } return ret; }