diff options
| author | Tyge Løvset <[email protected]> | 2022-12-20 10:59:31 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-20 10:59:31 +0100 |
| commit | 21817cae767d72e6007150b639f9365e35502173 (patch) | |
| tree | 4c897b401c75a243f11c6ea8cf0ca8699376a680 | |
| parent | 6167fa5e361b2954440594cb693f25f643eb9e0a (diff) | |
| download | STC-modified-21817cae767d72e6007150b639f9365e35502173.tar.gz STC-modified-21817cae767d72e6007150b639f9365e35502173.zip | |
Renamed c_sv() => c_SV() and reverted cstr_new() => cstr_lit(). Old names are deprecated (not removed).
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | docs/csview_api.md | 15 | ||||
| -rw-r--r-- | examples/forfilter.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 4 | ||||
| -rw-r--r-- | examples/sview_split.c | 2 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 2 | ||||
| -rw-r--r-- | include/stc/alt/cstr.h | 14 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 10 | ||||
| -rw-r--r-- | include/stc/cstr.h | 16 | ||||
| -rw-r--r-- | include/stc/csview.h | 7 | ||||
| -rw-r--r-- | include/stc/utf8.h | 2 | ||||
| -rw-r--r-- | src/cregex.c | 3 | ||||
| -rw-r--r-- | tests/cregex_test.c | 2 |
13 files changed, 40 insertions, 40 deletions
@@ -489,7 +489,6 @@ Memory efficiency - Renamed `csview_*_u8()` => `csview_u8_*()` - Added cstr_u8_slice() and csview_u8_slice(). - Removed `csview_from_s()`: Use `cstr_sv(s)` instead. - - Removed `csview_from_n()`: Use `c_sv(str, n)` instead. - Added back file coption.h - Simplified **cbits** usage: all inlined. - Updated docs. diff --git a/docs/csview_api.md b/docs/csview_api.md index 59ebf58d..8d288783 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -26,9 +26,10 @@ 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, size_t n); // overloaded csview constructor. +csview c_SV(const char literal_only[]); // construct from literal, no strlen() +csview c_SV(const char* str, size_t n); // shorthand for csview_from_n() csview csview_from(const char* str); // construct from const char* +csview csview_from_n(const char* str); // construct from const char* and len void csview_clear(csview* self); size_t csview_size(csview sv); @@ -109,7 +110,7 @@ uint64_t csview_hash(const csview* x); | Name | Value | Usage | |:---------------|:---------------------|:---------------------------------------------| -| `csview_NULL` | same as `c_sv("")` | `sview = csview_NULL;` | +| `csview_NULL` | same as `c_SV("")` | `sview = csview_NULL;` | | `c_ARGSV(sv)` | printf argument | `printf("sv: %.*s\n", c_ARGSV(sv));` | ## Example @@ -151,7 +152,7 @@ int main() { c_auto (cstr, s1) { s1 = cstr_new("hell😀 w😀rld"); - cstr_u8_replace(&s1, cstr_find(&s1, "😀rld"), 1, c_sv("ø")); + cstr_u8_replace(&s1, cstr_find(&s1, "😀rld"), 1, c_SV("ø")); printf("%s\n", cstr_str(&s1)); c_foreach (i, cstr, s1) @@ -194,12 +195,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/examples/forfilter.c b/examples/forfilter.c index 9eb1536e..ba4dce7f 100644 --- a/examples/forfilter.c +++ b/examples/forfilter.c @@ -106,7 +106,7 @@ void demo3(void) 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/examples/replace.c b/examples/replace.c index c22c71ff..15cf3bae 100644 --- a/examples/replace.c +++ b/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/examples/sview_split.c b/examples/sview_split.c index 81d93276..d22fccd1 100644 --- a/examples/sview_split.c +++ b/examples/sview_split.c @@ -5,7 +5,7 @@ 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"); size_t pos = 0; const csview year = csview_token(date, "/", &pos); const csview month = csview_token(date, "/", &pos); diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index c2b3c0cf..35e6b8ef 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -8,7 +8,7 @@ int main() { printf("%s\n", cstr_str(&hello)); /* replace second smiley at utf8 codepoint pos 7 */ - cstr_u8_replace(&hello, cstr_u8_to_pos(&hello, 7), 1, c_sv("🐨")); + cstr_u8_replace(&hello, cstr_u8_to_pos(&hello, 7), 1, c_SV("🐨")); printf("%s\n", cstr_str(&hello)); cstr_replace(&hello, "🐨", "ø", 1); diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 4496fb35..37eaa318 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -95,15 +95,15 @@ STC_INLINE void cstr_push_back(cstr* self, char value) STC_INLINE void cstr_pop_back(cstr* self) { self->str[ --_cstr_p(self)->size ] = '\0'; } STC_INLINE void cstr_insert_n(cstr* self, const size_t pos, const char* str, const size_t n) - { cstr_replace_at_sv(self, pos, 0, c_sv(str, n)); } + { cstr_replace_at_sv(self, pos, 0, c_SV(str, n)); } STC_INLINE void cstr_insert(cstr* self, const size_t pos, const char* str) - { cstr_replace_at_sv(self, pos, 0, c_sv(str, strlen(str))); } + { cstr_replace_at_sv(self, pos, 0, c_SV(str, strlen(str))); } STC_INLINE void cstr_insert_s(cstr* self, const size_t pos, cstr s) - { cstr_replace_at_sv(self, pos, 0, c_sv(s.str, _cstr_p(&s)->size)); } + { cstr_replace_at_sv(self, pos, 0, c_SV(s.str, _cstr_p(&s)->size)); } STC_INLINE void cstr_replace_at(cstr* self, const size_t pos, const size_t len, const char* str) - { cstr_replace_at_sv(self, pos, len, c_sv(str, strlen(str))); } + { cstr_replace_at_sv(self, pos, len, c_SV(str, strlen(str))); } STC_INLINE void cstr_replace_s(cstr* self, const size_t pos, const size_t len, cstr s) - { cstr_replace_at_sv(self, pos, len, c_sv(s.str, _cstr_p(&s)->size)); } + { cstr_replace_at_sv(self, pos, len, c_SV(s.str, _cstr_p(&s)->size)); } STC_INLINE char* cstr_front(cstr* self) { return self->str; } STC_INLINE char* cstr_back(cstr* self) { return self->str + _cstr_p(self)->size - 1; } @@ -185,8 +185,8 @@ STC_INLINE uint64_t cstr_hash(const cstr *self) { STC_INLINE void cstr_replace(cstr* self, const char* find, const char* repl, unsigned count) { csview in = cstr_sv(self); - cstr_take(self, cstr_replace_sv(in, c_sv(find, strlen(find)), - c_sv(repl, strlen(repl)), count)); + cstr_take(self, cstr_replace_sv(in, c_SV(find, strlen(find)), + c_SV(repl, strlen(repl)), count)); } /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 9aa55e00..af6b52a5 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -117,12 +117,13 @@ typedef const char* crawstr; #define crawstr_hash(p) cstrhash(*(p)) #define c_strlen_lit(literal) (sizeof("" literal) - 1U) -#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__) -#define c_sv1(lit) c_sv2(lit, c_strlen_lit(lit)) -#define c_sv2(str, n) (c_INIT(csview){str, n}) -#define c_ARGsv(sv) c_ARGSV(sv) /* [deprecated] */ +#define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__) +#define c_SV1(lit) c_SV2(lit, c_strlen_lit(lit)) +#define c_SV2(str, n) (c_INIT(csview){str, n}) #define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */ #define c_PAIR(ref) (ref)->first, (ref)->second +#define c_sv c_SV /* [deprecated] */ +#define c_ARGsv(sv) c_ARGSV(sv) /* [deprecated] */ #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) @@ -177,7 +178,6 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, ; _.it.ref && (_.key = &_.it.ref->first, _.val = &_.it.ref->second) \ ; C##_next(&_.it)) -#define c_forloop c_forrange // [deprecated] #define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__) #define c_forrange1(stop) c_forrange3(_c_i, 0, stop) #define c_forrange2(i, stop) c_forrange3(i, 0, stop) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index b60a072e..a0dd1adc 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -183,10 +183,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, strlen(str))); } + { return cstr_tolower_sv(c_SV(str, strlen(str))); } STC_INLINE cstr cstr_toupper(const char* str) - { return cstr_toupper_sv(c_sv(str, strlen(str))); } + { return cstr_toupper_sv(c_SV(str, strlen(str))); } STC_INLINE void cstr_lowercase(cstr* self) { cstr_take(self, cstr_tolower_sv(cstr_sv(self))); } @@ -318,7 +318,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); size_t len = 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)); } @@ -332,7 +332,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, strlen(sub))); } + { return cstr_ends_with_sv(self, c_SV(sub, strlen(sub))); } STC_INLINE bool cstr_iends_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); @@ -381,7 +381,7 @@ STC_INLINE void cstr_replace_at_sv(cstr* self, size_t pos, size_t len, const csv } STC_INLINE void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl) - { cstr_replace_at_sv(self, pos, len, c_sv(repl, strlen(repl))); } + { cstr_replace_at_sv(self, pos, len, c_SV(repl, strlen(repl))); } STC_INLINE void cstr_replace_at_s(cstr* self, size_t pos, size_t len, cstr repl) { cstr_replace_at_sv(self, pos, len, cstr_sv(&repl)); } @@ -391,7 +391,7 @@ STC_INLINE void cstr_u8_replace(cstr* self, size_t bytepos, size_t u8len, csview STC_INLINE void cstr_insert(cstr* self, size_t pos, const char* str) - { cstr_replace_at_sv(self, pos, 0, c_sv(str, strlen(str))); } + { cstr_replace_at_sv(self, pos, 0, c_SV(str, strlen(str))); } STC_INLINE void cstr_insert_sv(cstr* self, size_t pos, csview sv) { cstr_replace_at_sv(self, pos, 0, sv); } @@ -584,8 +584,8 @@ cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { STC_DEF void cstr_replace(cstr* self, const char* search, const char* repl, unsigned count) { csview in = cstr_sv(self); - cstr_take(self, cstr_replace_sv(in, c_sv(search, strlen(search)), - c_sv(repl, strlen(repl)), count)); + cstr_take(self, cstr_replace_sv(in, c_SV(search, strlen(search)), + c_SV(repl, strlen(repl)), count)); } STC_DEF void cstr_erase(cstr* self, const size_t pos, size_t len) { diff --git a/include/stc/csview.h b/include/stc/csview.h index e0f2ad0e..972bc788 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -27,11 +27,12 @@ #include "forward.h" #include "utf8.h" -#define csview_NULL c_sv1("") +#define csview_NULL c_SV1("") #define csview_init() csview_NULL #define csview_drop(p) c_default_drop(p) #define csview_clone(sv) c_default_clone(sv) -#define csview_from_n(str, n) c_sv2(str, n) +#define csview_lit(literal) c_SV1(literal) +#define csview_from_n(str, n) c_SV2(str, n) STC_API size_t csview_find_sv(csview sv, csview search); @@ -46,7 +47,7 @@ STC_INLINE bool csview_equals(csview sv, const char* str) { size_t n = strlen(str); return sv.size == n && !memcmp(sv.str, str, n); } STC_INLINE size_t csview_find(csview sv, const char* str) - { return csview_find_sv(sv, c_sv(str, strlen(str))); } + { return csview_find_sv(sv, c_SV(str, strlen(str))); } STC_INLINE bool csview_contains(csview sv, const char* str) { return csview_find(sv, str) != c_NPOS; } diff --git a/include/stc/utf8.h b/include/stc/utf8.h index ab39f3ba..cf36ee1c 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -43,7 +43,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, ~(size_t)0), c_sv(s2, ~(size_t)0)); + return utf8_icmp_sv(c_SV(s1, ~(size_t)0), c_SV(s2, ~(size_t)0)); } STC_INLINE bool utf8_valid(const char* s) { diff --git a/src/cregex.c b/src/cregex.c index 94e591a4..c30ff967 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -209,7 +209,7 @@ utfruneicase(const char *s, _Rune c) _Rune r = *s; int n; if (c < 128) for (c = tolower(c); r; ++s, r = *(unsigned char*)s) { - if (r < 128 && tolower(r) == c) return s; + if (r < 128 && (unsigned)tolower(r) == c) return s; } else for (c = utf8_casefold(c); r; s += n, r = *(unsigned char*)s) { if (r < 128) { n = 1; continue; } @@ -653,7 +653,6 @@ _lexutfclass(_Parser *par, _Rune *rp) case 'v': rune = '\v'; break; \ case 'f': rune = '\f'; break; \ case 'a': rune = '\a'; break; \ - case 'e': rune = '\e'; break; \ case 'd': rune = UTF_d; break; \ case 'D': rune = UTF_D; break; \ case 's': rune = UTF_s; break; \ diff --git a/tests/cregex_test.c b/tests/cregex_test.c index 3125600f..b9642159 100644 --- a/tests/cregex_test.c +++ b/tests/cregex_test.c @@ -225,7 +225,7 @@ START_TEST(captures_cap) csview cap[5]; EXPECT_EQ(cregex_find("xxabcdcde", &re, cap, 0), 1); - EXPECT_TRUE(csview_equals(cap.match[0], c_sv("abcdcd"))); + EXPECT_TRUE(csview_equals(cap.match[0], c_SV("abcdcd"))); /* EXPECT_EQ(cap0.end, 8); EXPECT_EQ(cap1.start, 2); |
