-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcre_subst.h
54 lines (44 loc) · 1.79 KB
/
pcre_subst.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
#ifndef PCRE_SUBST_H
#define PCRE_SUBST_H
// pcre_subst_create returns a null-terminated array of pcre_subst
#define PCRE_SUBST_END 0
#define PCRE_SUBST_REPLACEMENT 1
#define PCRE_SUBST_SUBJECT 2
typedef struct {
int type;
char *s; // string from replacement, when type = PCRE_SUBST_REPLACEMENT
int num; // number of backreference, when type = PCRE_SUBST_SUBJECT
} pcre_subst;
// default: substitutes \\ \n \r \t \e \a \f in replacement substrings and does not quote subject substrings
#define PCRE_SUBST_DEFAULT 0
// do not substitute \\ \n \r \t \e \a \f in replacement substrings (applies to create function only)
#define PCRE_SUBST_NO_SPECIAL_CHARS 1
// single-quote subject substrings, and escape any found single-quotes in them (applies to replace function only)
#define PCRE_SUBST_SHELL_ESCAPE_SUBJ 2
/*
* Create a subst structure.
* Result can be used repeatedly by pcre_subst_replace()
* Once a replacement string has been studied, it can be modified or freed.
*/
pcre_subst *pcre_subst_create(char *s, int options);
/*
* Replaces matches returned by pcre_exec() into pcre_subst structure, returning a string
* subject: the string matched with pcre_exec
* tpl: template as returned by pcre_subst_create
* ovector: same as returned by pcre_exec()
* ovecsize: same used with pcre_exec()
* return: a new allocated string with the substitutions made, must be freed by caller
*/
char *pcre_subst_replace(char *subject, pcre_subst *tpl, int *ovector, int ovecsize, int matches, int options);
/*
* Free replacement data returned by pcre_subst_create()
*/
void pcre_subst_free(pcre_subst *data);
/*
* Return string representing template (inverse of pcre_subst_create)
* return: a new allocated string, must be freed by caller
*/
#ifdef DEBUG
char *pcre_subst_str(pcre_subst *tpl);
#endif
#endif