summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authortylov <[email protected]>2023-08-14 09:42:35 +0200
committertylov <[email protected]>2023-08-14 09:42:35 +0200
commitfb5863de1d6ea8a5be8371e57bcd58bf31798a0a (patch)
treee2bc5d08051fd275e697472f6e5a70dd6ab6cb64 /include
parent25dc58db206714dc02c1ae0548f6ba7dd3519d29 (diff)
downloadSTC-modified-fb5863de1d6ea8a5be8371e57bcd58bf31798a0a.tar.gz
STC-modified-fb5863de1d6ea8a5be8371e57bcd58bf31798a0a.zip
Finished last commit (cleanup, fixes).
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h4
-rw-r--r--include/stc/cstr.h5
-rw-r--r--include/stc/csubstr.h5
-rw-r--r--include/stc/csview.h12
4 files changed, 11 insertions, 15 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 24967a10..1b4a2277 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -135,9 +135,9 @@ typedef const char* ccharptr;
#define c_ss_2(str, n) (c_LITERAL(csubstr){str, n})
#define c_SS(ss) (int)(ss).size, (ss).str // printf("%.*s\n", c_SS(ss));
-#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__)
-#define c_sv_1(literal) c_sv_2(literal, c_litstrlen(literal))
+#define c_sv(literal) c_sv_2(literal, c_litstrlen(literal))
#define c_sv_2(str, n) (c_LITERAL(csview){str, n})
+#define c_SV(sv) c_SS(sv) // [deprecated] - unneeded
#define c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 47cf65da..ce398628 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -115,7 +115,7 @@ STC_INLINE cstr cstr_from(const char* str)
STC_INLINE cstr cstr_from_ss(csubstr sv)
{ return cstr_from_n(sv.str, sv.size); }
-STC_INLINE cstr cstr_from_v(csview sv)
+STC_INLINE cstr cstr_from_sv(csview sv)
{ return cstr_from_n(sv.str, sv.size); }
STC_INLINE cstr cstr_with_size(const intptr_t size, const char value) {
@@ -252,9 +252,6 @@ STC_INLINE bool cstr_equals(const cstr* self, const char* str)
STC_INLINE bool cstr_equals_ss(const cstr* self, csubstr sv)
{ return sv.size == cstr_size(self) && !c_memcmp(cstr_str(self), sv.str, sv.size); }
-STC_INLINE bool cstr_equals_sv(const cstr* self, csview sv)
- { return sv.size == cstr_size(self) && !c_memcmp(cstr_str(self), sv.str, sv.size); }
-
STC_INLINE bool cstr_equals_s(const cstr* self, cstr s)
{ return !cstr_cmp(self, &s); }
diff --git a/include/stc/csubstr.h b/include/stc/csubstr.h
index 152f7041..c7a43052 100644
--- a/include/stc/csubstr.h
+++ b/include/stc/csubstr.h
@@ -45,8 +45,11 @@ STC_INLINE void csubstr_clear(csubstr* self) { *self = csubstr_init(); }
STC_INLINE intptr_t csubstr_size(csubstr ss) { return ss.size; }
STC_INLINE bool csubstr_empty(csubstr ss) { return ss.size == 0; }
+STC_INLINE bool csubstr_equals_ss(csubstr ss1, csubstr ss2)
+ { return ss1.size == ss2.size && !c_memcmp(ss1.str, ss2.str, ss1.size); }
+
STC_INLINE bool csubstr_equals(csubstr ss, const char* str)
- { intptr_t n = c_strlen(str); return ss.size == n && !c_memcmp(ss.str, str, n); }
+ { return csubstr_equals_ss(ss, c_ss_2(str, c_strlen(str))); }
STC_INLINE intptr_t csubstr_find(csubstr ss, const char* str)
{ return csubstr_find_ss(ss, c_ss_2(str, c_strlen(str))); }
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 0d1ca36c..367258e4 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -26,13 +26,12 @@
#ifndef CSVIEW_H_INCLUDED
#define CSVIEW_H_INCLUDED
-#define csview_init() c_sv_1("")
+#define csview_init() c_sv("")
#define csview_drop(p) c_default_drop(p)
#define csview_clone(sv) c_default_clone(sv)
-#define csview_from_n(str, n) c_sv_2(str, n)
STC_INLINE csview csview_from(const char* str)
- { return csview_from_n(str, c_strlen(str)); }
+ { return c_sv_2(str, c_strlen(str)); }
STC_INLINE void csview_clear(csview* self) { *self = csview_init(); }
STC_INLINE csubstr csview_ss(csview sv) { return c_ss_2(sv.str, sv.size); }
@@ -44,14 +43,11 @@ STC_INLINE bool csview_equals(csview sv, const char* str) {
return sv.size == n && !c_memcmp(sv.str, str, n);
}
-STC_INLINE intptr_t csview_find_v(csview sv, csview search) {
- char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
+STC_INLINE intptr_t csview_find(csview sv, const char* search) {
+ char* res = cstrnstrn(sv.str, search, sv.size, c_strlen(search));
return res ? (res - sv.str) : c_NPOS;
}
-STC_INLINE intptr_t csview_find(csview sv, const char* str)
- { return csview_find_v(sv, c_sv_2(str, c_strlen(str))); }
-
STC_INLINE bool csview_contains(csview sv, const char* str)
{ return csview_find(sv, str) != c_NPOS; }