1 #ifndef UTIL_REGEXP_H
2 #define UTIL_REGEXP_H
3
4 #include <regex.h>
5 #include <stdbool.h>
6 #include "util/ptr-array.h"
7
8 bool regexp_match_nosub(const char *pattern, const char *buf, size_t size);
9 bool regexp_match(const char *pattern, const char *buf, size_t size, PointerArray *m);
10
11 bool regexp_compile_internal(regex_t *re, const char *pattern, int flags);
12 bool regexp_exec(const regex_t *re, const char *buf, size_t size, size_t nr_m, regmatch_t *m, int flags);
13 bool regexp_exec_sub(const regex_t *re, const char *buf, size_t size, PointerArray *matches, int flags);
14
regexp_compile(regex_t * re,const char * pattern,int flags)15 static inline bool regexp_compile(regex_t *re, const char *pattern, int flags)
16 {
17 return regexp_compile_internal(re, pattern, flags | REG_EXTENDED);
18 }
19
regexp_is_valid(const char * pattern,int flags)20 static inline bool regexp_is_valid(const char *pattern, int flags)
21 {
22 regex_t re;
23 if (!regexp_compile(&re, pattern, flags | REG_NOSUB)) {
24 return false;
25 }
26 regfree(&re);
27 return true;
28 }
29
regexp_compile_basic(regex_t * re,const char * pattern,int flags)30 static inline bool regexp_compile_basic(regex_t *re, const char *pattern, int flags)
31 {
32 return regexp_compile_internal(re, pattern, flags);
33 }
34
35 #endif
36