-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrx.h
More file actions
143 lines (128 loc) · 2.81 KB
/
Copy pathrx.h
File metadata and controls
143 lines (128 loc) · 2.81 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef __RX_H__
#define __RX_H__
enum {
EMPTY,
TAKE,
BRANCH,
CAPTURE_START,
CAPTURE_END,
MATCH_END,
ASSERTION,
CHAR_CLASS,
CHAR_SET,
GROUP_START,
GROUP_END,
};
enum {
ASSERT_SOS, // start of string
ASSERT_SOL, // start of line
ASSERT_EOS, // end of string
ASSERT_EOL, // end of line
ASSERT_SOP, // start of position
ASSERT_SOW, // start of word
ASSERT_EOW, // end of word
};
enum {
CS_ANY,
CS_NOTNL,
CS_DIGIT,
CS_NOTDIGIT,
CS_WORD,
CS_NOTWORD,
CS_SPACE,
CS_NOTSPACE,
};
typedef unsigned int (hash_func_t) (void *key);
typedef int (equal_func_t) (void *key1, void *key2);
typedef struct {
int allocated;
int count;
int *defined;
unsigned int *hashes;
void **keys;
void **values;
hash_func_t *hash_func;
equal_func_t *equal_func;
} hash_t;
typedef struct node_t node_t;
typedef struct {
int min;
int max;
int greedy;
} quantifier_t;
typedef struct {
char negated;
int values_count;
char *values;
int ranges_count;
char *ranges;
int char_sets_count;
char *char_sets;
int str_size;
char *str;
} char_class_t;
struct node_t {
char type;
node_t *next;
union {
int value;
node_t *next2;
char_class_t *ccval;
};
};
typedef struct {
node_t *start;
int regexp_size;
char *regexp;
node_t **nodes;
int nodes_count;
int nodes_allocated;
int cap_count;
int cap_allocated;
node_t **cap_start;
node_t **or_end;
int error;
char *errorstr;
int ignorecase;
int char_classes_count;
int char_classes_allocated;
char_class_t **char_classes;
int dfs_stack_count;
int dfs_stack_allocated;
node_t **dfs_stack;
hash_t *dfs_map;
} rx_t;
typedef struct {
node_t *node;
int pos;
} path_t;
// The matcher maintains a list of positions that are important for backtracking
// and for remembering captures.
typedef struct {
int path_count;
int path_allocated;
path_t *path;
int cap_count;
int cap_allocated;
int *cap_start;
int *cap_end;
char *cap_defined;
char **cap_str;
int *cap_size;
int success;
int value;
} matcher_t;
rx_t *rx_alloc ();
matcher_t *rx_matcher_alloc ();
int rx_init (rx_t *rx, int regexp_size, char *regexp);
int rx_init_start (rx_t *rx, int regexp_size, char *regexp, node_t *start, int value);
node_t *rx_node_create (rx_t *rx);
void rx_print (rx_t *rx);
void rx_match_print (matcher_t *m);
int rx_match (rx_t *rx, matcher_t *m, int str_size, char *str, int start_pos);
int rx_hex_to_int (char *str, int size, unsigned int *dest);
int rx_int_to_utf8 (unsigned int value, char *str);
int rx_utf8_char_size (int str_size, char *str, int pos);
void rx_matcher_free (matcher_t *m);
void rx_free (rx_t *rx);
#endif