summaryrefslogtreecommitdiffhomepage
path: root/docs/cregex_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-11 18:30:00 +0200
committerTyge Løvset <[email protected]>2022-09-11 21:47:10 +0200
commitc319568654c54243cb8fdb54f4ff53f0300a09a8 (patch)
tree8ec9558df96896d4d3f23fe2479988e86858a407 /docs/cregex_api.md
parent7eaeb7bb2c7cad9b0a437df71a396424b0c6933e (diff)
downloadSTC-modified-c319568654c54243cb8fdb54f4ff53f0300a09a8.tar.gz
STC-modified-c319568654c54243cb8fdb54f4ff53f0300a09a8.zip
Changed cregex API:
1) Renamed: cregex_find_pt() -> cregex_find_pattern() cregex_replace_pe() -> cregex_replace_pattern() cregex_replace_ex() -> cregex_replace_sv() 2) Removed: cregex_replace_pt() 3) Moved cregex* (or pattern) to be first parameter.
Diffstat (limited to 'docs/cregex_api.md')
-rw-r--r--docs/cregex_api.md29
1 files changed, 13 insertions, 16 deletions
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index 87e25e02..6fd5ba1d 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -32,20 +32,17 @@ int cregex_compile(cregex *self, const char* pattern, int cflags);
int cregex_captures(const cregex* self);
// return 1=match, 0=nomatch, -1=error. match array size: at least num groups in RE (1+).
-int cregex_find(const char* input, const cregex* re, csview match[], int mflags);
-int cregex_find_sv(csview input, const cregex* re, csview match[]);
- // takes string pattern instead of re. (for one-time matches)
-int cregex_find_pt(const char* input, const char* pattern, csview match[], int cmflags);
+int cregex_find(const cregex* re, const char* input, csview match[], int mflags);
+int cregex_find_sv(const cregex* re, csview input, csview match[]);
+int cregex_find_pattern(const char* pattern, const char* input, csview match[], int cmflags);
-bool cregex_is_match(const char* input, const cregex* re);
+bool cregex_is_match(const cregex* re, const char* input);
-cstr cregex_replace(const char* input, const cregex* re, const char* replace, unsigned count);
-cstr cregex_replace_ex(const char* input, const cregex* re, const char* replace, unsigned count,
- int rflags, bool (*mfun)(int grp, csview match, cstr* mstr));
- // takes string pattern instead of re
-cstr cregex_replace_pt(const char* input, const char* pattern, const char* replace, unsigned count);
-cstr cregex_replace_pe(const char* input, const char* pattern, const char* replace, unsigned count,
- int crflags, bool (*mfun)(int grp, csview match, cstr* mstr));
+cstr cregex_replace(const cregex* re, const char* input, const char* replace, unsigned count);
+cstr cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned count,
+ int rflags, bool(*mfun)(int capgrp, csview match, cstr* mstr));
+cstr cregex_replace_pattern(const char* pattern, const char* input, const char* replace, unsigned count,
+ int rflags, bool(*mfun)(int capgrp, csview match, cstr* mstr));
void cregex_drop(cregex* self); // destroy
```
@@ -101,13 +98,13 @@ int main() {
// Lets find the first date in the string:
csview match[4]; // full-match, year, month, date.
- if (cregex_find(input, &re, match, 0) == cre_success)
+ if (cregex_find(&re, input, match, 0) == cre_success)
printf("Found date: %.*s\n", c_ARGsv(match[0]));
else
printf("Could not find any date\n");
// Lets change all dates into US date format MM/DD/YYYY:
- cstr us_input = cregex_replace(input, &re, "$2/$3/$1");
+ cstr us_input = cregex_replace(&re, input, "$2/$3/$1");
printf("US input: %s\n", cstr_str(&us_input));
// Free allocated data
@@ -118,7 +115,7 @@ int main() {
For a single match you may use the all-in-one function:
```c
-if (cregex_find_pt(input, pattern, match, 0))
+if (cregex_find_pattern(pattern, input, match, 0))
printf("Found date: %.*s\n", c_ARGsv(match[0]));
```
@@ -130,7 +127,7 @@ In order to use a callback function in the replace call, see `examples/regex_rep
To iterate multiple matches in an input string, you may use:
```c
csview match[5] = {0};
-while (cregex_find(input, &re, match, cre_m_next) == cre_success)
+while (cregex_find(&re, input, match, cre_m_next) == cre_success)
c_forrange (int, k, cregex_captures(&re))
printf("submatch %d: %.*s\n", k, c_ARGsv(match[k]));
```