summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-08-28 15:49:42 +0200
committerTyge Løvset <[email protected]>2021-08-28 15:49:42 +0200
commit28bf4ac92625b2ec7c4ddade9c14a4363ebd2681 (patch)
tree580ec2fa435464e18505a9bb0b30720bde2340ca
parent4c9ad3e584feff277800e1dfe49ae470e3c4a9c4 (diff)
downloadSTC-modified-28bf4ac92625b2ec7c4ddade9c14a4363ebd2681.tar.gz
STC-modified-28bf4ac92625b2ec7c4ddade9c14a4363ebd2681.zip
Breaking change cstr and csview renames in order to improve consistency:
cstr_equals() => cstr_equalto() cstr_compare_ref() => cstr_compare() cstr_equals_ref() => cstr_equals() cstr_hash_ref() => cstr_hash()
-rw-r--r--benchmarks/others/sstr.h8
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/cstr_api.md13
-rw-r--r--docs/csview_api.md8
-rw-r--r--examples/cstr_match.c2
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/cstr.h15
-rw-r--r--include/stc/csview.h10
8 files changed, 29 insertions, 31 deletions
diff --git a/benchmarks/others/sstr.h b/benchmarks/others/sstr.h
index 7947870a..5301978a 100644
--- a/benchmarks/others/sstr.h
+++ b/benchmarks/others/sstr.h
@@ -163,19 +163,19 @@ STC_INLINE sstr_size_t sstr_capacity(sstr s) {
return sstr_select_(&s, cap(&s));
}
-STC_INLINE bool sstr_equals(sstr s1, const char* str) {
+STC_INLINE bool sstr_equalto(sstr s1, const char* str) {
return strcmp(sstr_str(&s1), str) == 0;
}
-STC_INLINE bool sstr_equals_s(sstr s1, sstr s2) {
+STC_INLINE bool sstr_equalto_s(sstr s1, sstr s2) {
return strcmp(sstr_str(&s1), sstr_str(&s2)) == 0;
}
-STC_INLINE int sstr_equals_ref(const sstr* s1, const sstr* s2) {
+STC_INLINE int sstr_equals(const sstr* s1, const sstr* s2) {
return strcmp(sstr_str(s1), sstr_str(s2)) == 0;
}
-STC_INLINE int sstr_compare_ref(const sstr* s1, const sstr* s2) {
+STC_INLINE int sstr_compare(const sstr* s1, const sstr* s2) {
return strcmp(sstr_str(s1), sstr_str(s2));
}
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index ea9efb39..7467974f 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -275,7 +275,7 @@ static int Viking_equals(const Viking* a, const Viking* b) {
}
static uint32_t Viking_hash(const Viking* a, int ignored) {
- return cstr_hash(a->name) ^ (cstr_hash(a->country) >> 15);
+ return cstr_hash(&a->name) ^ (cstr_hash(&a->country) >> 15);
}
static void Viking_del(Viking* v) {
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index adf57209..1acceec2 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -58,15 +58,15 @@ void cstr_replace_all(cstr* self, const char* find, const char* replace)
void cstr_erase(cstr* self, size_t pos);
void cstr_erase_n(cstr* self, size_t pos, size_t n);
-bool cstr_equals(cstr s, const char* str);
-bool cstr_equals_s(cstr s, cstr s2);
+bool cstr_equalto(cstr s, const char* str);
+bool cstr_equalto_s(cstr s, cstr s2);
size_t cstr_find(cstr s, const char* needle);
size_t cstr_find_n(cstr s, const char* needle, size_t pos, size_t nmax);
bool cstr_contains(cstr s, const char* needle);
bool cstr_starts_with(cstr s, const char* str);
bool cstr_ends_with(cstr s, const char* str);
-bool cstr_iequals(cstr s, const char* str); // prefix i = case-insensitive
+bool cstr_iequalto(cstr s, const char* str); // prefix i = case-insensitive
size_t cstr_ifind_n(cstr s, const char* needle, size_t pos, size_t nmax);
bool cstr_icontains(cstr s, const char* needle);
bool cstr_istarts_with(cstr s, const char* str);
@@ -91,12 +91,13 @@ Note that all methods with arguments `(..., const char* str, size_t n)`, `n` mus
```c
const char* cstr_toraw(const cstr* self);
-int cstr_compare_ref(const cstr *s1, const cstr *s2);
-bool cstr_equals_ref(const cstr *s1, const cstr *s2);
+int cstr_compare(const cstr *s1, const cstr *s2);
+bool cstr_equals(const cstr *s1, const cstr *s2);
+bool cstr_hash(const cstr *s, ...);
int c_rawstr_compare(const char** x, const char** y);
bool c_rawstr_equals(const char** x, const char** y);
-uint64_t c_rawstr_hash(const char* const* x, size_t ignored);
+uint64_t c_rawstr_hash(const char* const* x, ...);
int c_strncasecmp(const char* str1, const char* str2, size_t n);
char* c_strnstrn(const char* str, const char* needle, size_t slen, size_t nlen);
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 70bc9b41..dfca37c5 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -45,7 +45,7 @@ csview csview_slice(csview sv, intptr_t p1, intptr_t p2); // negative p
csview csview_first_token(csview sv, csview sep); // see split example below.
csview csview_next_token(csview sv, csview sep, csview token);
-bool csview_equals(csview sv, csview sv2);
+bool csview_equalto(csview sv, csview sv2);
size_t csview_find(csview sv, csview needle);
bool csview_contains(csview sv, csview needle);
bool csview_starts_with(csview sv, csview sub);
@@ -78,9 +78,9 @@ bool cstr_ends_with_v(cstr s, csview sub);
```
#### Helper methods
```c
-int csview_compare_ref(const csview* x, const csview* y);
-bool csview_equals_ref(const csview* x, const csview* y);
-uint64_t csview_hash_ref(const csview* x, size_t ignored);
+int csview_compare(const csview* x, const csview* y);
+bool csview_equals(const csview* x, const csview* y);
+uint64_t csview_hash(const csview* x, ...);
```
## Types
diff --git a/examples/cstr_match.c b/examples/cstr_match.c
index 72bdd2d2..a4dbe8d8 100644
--- a/examples/cstr_match.c
+++ b/examples/cstr_match.c
@@ -6,7 +6,7 @@ int main()
c_forvar (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_del(&ss)) {
size_t pos = cstr_find_n(ss, "brown", 0, 5);
printf("%zu [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
- printf("iequals: %d\n", cstr_iequals(ss, "the quick brown fox jumps over the lazy dog.jpg"));
+ printf("iequals: %d\n", cstr_iequalto(ss, "the quick brown fox jumps over the lazy dog.jpg"));
printf("icontains: %d\n", cstr_icontains(ss, "uMPS Ove"));
printf("istarts_with: %d\n", cstr_istarts_with(ss, "The Quick Brown"));
printf("iends_with: %d\n", cstr_iends_with(ss, ".Jpg"));
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index f79060a8..b2501416 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -99,7 +99,7 @@
#define c_rawstr_compare(x, y) strcmp(*(x), *(y))
#define c_rawstr_equals(x, y) (strcmp(*(x), *(y)) == 0)
-#define c_rawstr_hash(p, none) c_default_hash(*(p), strlen(*(p)))
+#define c_rawstr_hash(p, ...) c_default_hash(*(p), strlen(*(p)))
#define c_no_clone(x) (assert(!"c_no_clone() called"), x)
#define c_default_fromraw(x) (x)
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index d5c2dd86..e7af71f3 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -118,11 +118,11 @@ STC_INLINE cstr_iter_t cstr_begin(cstr* self)
STC_INLINE cstr_iter_t cstr_end(cstr* self)
{ return c_make(cstr_iter_t){self->str + _cstr_rep(self)->size}; }
STC_INLINE void cstr_next(cstr_iter_t* it) {++it->ref; }
-STC_INLINE bool cstr_equals(cstr s, const char* str)
+STC_INLINE bool cstr_equalto(cstr s, const char* str)
{ return strcmp(s.str, str) == 0; }
-STC_INLINE bool cstr_equals_s(cstr s1, cstr s2)
+STC_INLINE bool cstr_equalto_s(cstr s1, cstr s2)
{ return strcmp(s1.str, s2.str) == 0; }
-STC_INLINE bool cstr_iequals(cstr s, const char* str)
+STC_INLINE bool cstr_iequalto(cstr s, const char* str)
{ return c_strncasecmp(s.str, str, cstr_npos) == 0; }
STC_INLINE bool cstr_contains(cstr s, const char* needle)
{ return strstr(s.str, needle) != NULL; }
@@ -184,12 +184,11 @@ cstr_iends_with(cstr s, const char* sub) {
return n <= sz && !c_strncasecmp(s.str + sz - n, sub, n);
}
-/* cvec/cmap adaption functions: */
+/* container adaptor functions: */
#define cstr_toraw(xp) ((xp)->str)
-#define cstr_compare_ref(xp, yp) strcmp((xp)->str, (yp)->str)
-#define cstr_equals_ref(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
-#define cstr_hash_ref(xp, none) c_default_hash((xp)->str, cstr_size(*(xp)))
-#define cstr_hash(x) c_default_hash((x).str, cstr_size(x))
+#define cstr_compare(xp, yp) strcmp((xp)->str, (yp)->str)
+#define cstr_equals(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
+#define cstr_hash(xp, ...) c_default_hash((xp)->str, cstr_size(*(xp)))
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/csview.h b/include/stc/csview.h
index c631a0b7..d5d6d246 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -57,8 +57,7 @@ STC_INLINE char csview_back(csview sv) { return sv.str[sv.size - 1]; }
STC_INLINE void csview_clear(csview* self) { *self = csview_null; }
-#define csview_hash(sv) c_default_hash((sv).str, (sv).size)
-STC_INLINE bool csview_equals(csview sv, csview sv2)
+STC_INLINE bool csview_equalto(csview sv, csview sv2)
{ return sv.size == sv2.size && !memcmp(sv.str, sv2.str, sv.size); }
STC_INLINE size_t csview_find(csview sv, csview needle)
{ char* res = c_strnstrn(sv.str, needle.str, sv.size, needle.size);
@@ -115,10 +114,9 @@ STC_INLINE bool cstr_ends_with_v(cstr s, csview sub)
/* ---- Container helper functions ---- */
-STC_INLINE bool csview_equals_ref(const csview* a, const csview* b)
- { return a->size == b->size && !memcmp(a->str, b->str, a->size); }
-#define csview_hash_ref(xp, none) c_default_hash((xp)->str, (xp)->size)
-#define csview_compare_ref(xp, yp) strcmp((xp)->str, (yp)->str)
+#define csview_compare(xp, yp) strcmp((xp)->str, (yp)->str)
+#define csview_hash(xp, ...) c_default_hash((xp)->str, (xp)->size)
+#define csview_equals(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
/* -------------------------- IMPLEMENTATION ------------------------- */