summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-01-14 09:09:45 +0100
committerTyge Løvset <[email protected]>2022-01-14 09:09:45 +0100
commitc0359b2d99be860370a3520cbddf11cd3dd1ade9 (patch)
tree152a04e3ef9e0b9e5be13f5ffee4cab51905c2d6
parent379c01f19e186dbd9889bc9dd43d6d867a2a33be (diff)
downloadSTC-modified-c0359b2d99be860370a3520cbddf11cd3dd1ade9.tar.gz
STC-modified-c0359b2d99be860370a3520cbddf11cd3dd1ade9.zip
Renamed *_v() methods to *_sv(). Note: this breaks API, hopefully not too intrusive.
The change was needed to be consistent in using 'sv' as a shorthand for "string view" everywhere, and is easier to understand than _v().
-rw-r--r--docs/csview_api.md30
-rw-r--r--examples/splitstr.c2
-rw-r--r--examples/sview_split.c2
-rw-r--r--include/stc/csview.h24
-rw-r--r--include/stc/utf8.h2
5 files changed, 30 insertions, 30 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 36d82436..a6bd7573 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -56,24 +56,24 @@ void csview_next(csview_iter* it);
```
#### Extended cstr methods
```c
-cstr cstr_from_v(csview sv); // construct cstr from csview
-csview cstr_to_v(const cstr* self); // convert to csview from cstr*
-cstr cstr_from_replace_all_v(csview sv, csview find, csview replace);
+cstr cstr_from_sv(csview sv); // construct cstr from csview
+csview cstr_to_sv(const cstr* self); // convert to csview from cstr*
+cstr cstr_from_replace_all_sv(csview sv, csview find, csview replace);
csview cstr_sv(cstr s); // convert to csview from cstr
csview cstr_substr(cstr s, intptr_t pos, size_t n); // negative pos counts from end
csview cstr_slice(cstr s, intptr_t p1, intptr_t p2); // negative p1, p2 counts from end
-cstr* cstr_assign_v(cstr* self, csview sv);
-cstr* cstr_append_v(cstr* self, csview sv);
-void cstr_insert_v(cstr* self, size_t pos, csview sv);
-void cstr_replace_v(cstr* self, size_t pos, size_t len, csview sv);
+cstr* cstr_assign_sv(cstr* self, csview sv);
+cstr* cstr_append_sv(cstr* self, csview sv);
+void cstr_insert_sv(cstr* self, size_t pos, csview sv);
+void cstr_replace_sv(cstr* self, size_t pos, size_t len, csview sv);
-bool cstr_equals_v(cstr s, csview sv);
-size_t cstr_find_v(cstr s, csview needle);
-bool cstr_contains_v(cstr s, csview needle);
-bool cstr_starts_with_v(cstr s, csview sub);
-bool cstr_ends_with_v(cstr s, csview sub);
+bool cstr_equals_sv(cstr s, csview sv);
+size_t cstr_find_sv(cstr s, csview needle);
+bool cstr_contains_sv(cstr s, csview needle);
+bool cstr_starts_with_sv(cstr s, csview sub);
+bool cstr_ends_with_sv(cstr s, csview sub);
```
#### Helper methods
```c
@@ -114,8 +114,8 @@ int main ()
printf(c_PRIsv c_PRIsv c_PRIsv "\n", c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3));
cstr s1 = cstr_new("Apples are red");
- cstr s2 = cstr_from_v(cstr_substr(s1, -3, 3)); // "red"
- cstr s3 = cstr_from_v(cstr_substr(s1, 0, 6)); // "Apples"
+ cstr s2 = cstr_from_sv(cstr_substr(s1, -3, 3)); // "red"
+ cstr s3 = cstr_from_sv(cstr_substr(s1, 0, 6)); // "Apples"
printf("%s %s\n", s2, s3.str);
c_drop(cstr, &str1, &s1, &s2, &s3);
@@ -153,7 +153,7 @@ cvec_str string_split(csview str, csview sep)
size_t pos = 0;
while (pos != str.size) {
csview tok = csview_token(str, sep, &pos);
- cvec_str_push_back(&vec, cstr_from_v(tok));
+ cvec_str_push_back(&vec, cstr_from_sv(tok));
}
return vec;
}
diff --git a/examples/splitstr.c b/examples/splitstr.c
index 695e7595..35fe3cfa 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -18,7 +18,7 @@ cvec_str string_split(csview str, csview sep)
size_t pos = 0;
while (pos != str.size) {
csview tok = csview_token(str, sep, &pos);
- cvec_str_push_back(&vec, cstr_from_v(tok));
+ cvec_str_push_back(&vec, cstr_from_sv(tok));
}
return vec;
}
diff --git a/examples/sview_split.c b/examples/sview_split.c
index 1c29240b..0db175ce 100644
--- a/examples/sview_split.c
+++ b/examples/sview_split.c
@@ -14,7 +14,7 @@ int main()
c_ARGsv(year), c_ARGsv(month), c_ARGsv(day));
c_auto (cstr, y, m, d) {
- y = cstr_from_v(year), m = cstr_from_v(month), d = cstr_from_v(day);
+ y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day);
printf("%s, %s, %s\n", y.str, m.str, d.str);
}
}
diff --git a/include/stc/csview.h b/include/stc/csview.h
index d8bb567e..e65821bb 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -95,36 +95,36 @@ STC_INLINE csview utf8_substr(const char* str, size_t pos, size_t n) {
STC_INLINE csview csview_from_s(cstr s)
{ return c_make(csview){s.str, _cstr_rep(&s)->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_from_replace_all_v(csview sv, csview find, csview repl)
+STC_INLINE cstr cstr_from_replace_all_sv(csview sv, csview find, csview repl)
{ return cstr_from_replace_all(sv.str, sv.size, find.str, find.size,
repl.str, repl.size); }
-STC_INLINE csview cstr_to_v(const cstr* self)
+STC_INLINE csview cstr_to_sv(const cstr* self)
{ return c_make(csview){self->str, _cstr_rep(self)->size}; }
STC_INLINE csview cstr_substr(cstr s, intptr_t pos, size_t n)
{ return csview_substr(csview_from_s(s), pos, n); }
STC_INLINE csview cstr_slice(cstr s, intptr_t p1, intptr_t p2)
{ return csview_slice(csview_from_s(s), p1, p2); }
-STC_INLINE cstr* cstr_assign_v(cstr* self, csview sv)
+STC_INLINE cstr* cstr_assign_sv(cstr* self, csview sv)
{ return cstr_assign_n(self, sv.str, sv.size); }
-STC_INLINE cstr* cstr_append_v(cstr* self, csview sv)
+STC_INLINE cstr* cstr_append_sv(cstr* self, csview sv)
{ return cstr_append_n(self, sv.str, sv.size); }
-STC_INLINE void cstr_insert_v(cstr* self, size_t pos, csview sv)
+STC_INLINE void cstr_insert_sv(cstr* self, size_t pos, csview sv)
{ cstr_replace_n(self, pos, 0, sv.str, sv.size); }
-STC_INLINE void cstr_replace_v(cstr* self, csview sub, csview with)
+STC_INLINE void cstr_replace_sv(cstr* self, csview sub, csview with)
{ cstr_replace_n(self, sub.str - self->str, sub.size, with.str, with.size); }
-STC_INLINE bool cstr_equals_v(cstr s, csview sv)
+STC_INLINE bool cstr_equals_sv(cstr s, csview sv)
{ return sv.size == cstr_size(s) && !memcmp(s.str, sv.str, sv.size); }
-STC_INLINE size_t cstr_find_v(cstr s, csview needle)
+STC_INLINE size_t cstr_find_sv(cstr s, csview needle)
{ char* res = c_strnstrn(s.str, needle.str, cstr_size(s), needle.size);
return res ? res - s.str : cstr_npos; }
-STC_INLINE bool cstr_contains_v(cstr s, csview needle)
+STC_INLINE bool cstr_contains_sv(cstr s, csview needle)
{ return c_strnstrn(s.str, needle.str, cstr_size(s), needle.size) != NULL; }
-STC_INLINE bool cstr_starts_with_v(cstr s, csview sub)
+STC_INLINE bool cstr_starts_with_sv(cstr s, csview sub)
{ if (sub.size > cstr_size(s)) return false;
return !memcmp(s.str, sub.str, sub.size); }
-STC_INLINE bool cstr_ends_with_v(cstr s, csview sub)
+STC_INLINE bool cstr_ends_with_sv(cstr s, csview sub)
{ if (sub.size > cstr_size(s)) return false;
return !memcmp(s.str + cstr_size(s) - sub.size, sub.str, sub.size); }
#endif
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index a064b906..93f8461a 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -9,7 +9,7 @@ int main()
{
c_auto (cstr, s1) {
s1 = cstr_new("hell😀 w😀rld");
- cstr_replace_v(&s1, utf8_substr(s1.str, 7, 1), c_sv("x"));
+ cstr_replace_sv(&s1, utf8_substr(s1.str, 7, 1), c_sv("x"));
printf("%s\n", s1.str);
csview sv = csview_from_s(s1);