summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-05 21:21:55 +0100
committerTyge Løvset <[email protected]>2023-02-05 21:21:55 +0100
commite6dfaf1720f6833784d17d5364e1dd76324dff6a (patch)
tree0808f479425e58971aef993288bb818e60417422
parent217865ae413f9cfcc72af176ec7e98f418bddbea (diff)
downloadSTC-modified-e6dfaf1720f6833784d17d5364e1dd76324dff6a.tar.gz
STC-modified-e6dfaf1720f6833784d17d5364e1dd76324dff6a.zip
Some last minute changes: reverted mostly the c_extern from last commit.
Renamed c_ARGSV(sv) macro to c_SVARG(sv). Both available.
-rw-r--r--docs/cregex_api.md8
-rw-r--r--docs/csview_api.md10
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/crandom.h2
-rw-r--r--include/stc/cspan.h2
-rw-r--r--include/stc/csview.h2
-rw-r--r--include/stc/priv/altnames.h1
-rw-r--r--misc/examples/cstr_match.c4
-rw-r--r--misc/examples/forfilter.c2
-rw-r--r--misc/examples/regex2.c2
-rw-r--r--misc/examples/splitstr.c4
-rw-r--r--misc/examples/sso_substr.c2
-rw-r--r--misc/examples/sview_split.c2
-rw-r--r--misc/examples/utf8replace_c.c2
14 files changed, 23 insertions, 22 deletions
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index e74040d8..a115b4af 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -108,7 +108,7 @@ int main() {
// Lets find the first date in the string:
csview match[4]; // full-match, year, month, date.
if (cregex_find(&re, input, match, CREG_DEFAULT) == CREG_OK)
- printf("Found date: %.*s\n", c_ARGSV(match[0]));
+ printf("Found date: %.*s\n", c_SVARG(match[0]));
else
printf("Could not find any date\n");
@@ -124,7 +124,7 @@ int main() {
For a single match you may use the all-in-one function:
```c
if (cregex_find_pattern(pattern, input, match, CREG_DEFAULT))
- printf("Found date: %.*s\n", c_ARGSV(match[0]));
+ printf("Found date: %.*s\n", c_SVARG(match[0]));
```
To compile, use: `gcc first_match.c src/cregex.c src/utf8code.c`.
@@ -137,13 +137,13 @@ To iterate multiple matches in an input string, you may use
csview match[5] = {0};
while (cregex_find(&re, input, match, CREG_M_NEXT) == CREG_OK)
c_FORRANGE (k, cregex_captures(&re))
- printf("submatch %lld: %.*s\n", k, c_ARGSV(match[k]));
+ printf("submatch %lld: %.*s\n", k, c_SVARG(match[k]));
```
There is also a safe macro which simplifies this:
```c
c_FORMATCH (it, &re, input)
c_FORRANGE (k, cregex_captures(&re))
- printf("submatch %lld: %.*s\n", k, c_ARGSV(it.match[k]));
+ printf("submatch %lld: %.*s\n", k, c_SVARG(it.match[k]));
```
## Using cregex in a project
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 3971c6a6..e3c65766 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -88,7 +88,7 @@ csview cstr_slice_ex(const cstr* s, intptr_t p, intptr_t q); // nega
To iterate tokens in an input string separated by a string:
```c
c_FORTOKEN (i, "hello, one, two, three", ", ")
- printf("token: %.*s\n", c_ARGSV(i.token));
+ printf("token: %.*s\n", c_SVARG(i.token));
```
#### Helper methods
@@ -112,7 +112,7 @@ uint64_t csview_hash(const csview* x);
| Name | Value | Usage |
|:---------------|:---------------------|:---------------------------------------------|
| `csview_NULL` | same as `c_SV("")` | `sview = csview_NULL;` |
-| `c_ARGSV(sv)` | printf argument | `printf("sv: %.*s\n", c_ARGSV(sv));` |
+| `c_SVARG(sv)` | printf argument | `printf("sv: %.*s\n", c_SVARG(sv));` |
## Example
```c
@@ -129,7 +129,7 @@ int main ()
csview sv2 = cstr_substr(&str1, pos, 4); // get "live"
csview sv3 = cstr_slice(&str1, -8, -1); // get "details"
printf("%.*s %.*s %.*s\n",
- c_ARGSV(sv1), c_ARGSV(sv2), c_ARGSV(sv3));
+ c_SVARG(sv1), c_SVARG(sv2), c_SVARG(sv3));
cstr s1 = cstr_lit("Apples are red");
cstr s2 = cstr_from_sv(cstr_substr(&s1, -3, 3)); // "red"
cstr s3 = cstr_from_sv(cstr_substr(&s1, 0, 6)); // "Apples"
@@ -157,7 +157,7 @@ int main()
printf("%s\n", cstr_str(&s1));
c_FOREACH (i, cstr, s1)
- printf("%.*s,", c_ARGSV(i.u8.chr));
+ printf("%.*s,", c_SVARG(i.u8.chr));
}
}
```
@@ -177,7 +177,7 @@ and does not depend on null-terminated strings. *string_split()* function return
void print_split(csview input, const char* sep)
{
c_FORTOKEN_SV (i, input, sep)
- printf("[%.*s]\n", c_ARGSV(i.token));
+ printf("[%.*s]\n", c_SVARG(i.token));
}
#include <stc/cstr.h>
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index b8ea6316..d5daf252 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -133,7 +133,7 @@ typedef const char* crawstr;
#define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__)
#define c_SV_1(lit) c_SV_2(lit, crawstr_len(lit))
#define c_SV_2(str, n) (c_LITERAL(csview){str, n})
-#define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
+#define c_SVARG(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
#define c_PAIR(ref) (ref)->first, (ref)->second
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
diff --git a/include/stc/crandom.h b/include/stc/crandom.h
index 827c93d6..a9374602 100644
--- a/include/stc/crandom.h
+++ b/include/stc/crandom.h
@@ -109,7 +109,7 @@ STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) {
}
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_static) || defined(i_extern)
+#if defined(i_implement)
/* Global random() */
static stc64_t stc64_global = {{
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index f8ae9315..cc3d03b3 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -207,7 +207,7 @@ STC_API intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
int rank, const int32_t a[][2]);
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_static) || defined(i_extern)
+#if defined(i_implement)
STC_DEF intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stri[], const int32_t a[]) {
intptr_t off = a[0];
diff --git a/include/stc/csview.h b/include/stc/csview.h
index aa519fec..a30672cd 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -159,7 +159,7 @@ STC_INLINE bool csview_eq(const csview* x, const csview* y)
STC_API uint64_t csview_hash(const csview *self);
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_static) || defined(i_extern)
+#if defined(i_implement)
STC_DEF intptr_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h
index 024868c2..0c6db0b2 100644
--- a/include/stc/priv/altnames.h
+++ b/include/stc/priv/altnames.h
@@ -38,3 +38,4 @@
#define c_scope c_SCOPE
#define c_defer c_DEFER
#define c_sv c_SV
+#define c_ARGSV c_SVARG
diff --git a/misc/examples/cstr_match.c b/misc/examples/cstr_match.c
index bfb0df6b..828ef424 100644
--- a/misc/examples/cstr_match.c
+++ b/misc/examples/cstr_match.c
@@ -17,7 +17,7 @@ int main()
csview ch1 = cstr_u8_chr(&s1, 7);
csview ch2 = cstr_u8_chr(&s1, 10);
printf("%s\nsize: %" c_ZI ", %" c_ZI "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1));
- printf("ch1: %.*s\n", c_ARGSV(ch1));
- printf("ch2: %.*s\n", c_ARGSV(ch2));
+ printf("ch1: %.*s\n", c_SVARG(ch1));
+ printf("ch2: %.*s\n", c_SVARG(ch2));
}
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index 1c64c9e0..d7e1bb1e 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -102,7 +102,7 @@ void demo3(void)
puts("demo3:");
c_FOREACH (w, SVec, words_containing_i)
- printf(" %.*s", c_ARGSV(*w.ref));
+ printf(" %.*s", c_SVARG(*w.ref));
puts("");
}
}
diff --git a/misc/examples/regex2.c b/misc/examples/regex2.c
index 2b742529..296d4135 100644
--- a/misc/examples/regex2.c
+++ b/misc/examples/regex2.c
@@ -27,7 +27,7 @@ int main()
c_FORMATCH (j, &re, s[i].input) {
c_FORRANGE (k, cregex_captures(&re))
- printf(" submatch %lld: %.*s\n", k, c_ARGSV(j.match[k]));
+ printf(" submatch %lld: %.*s\n", k, c_SVARG(j.match[k]));
}
}
}
diff --git a/misc/examples/splitstr.c b/misc/examples/splitstr.c
index ba927412..43309634 100644
--- a/misc/examples/splitstr.c
+++ b/misc/examples/splitstr.c
@@ -8,12 +8,12 @@ int main()
puts("Split with c_FORTOKEN (csview):");
c_FORTOKEN (i, "Hello World C99!", " ")
- printf("'%.*s'\n", c_ARGSV(i.token));
+ printf("'%.*s'\n", c_SVARG(i.token));
puts("\nSplit with c_FORMATCH (regex):");
c_WITH (cregex re = cregex_from("[^ ]+"), cregex_drop(&re))
c_FORMATCH (i, &re, " Hello World C99! ")
- printf("'%.*s'\n", c_ARGSV(i.match[0]));
+ printf("'%.*s'\n", c_SVARG(i.match[0]));
}
diff --git a/misc/examples/sso_substr.c b/misc/examples/sso_substr.c
index 317f5e78..d17dc89c 100644
--- a/misc/examples/sso_substr.c
+++ b/misc/examples/sso_substr.c
@@ -8,7 +8,7 @@ int main ()
intptr_t pos = cstr_find(&str, "live"); // position of "live"
csview sv2 = cstr_substr_ex(&str, pos, 4); // "live"
csview sv3 = cstr_slice_ex(&str, -8, -1); // "details"
- printf("%.*s, %.*s, %.*s\n", c_ARGSV(sv1), c_ARGSV(sv2), c_ARGSV(sv3));
+ printf("%.*s, %.*s, %.*s\n", c_SVARG(sv1), c_SVARG(sv2), c_SVARG(sv3));
cstr_assign(&str, "apples are green or red");
cstr s2 = cstr_from_sv(cstr_substr_ex(&str, -3, 3)); // "red"
diff --git a/misc/examples/sview_split.c b/misc/examples/sview_split.c
index 2dd21a1a..77caf640 100644
--- a/misc/examples/sview_split.c
+++ b/misc/examples/sview_split.c
@@ -10,7 +10,7 @@ int main()
const csview month = csview_token(date, "/", &pos);
const csview day = csview_token(date, "/", &pos);
- printf("%.*s, %.*s, %.*s\n", c_ARGSV(year), c_ARGSV(month), c_ARGSV(day));
+ printf("%.*s, %.*s, %.*s\n", c_SVARG(year), c_SVARG(month), c_SVARG(day));
c_AUTO (cstr, y, m, d) {
y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day);
diff --git a/misc/examples/utf8replace_c.c b/misc/examples/utf8replace_c.c
index 3f98a2a6..035c5b00 100644
--- a/misc/examples/utf8replace_c.c
+++ b/misc/examples/utf8replace_c.c
@@ -14,7 +14,7 @@ int main() {
printf("%s\n", cstr_str(&hello));
c_FOREACH (c, cstr, hello)
- printf("%.*s,", c_ARGSV(c.u8.chr));
+ printf("%.*s,", c_SVARG(c.u8.chr));
str = cstr_lit("scooby, dooby doo");
cstr_replace(&str, "oo", "00");