1 /* NetHack 3.6 cppregex.cpp $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
2 /* Copyright (c) Sean Hunt 2015. */
3 /* NetHack may be freely redistributed. See license for details. */
8 /* nhregex interface documented in sys/share/posixregex.c */
13 extern const char regex_id
[] = "cppregex";
16 std::unique_ptr
<std::regex
> re
;
17 std::unique_ptr
<std::regex_error
> err
;
20 struct nhregex
*regex_init(void) {
24 boolean
regex_compile(const char *s
, struct nhregex
*re
) {
28 re
->re
.reset(new std::regex(s
, (std::regex::extended
30 | std::regex::optimize
)));
31 re
->err
.reset(nullptr);
33 } catch (const std::regex_error
& err
) {
34 re
->err
.reset(new std::regex_error(err
));
35 re
->re
.reset(nullptr);
40 const char *regex_error_desc(struct nhregex
*re
) {
42 return re
->err
->what();
47 boolean
regex_match(const char *s
, struct nhregex
*re
) {
51 return regex_search(s
, *re
->re
, std::regex_constants::match_any
);
52 } catch (const std::regex_error
& err
) {
57 void regex_free(struct nhregex
*re
) {