Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NetHack may be freely redistributed. See license for details. */
- #include <re2/re2.h>
- /* RE2 is recommended for public servers as it blocks DoS attacks. It is not
- * fully POSIX-compliant, but is feature-rich. Available at
- * https://github.com/google/re2
- *
- * nhregex interface documented in sys/share/posixregex.c
- */
- extern "C" {
- #include <hack.h>
- extern const char regex_id[] = "re2regex";
- struct nhregex {
- re2::RE2 *re;
- nhregex() : re(nullptr) {}
- ~nhregex() { delete re; }
- };
- struct nhregex *regex_init(void) {
- return new nhregex;
- }
- boolean regex_compile(const char *s, struct nhregex *re) {
- if (!s || !re)
- return false;
- if (re->re) {
- delete re->re;
- re->re = nullptr;
- }
- re->re = new re2::RE2(s);
- return re->re->ok();
- }
- const char *regex_error_desc(struct nhregex *re) {
- return (re && re->re && !re->re->ok()) ? re->re->error().c_str() : nullptr;
- }
- boolean regex_match(const char *s, struct nhregex *re) {
- return (s && re && re->re) ? RE2::PartialMatch(s, *(re->re)) : false;
- }
- void regex_free(struct nhregex *re) {
- delete re;
- }
- }
Add Comment
Please, Sign In to add comment