comparison th_regex.h @ 640:9e1f9e1d1487

Aaand some more work. Still just a broken concept.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 24 Jan 2020 09:13:24 +0200
parents 8c957ad9d4c3
children b897995101b7
comparison
equal deleted inserted replaced
639:8c957ad9d4c3 640:9e1f9e1d1487
20 20
21 21
22 // 22 //
23 // Definitions 23 // Definitions
24 // 24 //
25
25 // Character type 26 // Character type
26 typedef char th_regex_char; 27 typedef char th_regex_char_t;
27 28
28 29
30 // Structure containing the compiled regular expression
31 struct th_regex_t;
32 typedef struct th_regex_t th_regex_t;
33
34
35 // Linked list structure for returned match sequences
36 typedef struct
37 {
38 th_llist_t node;
39 size_t start, len;
40 } th_regex_match_t;
41
42
43 // Flags for th_regex_match()
44 // (not actually used or supported yet :D)
29 enum 45 enum
30 { 46 {
31 TH_REF_CASEFOLD = 0x0001, 47 TH_REF_CASEFOLD = 0x0001,
32 TH_REF_ANCHORED = 0x0002, 48 TH_REF_ANCHORED = 0x0002,
33 }; 49 };
34
35
36 typedef struct
37 {
38 int type;
39 th_regex_char start, end;
40
41 size_t nchars;
42 th_regex_char *chars;
43 } th_regex_list_item;
44
45
46 typedef struct
47 {
48 size_t nitems, itemssize;
49 th_regex_list_item *items;
50 } th_regex_list;
51
52
53 struct th_regex_ctx;
54
55 typedef struct
56 {
57 int mode, type;
58 ssize_t repeatMin, repeatMax;
59
60 union
61 {
62 th_regex_char chr;
63
64 struct
65 {
66 size_t nchars;
67 th_regex_char *chars;
68 } list;
69
70 struct th_regex_ctx *expr;
71 } match;
72 } th_regex_node;
73
74
75 typedef struct th_regex_ctx
76 {
77 size_t nnodes, nodessize;
78 th_regex_node *nodes;
79 } th_regex_ctx;
80
81
82 typedef struct
83 {
84 th_llist_t node;
85 size_t start, len;
86 } th_regex_match_node;
87 50
88 51
89 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG 52 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG
90 enum 53 enum
91 { 54 {
99 62
100 63
101 // 64 //
102 // Functions 65 // Functions
103 // 66 //
104 int th_regex_compile(th_regex_ctx **pexpr, const th_regex_char *pattern); 67 int th_regex_compile(th_regex_t **pexpr, const th_regex_char_t *pattern);
105 void th_regex_free(th_regex_ctx *expr); 68 void th_regex_free(th_regex_t *expr);
106 69
107 int th_regex_match(const th_regex_ctx *expr, const th_regex_char *haystack, 70 int th_regex_match(const th_regex_t *expr, const th_regex_char_t *haystack,
108 size_t *pnmatches, th_regex_match_node **pmatches, const size_t maxmatches, 71 size_t *pnmatches, th_regex_match_t **pmatches, const size_t maxmatches,
109 const int flags); 72 const int flags);
110 void th_regex_free_matches(th_regex_match_node *matches); 73
74 void th_regex_free_matches(th_regex_match_t *matches);
111 75
112 76
113 #ifdef __cplusplus 77 #ifdef __cplusplus
114 } 78 }
115 #endif 79 #endif