-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregex_util.h
60 lines (52 loc) · 2.25 KB
/
regex_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (C) 2015 Richard Burke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WED_REGEX_UTIL_H
#define WED_REGEX_UTIL_H
#include <stdarg.h>
#include <pcre.h>
#include "status.h"
#include "value.h"
/* Utility interface for regular expressions, in effect a wrapper
* around a couple of the core pcre_* functions. For more information:
* man pcreapi */
/* pcre_exec output vector size */
#define RE_OUTPUT_VECTOR_SIZE 90
/* Compiled PCRE regex */
typedef struct {
pcre *regex; /* Compiled regex */
pcre_extra *regex_study; /* Optimization info */
} RegexInstance;
/* Result of regex run */
typedef struct {
int match; /* True if match found, equivalent to checking return_code > 0 */
int return_code; /* pcre_exec return code */
int output_vector[RE_OUTPUT_VECTOR_SIZE]; /* Stores captured group data */
int match_length; /* output_vector[1] - output_vector[0] for convenience */
} RegexResult;
Status ru_compile(RegexInstance *, const Regex *);
Status ru_compile_custom_error_msg(RegexInstance *, const Regex *,
const char *fmt, ...);
void ru_free_instance(const RegexInstance *);
Status ru_exec(RegexResult *, const RegexInstance *, const char *str,
size_t str_len, size_t start);
Status ru_exec_custom_error_msg(RegexResult *, const RegexInstance *,
const char *str, size_t str_len, size_t start,
const char *fmt, ...);
Status ru_get_group(const RegexResult *, const char *str, size_t str_len,
size_t group, char **group_str_ptr);
#endif