summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-13 18:03:22 +0100
committerTyge Løvset <[email protected]>2023-02-13 18:03:22 +0100
commita3645620cf4b8855801d9ca0cf7385de5a70c5d9 (patch)
tree4ef27f9dc36d03507d86a4e6fee66494152c76dd
parent3421d7b745310da05117fa97348a99a4a6ef8b5b (diff)
downloadSTC-modified-a3645620cf4b8855801d9ca0cf7385de5a70c5d9.tar.gz
STC-modified-a3645620cf4b8855801d9ca0cf7385de5a70c5d9.zip
Removed support for uppercase version of c_sv() (i.e c_SV => c_sv).
Renamed c_ARGSV => c_SV. Old name is still working.
-rw-r--r--README.md3
-rw-r--r--docs/cregex_api.md8
-rw-r--r--docs/csview_api.md28
-rw-r--r--include/stc/ccommon.h16
-rw-r--r--include/stc/cstr.h16
-rw-r--r--include/stc/csview.h8
-rw-r--r--include/stc/priv/altnames.h3
-rw-r--r--include/stc/utf8.h2
-rw-r--r--misc/examples/cstr_match.c4
-rw-r--r--misc/examples/forfilter.c4
-rw-r--r--misc/examples/regex2.c2
-rw-r--r--misc/examples/replace.c4
-rw-r--r--misc/examples/splitstr.c4
-rw-r--r--misc/examples/sso_substr.c2
-rw-r--r--misc/examples/sview_split.c4
-rw-r--r--misc/examples/utf8replace_c.c4
16 files changed, 56 insertions, 56 deletions
diff --git a/README.md b/README.md
index e450bed3..88edc13d 100644
--- a/README.md
+++ b/README.md
@@ -14,9 +14,10 @@ I am happy to finally announce a new release! Major changes:
- [crange](docs/ccommon_api.md#crange) - similar to [boost::irange](https://www.boost.org/doc/libs/release/libs/range/doc/html/range/reference/ranges/irange.html) integer range generator.
- [c_forfilter](docs/ccommon_api.md#c_forfilter) - ranges-like filtering.
- [csort](misc/benchmarks/various/csort_bench.c) - fast quicksort with custom inline comparison.
+- Renamed `c_ARGSV()` => `c_SV()`: **csview** print arg. `c_sv()` is the shorthand **csview** constructor.
- Support for [uppercase flow-control](include/stc/priv/altnames.h) macro names in ccommon.h.
+- Some API changes in **cregex** and **cstr**.
- Create single header container versions with python script.
-- Some API changes in cregex and cstr.
- [Previous changes for version 4](#version-4).
Introduction
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index 8cabb6fc..64fb6a2b 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_SVARG(match[0]));
+ printf("Found date: %.*s\n", c_SV(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_SVARG(match[0]));
+ printf("Found date: %.*s\n", c_SV(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_SVARG(match[k]));
+ printf("submatch %lld: %.*s\n", k, c_SV(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_SVARG(it.match[k]));
+ printf("submatch %lld: %.*s\n", k, c_SV(it.match[k]));
```
## Using cregex in a project
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 29c59d9c..33e61f0e 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -26,11 +26,11 @@ All csview definitions and prototypes are available by including a single header
## Methods
```c
-csview c_SV(const char literal_only[]); // construct from literal, no strlen()
-csview c_SV(const char* str, intptr_t n); // construct from str and length n
-csview csview_lit(const char literal_only[]); // alias for c_SV(lit)
+csview c_sv(const char literal_only[]); // construct from literal, no strlen()
+csview c_sv(const char* str, intptr_t n); // construct from str and length n
+csview csview_lit(const char literal_only[]); // alias for c_sv(lit)
csview csview_from(const char* str); // construct from const char*
-csview csview_from_n(const char* str, intptr_t n); // alias for c_SV(str, n)
+csview csview_from_n(const char* str, intptr_t n); // alias for c_sv(str, n)
intptr_t csview_size(csview sv);
bool csview_empty(csview sv);
@@ -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_SVARG(i.token));
+ printf("token: %.*s\n", c_SV(i.token));
```
#### Helper methods
@@ -111,8 +111,8 @@ uint64_t csview_hash(const csview* x);
| Name | Value | Usage |
|:---------------|:---------------------|:---------------------------------------------|
-| `csview_NULL` | same as `c_SV("")` | `sview = csview_NULL;` |
-| `c_SVARG(sv)` | printf argument | `printf("sv: %.*s\n", c_SVARG(sv));` |
+| `csview_NULL` | same as `c_sv("")` | `sview = csview_NULL;` |
+| `c_SV(sv)` | printf argument | `printf("sv: %.*s\n", c_SV(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_SVARG(sv1), c_SVARG(sv2), c_SVARG(sv3));
+ c_SV(sv1), c_SV(sv2), c_SV(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"
@@ -153,11 +153,11 @@ int main()
{
c_auto (cstr, s1) {
s1 = cstr_lit("hell😀 w😀rld");
- cstr_u8_replace_at(&s1, cstr_find(&s1, "😀rld"), 1, c_SV("ø"));
+ cstr_u8_replace_at(&s1, cstr_find(&s1, "😀rld"), 1, c_sv("ø"));
printf("%s\n", cstr_str(&s1));
c_foreach (i, cstr, s1)
- printf("%.*s,", c_SVARG(i.u8.chr));
+ printf("%.*s,", c_SV(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_SVARG(i.token));
+ printf("[%.*s]\n", c_SV(i.token));
}
#include <stc/cstr.h>
@@ -196,12 +196,12 @@ cstack_str string_split(csview input, const char* sep)
int main()
{
- print_split(c_SV("//This is a//double-slash//separated//string"), "//");
+ print_split(c_sv("//This is a//double-slash//separated//string"), "//");
puts("");
- print_split(c_SV("This has no matching separator"), "xx");
+ print_split(c_sv("This has no matching separator"), "xx");
puts("");
- c_with (cstack_str s = string_split(c_SV("Split,this,,string,now,"), ","), cstack_str_drop(&s))
+ c_with (cstack_str s = string_split(c_sv("Split,this,,string,now,"), ","), cstack_str_drop(&s))
c_foreach (i, cstack_str, s)
printf("[%s]\n", cstr_str(i.ref));
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 0b3083ef..04c26d4c 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -129,13 +129,13 @@ typedef const char* crawstr;
#define crawstr_hash(p) cstrhash(*(p))
#define crawstr_len(literal) (c_sizeof("" literal) - 1)
-#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_SVARG(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
-#define c_PAIR(ref) (ref)->first, (ref)->second
+#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_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
+#define c_SV(sv) (int)(sv).size, (sv).str // print csview: use format "%.*s"
+#define c_PAIR(ref) (ref)->first, (ref)->second
+#define c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) {
const uint8_t *x = (const uint8_t*) key;
@@ -143,7 +143,7 @@ STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) {
uint32_t u4;
while (n--) {
memcpy(&u8, x, 8), x += 8;
- h += (_c_ROTL(u8, 26) ^ u8)*0xc6a4a7935bd1e99d;
+ h += (c_ROTL(u8, 26) ^ u8)*0xc6a4a7935bd1e99d;
}
switch (len &= 7) {
case 0: return h;
@@ -152,7 +152,7 @@ STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) {
}
h += *x++;
while (--len) h = (h << 10) - h + *x++;
- return _c_ROTL(h, 26) ^ h;
+ return c_ROTL(h, 26) ^ h;
}
STC_INLINE uint64_t cstrhash(const char *str)
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index c5808d02..ce6dba81 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -181,10 +181,10 @@ STC_INLINE cstr cstr_toupper_sv(csview sv)
{ return cstr_tocase(sv, 2); }
STC_INLINE cstr cstr_tolower(const char* str)
- { return cstr_tolower_sv(c_SV(str, c_strlen(str))); }
+ { return cstr_tolower_sv(c_sv(str, c_strlen(str))); }
STC_INLINE cstr cstr_toupper(const char* str)
- { return cstr_toupper_sv(c_SV(str, c_strlen(str))); }
+ { return cstr_toupper_sv(c_sv(str, c_strlen(str))); }
STC_INLINE void cstr_lowercase(cstr* self)
{ cstr_take(self, cstr_tolower_sv(cstr_sv(self))); }
@@ -316,7 +316,7 @@ STC_INLINE bool cstr_starts_with_s(const cstr* self, cstr sub)
STC_INLINE bool cstr_istarts_with(const cstr* self, const char* sub) {
csview sv = cstr_sv(self);
intptr_t len = c_strlen(sub);
- return len <= sv.size && !utf8_icmp_sv(sv, c_SV(sub, len));
+ return len <= sv.size && !utf8_icmp_sv(sv, c_sv(sub, len));
}
@@ -330,7 +330,7 @@ STC_INLINE bool cstr_ends_with_s(const cstr* self, cstr sub)
{ return cstr_ends_with_sv(self, cstr_sv(&sub)); }
STC_INLINE bool cstr_ends_with(const cstr* self, const char* sub)
- { return cstr_ends_with_sv(self, c_SV(sub, c_strlen(sub))); }
+ { return cstr_ends_with_sv(self, c_sv(sub, c_strlen(sub))); }
STC_INLINE bool cstr_iends_with(const cstr* self, const char* sub) {
csview sv = cstr_sv(self);
@@ -375,8 +375,8 @@ STC_INLINE char* cstr_append_s(cstr* self, cstr s) {
#define cstr_replace(...) c_MACRO_OVERLOAD(cstr_replace, __VA_ARGS__)
#define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, INT32_MAX)
STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, int32_t count) {
- cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(search, c_strlen(search)),
- c_SV(repl, c_strlen(repl)), count));
+ cstr_take(self, cstr_replace_sv(cstr_sv(self), c_sv(search, c_strlen(search)),
+ c_sv(repl, c_strlen(repl)), count));
}
STC_INLINE void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const csview repl) {
@@ -385,7 +385,7 @@ STC_INLINE void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const
}
STC_INLINE void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl)
- { cstr_replace_at_sv(self, pos, len, c_SV(repl, c_strlen(repl))); }
+ { cstr_replace_at_sv(self, pos, len, c_sv(repl, c_strlen(repl))); }
STC_INLINE void cstr_replace_at_s(cstr* self, intptr_t pos, intptr_t len, cstr repl)
{ cstr_replace_at_sv(self, pos, len, cstr_sv(&repl)); }
@@ -395,7 +395,7 @@ STC_INLINE void cstr_u8_replace_at(cstr* self, intptr_t bytepos, intptr_t u8len,
STC_INLINE void cstr_insert(cstr* self, intptr_t pos, const char* str)
- { cstr_replace_at_sv(self, pos, 0, c_SV(str, c_strlen(str))); }
+ { cstr_replace_at_sv(self, pos, 0, c_sv(str, c_strlen(str))); }
STC_INLINE void cstr_insert_sv(cstr* self, intptr_t pos, csview sv)
{ cstr_replace_at_sv(self, pos, 0, sv); }
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 748f7d30..bba3aea3 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -27,12 +27,12 @@
#include "forward.h"
#include "utf8.h"
-#define csview_NULL c_SV_1("")
+#define csview_NULL c_sv_1("")
#define csview_init() csview_NULL
#define csview_drop(p) c_default_drop(p)
#define csview_clone(sv) c_default_clone(sv)
-#define csview_lit(literal) c_SV_1(literal)
-#define csview_from_n(str, n) c_SV_2(str, n)
+#define csview_lit(literal) c_sv_1(literal)
+#define csview_from_n(str, n) c_sv_2(str, n)
STC_API intptr_t csview_find_sv(csview sv, csview search);
@@ -47,7 +47,7 @@ STC_INLINE bool csview_equals(csview sv, const char* str)
{ intptr_t n = c_strlen(str); return sv.size == n && !c_memcmp(sv.str, str, n); }
STC_INLINE intptr_t csview_find(csview sv, const char* str)
- { return csview_find_sv(sv, c_SV(str, c_strlen(str))); }
+ { return csview_find_sv(sv, c_sv(str, c_strlen(str))); }
STC_INLINE bool csview_contains(csview sv, const char* str)
{ return csview_find(sv, str) != c_NPOS; }
diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h
index bfda05ca..b10c7a11 100644
--- a/include/stc/priv/altnames.h
+++ b/include/stc/priv/altnames.h
@@ -35,5 +35,4 @@
#define c_DEFER c_defer
#define c_NEW c_new
#define c_ARRAYLEN c_arraylen
-#define c_ARGSV c_SVARG
-#define c_sv c_SV
+#define c_ARGSV c_SV // [deprecated]
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index 7ad01ef4..a4cc3846 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -68,7 +68,7 @@ STC_INLINE uint32_t utf8_peek(const char* s) {
/* case-insensitive utf8 string comparison */
STC_INLINE int utf8_icmp(const char* s1, const char* s2) {
- return utf8_icmp_sv(c_SV(s1, INTPTR_MAX), c_SV(s2, INTPTR_MAX));
+ return utf8_icmp_sv(c_sv(s1, INTPTR_MAX), c_sv(s2, INTPTR_MAX));
}
STC_INLINE bool utf8_valid(const char* s) {
diff --git a/misc/examples/cstr_match.c b/misc/examples/cstr_match.c
index 4d11edbb..6682c4ba 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_SVARG(ch1));
- printf("ch2: %.*s\n", c_SVARG(ch2));
+ printf("ch1: %.*s\n", c_SV(ch1));
+ printf("ch2: %.*s\n", c_SV(ch2));
}
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index b0be4e69..5e1cf15e 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -102,14 +102,14 @@ void demo3(void)
puts("demo3:");
c_foreach (w, SVec, words_containing_i)
- printf(" %.*s", c_SVARG(*w.ref));
+ printf(" %.*s", c_SV(*w.ref));
puts("");
}
}
void demo4(void)
{
- csview s = c_SV("ab123cReAghNGnΩoEp"); // Ω = multi-byte
+ csview s = c_sv("ab123cReAghNGnΩoEp"); // Ω = multi-byte
c_auto (cstr, out) {
c_forfilter (i, csview, s, utf8_isupper(utf8_peek(i.ref))) {
char chr[4];
diff --git a/misc/examples/regex2.c b/misc/examples/regex2.c
index 4c58f3ba..20bd323c 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_SVARG(j.match[k]));
+ printf(" submatch %lld: %.*s\n", k, c_SV(j.match[k]));
}
}
}
diff --git a/misc/examples/replace.c b/misc/examples/replace.c
index 15cf3bae..c22c71ff 100644
--- a/misc/examples/replace.c
+++ b/misc/examples/replace.c
@@ -19,13 +19,13 @@ int main ()
cstr_replace_at(&s, 9, 5, s2); // "this is an example string." (1)
printf("(1) %s\n", cstr_str(&s));
- cstr_replace_at_sv(&s, 19, 6, c_SV(s3+7, 6)); // "this is an example phrase." (2)
+ cstr_replace_at_sv(&s, 19, 6, c_sv(s3+7, 6)); // "this is an example phrase." (2)
printf("(2) %s\n", cstr_str(&s));
cstr_replace_at(&s, 8, 10, "just a"); // "this is just a phrase." (3)
printf("(3) %s\n", cstr_str(&s));
- cstr_replace_at_sv(&s, 8, 6, c_SV("a shorty", 7)); // "this is a short phrase." (4)
+ cstr_replace_at_sv(&s, 8, 6, c_sv("a shorty", 7)); // "this is a short phrase." (4)
printf("(4) %s\n", cstr_str(&s));
cstr_replace_at(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5)
diff --git a/misc/examples/splitstr.c b/misc/examples/splitstr.c
index 4705696c..5bf02d42 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_SVARG(i.token));
+ printf("'%.*s'\n", c_SV(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_SVARG(i.match[0]));
+ printf("'%.*s'\n", c_SV(i.match[0]));
}
diff --git a/misc/examples/sso_substr.c b/misc/examples/sso_substr.c
index d17dc89c..4b2dbcc8 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_SVARG(sv1), c_SVARG(sv2), c_SVARG(sv3));
+ printf("%.*s, %.*s, %.*s\n", c_SV(sv1), c_SV(sv2), c_SV(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 2bb7aaee..18d547f8 100644
--- a/misc/examples/sview_split.c
+++ b/misc/examples/sview_split.c
@@ -4,13 +4,13 @@
int main()
{
// No memory allocations or string length calculations!
- const csview date = c_SV("2021/03/12");
+ const csview date = c_sv("2021/03/12");
intptr_t pos = 0;
const csview year = csview_token(date, "/", &pos);
const csview month = csview_token(date, "/", &pos);
const csview day = csview_token(date, "/", &pos);
- printf("%.*s, %.*s, %.*s\n", c_SVARG(year), c_SVARG(month), c_SVARG(day));
+ printf("%.*s, %.*s, %.*s\n", c_SV(year), c_SV(month), c_SV(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 adb8c042..b697efd8 100644
--- a/misc/examples/utf8replace_c.c
+++ b/misc/examples/utf8replace_c.c
@@ -11,12 +11,12 @@ int main()
cstr_u8_replace_at(&hello,
cstr_u8_to_pos(&hello, 7),
1,
- c_SV("🐨")
+ c_sv("🐨")
);
printf("%s\n", cstr_str(&hello));
c_foreach (c, cstr, hello)
- printf("%.*s,", c_SVARG(c.u8.chr));
+ printf("%.*s,", c_SV(c.u8.chr));
str = cstr_lit("scooby, dooby doo");
cstr_replace(&str, "oo", "00");