You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+12-23
Original file line number
Diff line number
Diff line change
@@ -20,34 +20,20 @@ I think you should test the patterns you are going to use. You can easily modify
20
20
The main design goal of this library is to be small, correct, self contained and use few resources while retaining acceptable performance and feature completeness. Clarity of the code is also highly valued.
21
21
22
22
### Notable features and omissions
23
-
- Small code and binary size: <500 SLOC, ~3kb binary for x86. Statically #define'd memory usage / allocation.
23
+
- Small code and binary size: 500 SLOC, ~3kb binary for x86. Statically #define'd memory usage / allocation.
24
24
- No use of dynamic memory allocation (i.e. no calls to `malloc` / `free`).
25
25
- To avoid call-stack exhaustion, iterative searching is preferred over recursive by default (can be changed with a pre-processor flag).
26
26
- No support for capturing groups or named capture: `(^P<name>group)` etc.
27
27
- Thorough testing : [exrex](https://github.com/asciimoo/exrex) is used to randomly generate test-cases from regex patterns, which are fed into the regex code for verification. Try `make test` to generate a few thousand tests cases yourself.
28
-
- Compiled for x86 using GCC 4.7.4 and optimizing for size, the binary takes up ~2-3kb code space and allocates ~0.5kb RAM :
28
+
- Provides character length of matches.
29
+
- Compiled for x86 using GCC 7.2.0 and optimizing for size, the binary takes up ~2-3kb code space and allocates ~0.5kb RAM :
29
30
```
30
31
> gcc -Os -c re.c
31
32
> size re.o
32
33
text data bss dec hex filename
33
-
2319 0544 2863b2f re.o
34
+
2440160 544 3144c48 re.o
34
35
35
36
```
36
-
For ARM/Thumb using GCC 4.8.1 it's around 1.5kb code and less RAM :
37
-
```
38
-
> arm-none-eabi-gcc -Os -mthumb -c re.c
39
-
> size re.o
40
-
text data bss dec hex filename
41
-
1418 0 280 1698 6a2 re.o
42
-
43
-
```
44
-
For 8-bit AVR using AVR-GCC 4.8.1 it's around 2kb code and less RAM :
45
-
```
46
-
> avr-gcc -Os -c re.c
47
-
> size re.o
48
-
text data bss dec hex filename
49
-
2128 0 130 2258 8d2 re.o
50
-
```
51
37
52
38
53
39
@@ -61,10 +47,10 @@ typedef struct regex_t* re_t;
61
47
re_tre_compile(const char* pattern);
62
48
63
49
/* Finds matches of the compiled pattern inside text. */
64
-
int re_matchp(re_t pattern, const char* text);
50
+
int re_matchp(re_t pattern, const char* text, int* matchlength);
65
51
66
52
/* Finds matches of pattern inside text (compiles first automatically). */
67
-
int re_match(const char* pattern, const char* text);
53
+
int re_match(const char* pattern, const char* text, int* matchlength);
68
54
```
69
55
70
56
### Supported regex-operators
@@ -97,22 +83,25 @@ Search a text-string for a regex and get an index into the string, using `re_mat
97
83
98
84
The returned index points to the first place in the string, where the regex pattern matches.
99
85
86
+
The integer pointer passed will hold the length of the match.
87
+
100
88
If the regular expression doesn't match, the matching function returns an index of -1 to indicate failure.
101
89
102
90
### Examples
103
91
Example of usage:
104
92
```C
93
+
/* Standard int to hold length of match */
105
94
/* Standard null-terminated C-string to search: */
106
95
const char* string_to_search = "ahem.. 'hello world !' ..";
107
96
108
97
/* Compile a simple regular expression using character classes, meta-char and greedy + non-greedy quantifiers: */
0 commit comments