| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef CRE2_H |
| 15 |
#define CRE2_H 1 |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifdef __cplusplus |
| 23 |
extern "C" { |
| 24 |
#else |
| 25 |
#include <stdbool.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <stdint.h> |
| 29 |
|
| 30 |
#ifndef cre2_decl |
| 31 |
# define cre2_decl extern |
| 32 |
#endif |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
typedef void cre2_options_t; |
| 40 |
|
| 41 |
typedef enum cre2_encoding_t { |
| 42 |
CRE2_UNKNOWN = 0, |
| 43 |
CRE2_UTF8 = 1, |
| 44 |
CRE2_Latin1 = 2 |
| 45 |
} cre2_encoding_t; |
| 46 |
|
| 47 |
cre2_decl cre2_options_t *cre2_opt_new (void); |
| 48 |
cre2_decl void cre2_opt_delete (cre2_options_t *opt); |
| 49 |
|
| 50 |
cre2_decl void cre2_opt_set_posix_syntax (cre2_options_t *opt, int flag); |
| 51 |
cre2_decl void cre2_opt_set_longest_match (cre2_options_t *opt, int flag); |
| 52 |
cre2_decl void cre2_opt_set_log_errors (cre2_options_t *opt, int flag); |
| 53 |
cre2_decl void cre2_opt_set_literal (cre2_options_t *opt, int flag); |
| 54 |
cre2_decl void cre2_opt_set_never_nl (cre2_options_t *opt, int flag); |
| 55 |
cre2_decl void cre2_opt_set_dot_nl (cre2_options_t *opt, int flag); |
| 56 |
cre2_decl void cre2_opt_set_never_capture (cre2_options_t *opt, int flag); |
| 57 |
cre2_decl void cre2_opt_set_case_sensitive (cre2_options_t *opt, int flag); |
| 58 |
cre2_decl void cre2_opt_set_perl_classes (cre2_options_t *opt, int flag); |
| 59 |
cre2_decl void cre2_opt_set_word_boundary (cre2_options_t *opt, int flag); |
| 60 |
cre2_decl void cre2_opt_set_one_line (cre2_options_t *opt, int flag); |
| 61 |
cre2_decl void cre2_opt_set_max_mem (cre2_options_t *opt, int64_t m); |
| 62 |
cre2_decl void cre2_opt_set_encoding (cre2_options_t *opt, cre2_encoding_t enc); |
| 63 |
cre2_decl void cre2_opt_set_latin1_encoding (cre2_options_t *opt); |
| 64 |
|
| 65 |
cre2_decl int cre2_opt_posix_syntax (cre2_options_t *opt); |
| 66 |
cre2_decl int cre2_opt_longest_match (cre2_options_t *opt); |
| 67 |
cre2_decl int cre2_opt_log_errors (cre2_options_t *opt); |
| 68 |
cre2_decl int cre2_opt_literal (cre2_options_t *opt); |
| 69 |
cre2_decl int cre2_opt_never_nl (cre2_options_t *opt); |
| 70 |
cre2_decl int cre2_opt_dot_nl (cre2_options_t *opt); |
| 71 |
cre2_decl int cre2_opt_never_capture (cre2_options_t *opt); |
| 72 |
cre2_decl int cre2_opt_case_sensitive (cre2_options_t *opt); |
| 73 |
cre2_decl int cre2_opt_perl_classes (cre2_options_t *opt); |
| 74 |
cre2_decl int cre2_opt_word_boundary (cre2_options_t *opt); |
| 75 |
cre2_decl int cre2_opt_one_line (cre2_options_t *opt); |
| 76 |
cre2_decl int64_t cre2_opt_max_mem (cre2_options_t *opt); |
| 77 |
cre2_decl cre2_encoding_t cre2_opt_encoding (cre2_options_t *opt); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
typedef struct cre2_string_t { |
| 85 |
const char * data; |
| 86 |
int length; |
| 87 |
} cre2_string_t; |
| 88 |
|
| 89 |
typedef void cre2_regexp_t; |
| 90 |
|
| 91 |
typedef struct cre2_named_groups_iter_t cre2_named_groups_iter_t; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
typedef enum cre2_error_code_t { |
| 96 |
CRE2_NO_ERROR = 0, |
| 97 |
CRE2_ERROR_INTERNAL, |
| 98 |
|
| 99 |
CRE2_ERROR_BAD_ESCAPE, |
| 100 |
CRE2_ERROR_BAD_CHAR_CLASS, |
| 101 |
CRE2_ERROR_BAD_CHAR_RANGE, |
| 102 |
CRE2_ERROR_MISSING_BRACKET, |
| 103 |
CRE2_ERROR_MISSING_PAREN, |
| 104 |
CRE2_ERROR_TRAILING_BACKSLASH, |
| 105 |
CRE2_ERROR_REPEAT_ARGUMENT, |
| 106 |
CRE2_ERROR_REPEAT_SIZE, |
| 107 |
CRE2_ERROR_REPEAT_OP, |
| 108 |
CRE2_ERROR_BAD_PERL_OP, |
| 109 |
CRE2_ERROR_BAD_UTF8, |
| 110 |
CRE2_ERROR_BAD_NAMED_CAPTURE, |
| 111 |
CRE2_ERROR_PATTERN_TOO_LARGE, |
| 112 |
} cre2_error_code_t; |
| 113 |
|
| 114 |
|
| 115 |
cre2_decl cre2_regexp_t * cre2_new (const char *pattern, int pattern_len, |
| 116 |
const cre2_options_t *opt); |
| 117 |
cre2_decl void cre2_delete (cre2_regexp_t *re); |
| 118 |
|
| 119 |
|
| 120 |
cre2_decl const char * cre2_pattern (const cre2_regexp_t *re); |
| 121 |
cre2_decl int cre2_error_code (const cre2_regexp_t *re); |
| 122 |
cre2_decl int cre2_num_capturing_groups (const cre2_regexp_t *re); |
| 123 |
cre2_decl int cre2_program_size (const cre2_regexp_t *re); |
| 124 |
|
| 125 |
|
| 126 |
cre2_decl int cre2_find_named_capturing_groups (const cre2_regexp_t *re, const char *name); |
| 127 |
cre2_decl cre2_named_groups_iter_t * cre2_named_groups_iter_new(const cre2_regexp_t *re); |
| 128 |
cre2_decl bool cre2_named_groups_iter_next(cre2_named_groups_iter_t* iter, const char ** name, int *index); |
| 129 |
cre2_decl void cre2_named_groups_iter_delete(cre2_named_groups_iter_t *iter); |
| 130 |
|
| 131 |
|
| 132 |
cre2_decl const char *cre2_error_string(const cre2_regexp_t *re); |
| 133 |
cre2_decl const char *cre2_error_arg(const cre2_regexp_t *re); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
typedef enum cre2_anchor_t { |
| 141 |
CRE2_UNANCHORED = 1, |
| 142 |
CRE2_ANCHOR_START = 2, |
| 143 |
CRE2_ANCHOR_BOTH = 3 |
| 144 |
} cre2_anchor_t; |
| 145 |
|
| 146 |
typedef struct cre2_range_t { |
| 147 |
long start; |
| 148 |
long past; |
| 149 |
} cre2_range_t; |
| 150 |
|
| 151 |
cre2_decl int cre2_match (const cre2_regexp_t * re, |
| 152 |
const char * text, int textlen, |
| 153 |
int startpos, int endpos, cre2_anchor_t anchor, |
| 154 |
cre2_string_t * match, int nmatch); |
| 155 |
|
| 156 |
cre2_decl int cre2_easy_match (const char * pattern, int pattern_len, |
| 157 |
const char * text, int text_len, |
| 158 |
cre2_string_t * match, int nmatch); |
| 159 |
|
| 160 |
cre2_decl void cre2_strings_to_ranges (const char * text, cre2_range_t * ranges, |
| 161 |
cre2_string_t * strings, int nmatch); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
typedef int cre2_match_stringz_fun_t (const char * pattern, const cre2_string_t * text, |
| 169 |
cre2_string_t * match, int nmatch); |
| 170 |
|
| 171 |
typedef int cre2_match_stringz2_fun_t (const char * pattern, cre2_string_t * text, |
| 172 |
cre2_string_t * match, int nmatch); |
| 173 |
|
| 174 |
typedef int cre2_match_rex_fun_t (cre2_regexp_t * rex, const cre2_string_t * text, |
| 175 |
cre2_string_t * match, int nmatch); |
| 176 |
|
| 177 |
typedef int cre2_match_rex2_fun_t (cre2_regexp_t * rex, cre2_string_t * text, |
| 178 |
cre2_string_t * match, int nmatch); |
| 179 |
|
| 180 |
cre2_decl cre2_match_stringz_fun_t cre2_full_match; |
| 181 |
cre2_decl cre2_match_stringz_fun_t cre2_partial_match; |
| 182 |
cre2_decl cre2_match_stringz2_fun_t cre2_consume; |
| 183 |
cre2_decl cre2_match_stringz2_fun_t cre2_find_and_consume; |
| 184 |
|
| 185 |
cre2_decl cre2_match_rex_fun_t cre2_full_match_re; |
| 186 |
cre2_decl cre2_match_rex_fun_t cre2_partial_match_re; |
| 187 |
cre2_decl cre2_match_rex2_fun_t cre2_consume_re; |
| 188 |
cre2_decl cre2_match_rex2_fun_t cre2_find_and_consume_re; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
cre2_decl int cre2_replace (const char * pattern, |
| 206 |
cre2_string_t * text_and_target, |
| 207 |
cre2_string_t * rewrite); |
| 208 |
cre2_decl int cre2_replace_re (cre2_regexp_t * rex, |
| 209 |
cre2_string_t * text_and_target, |
| 210 |
cre2_string_t * rewrite); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
cre2_decl int cre2_global_replace (const char * pattern, |
| 224 |
cre2_string_t * text_and_target, |
| 225 |
cre2_string_t * rewrite); |
| 226 |
cre2_decl int cre2_global_replace_re (cre2_regexp_t * rex, |
| 227 |
cre2_string_t * text_and_target, |
| 228 |
cre2_string_t * rewrite); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
cre2_decl int cre2_extract (const char * pattern, |
| 241 |
cre2_string_t * text, |
| 242 |
cre2_string_t * rewrite, |
| 243 |
cre2_string_t * target); |
| 244 |
|
| 245 |
cre2_decl int cre2_extract_re (cre2_regexp_t * rex, |
| 246 |
cre2_string_t * text, |
| 247 |
cre2_string_t * rewrite, |
| 248 |
cre2_string_t * target); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
cre2_decl int cre2_quote_meta (cre2_string_t * quoted, cre2_string_t * original); |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
cre2_decl int cre2_possible_match_range (cre2_regexp_t * rex, |
| 279 |
cre2_string_t * min_, cre2_string_t * max_, |
| 280 |
int maxlen); |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
cre2_decl int cre2_check_rewrite_string (cre2_regexp_t * rex, |
| 300 |
cre2_string_t * rewrite, cre2_string_t * errmsg); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
struct cre2_set; |
| 309 |
typedef struct cre2_set cre2_set; |
| 310 |
|
| 311 |
|
| 312 |
cre2_decl cre2_set *cre2_set_new(cre2_options_t *opt, cre2_anchor_t anchor); |
| 313 |
|
| 314 |
cre2_decl void cre2_set_delete(cre2_set *set); |
| 315 |
|
| 316 |
|
| 317 |
cre2_decl char* cre2_set_add(cre2_set *set, const char *pattern, size_t pattern_len); |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
cre2_decl int cre2_set_add_simple(cre2_set *set, const char *pattern); |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
cre2_decl int cre2_set_compile(cre2_set *set); |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
cre2_decl size_t cre2_set_match(cre2_set *set, const char *text, size_t text_len, |
| 330 |
int *match, size_t match_len); |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
#ifdef __cplusplus |
| 338 |
} |
| 339 |
#endif |
| 340 |
|
| 341 |
#endif |
| 342 |
|
| 343 |
|