summaryrefslogtreecommitdiffhomepage
path: root/docs/csview_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-03-26 17:49:49 +0100
committerTyge Løvset <[email protected]>2022-03-26 17:49:49 +0100
commit12ce8c74e8e8c69e0d3cbcd86d91891cfbd26dfc (patch)
tree446e8cc9b2e5ad3c78acb212264dbb97fb26ce20 /docs/csview_api.md
parent920a55280a28ce38b98045f797067e285395bb6e (diff)
downloadSTC-modified-12ce8c74e8e8c69e0d3cbcd86d91891cfbd26dfc.tar.gz
STC-modified-12ce8c74e8e8c69e0d3cbcd86d91891cfbd26dfc.zip
Updated csview API docs.
Diffstat (limited to 'docs/csview_api.md')
-rw-r--r--docs/csview_api.md61
1 files changed, 30 insertions, 31 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 75e50373..988e15d1 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[]); // alias for csview_new
-csview csview_new(const char literal_only[]); // make csview from literal, no strlen()
-csview csview_from_s(cstr s); // same as cstr_sv()
-csview csview_from(const char* str); // make csview from const char*
-csview csview_from_n(const char* str, size_t n); // construct
+csview c_sv(const char literal_only[]); // alias for csview_new
+csview csview_new(const char literal_only[]); // make csview from literal, no strlen()
+csview csview_from_s(const cstr* s); // convert to csview from cstr
+csview csview_from(const char* str); // make csview from const char*
+csview csview_from_n(const char* str, size_t n); // construct
size_t csview_size(csview sv);
size_t csview_length(csview sv);
@@ -40,9 +40,9 @@ char csview_back(csview sv);
void csview_clear(csview* self);
-csview csview_substr(csview sv, intptr_t pos, size_t n); // negative pos count from end
-csview csview_slice(csview sv, intptr_t p1, intptr_t p2); // negative p1, p2 count from end
-csview csview_token(csview sv, csview sep, size_t* start); // see split example below.
+csview csview_substr(csview sv, intptr_t pos, size_t n); // negative pos count from end
+csview csview_slice(csview sv, intptr_t p1, intptr_t p2); // negative p1, p2 count from end
+csview csview_token(csview sv, csview sep, size_t* start); // see split example below.
bool csview_equals(csview sv, csview sv2);
size_t csview_find(csview sv, csview needle);
@@ -52,7 +52,7 @@ bool csview_ends_with(csview sv, csview sub);
csview_iter csview_begin(const csview* self);
csview_iter csview_end(const csview* self);
-void csview_next(csview_iter* it); // NB: UTF8 codepoint step, not byte!
+void csview_next(csview_iter* it); // NB: UTF8 codepoint step, not byte!
```
#### UTF8 methods
@@ -63,25 +63,24 @@ csview utf8_substr(const char* str, size_t pos, size_t n);
bool utf8_valid(const char* s);
size_t utf8_size(const char *s);
-size_t utf8_size_n(const char *s, size_t n); // number of UTF8 codepoints within n bytes
-const char* utf8_at(const char *s, size_t index); // from UTF8 index to char* position
-size_t utf8_pos(const char* s, size_t index); // from UTF8 index to byte index position
-const char* utf8_next(const char *s); // next codepoint as char*; NULL if *s == 0
-uint32_t utf8_peek(const char *s); // next codepoint as uint32_t
+size_t utf8_size_n(const char *s, size_t n); // number of UTF8 codepoints within n bytes
+const char* utf8_at(const char *s, size_t index); // from UTF8 index to char* position
+size_t utf8_pos(const char* s, size_t index); // from UTF8 index to byte index position
+const char* utf8_next(const char *s); // next codepoint as char*; NULL if *s == 0
+uint32_t utf8_peek(const char *s); // next codepoint as uint32_t
-size_t utf8_codep_size(const char* s); // 1-4 (0 if s[0] is illegal first cp char)
+size_t utf8_codep_size(const char* s); // 1-4 (0 if s[0] is illegal first cp char)
uint32_t utf8_decode(uint32_t *state, uint32_t *codep, const uint32_t byte); // decode next utf8 codepoint.
```
#### Extended cstr methods
```c
-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_sv(csview sv); // construct cstr from csview
+csview cstr_to_sv(const cstr* self); // convert to csview from const 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
+csview cstr_substr(const cstr* s, intptr_t pos, size_t n); // negative pos count from end
+csview cstr_slice(const cstr* s, intptr_t p, intptr_t q); // negative p or q count from end
cstr* cstr_assign_sv(cstr* self, csview sv);
cstr* cstr_append_sv(cstr* self, csview sv);
@@ -126,18 +125,18 @@ uint64_t csview_hash(const csview* x, size_t dummy);
int main ()
{
cstr str1 = cstr_new("We think in generalities, but we live in details.");
- // (quoting Alfred N. Whitehead)
+ // (quoting Alfred N. Whitehead)
- csview sv1 = cstr_substr(str1, 3, 5); // "think"
- size_t pos = cstr_find(str1, "live"); // position of "live" in str1
- csview sv2 = cstr_substr(str1, pos, 4); // get "live"
- csview sv3 = cstr_slice(str1, -8, -1); // get "details"
+ csview sv1 = cstr_substr(&str1, 3, 5); // "think"
+ size_t pos = cstr_find(str1, "live"); // position of "live" in str1
+ csview sv2 = cstr_substr(&str1, pos, 4); // get "live"
+ csview sv3 = cstr_slice(&str1, -8, -1); // get "details"
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_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);
+ 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", cstr_str(&s2), cstr_str(&s3));
c_drop(cstr, &str1, &s1, &s2, &s3);
}
@@ -157,10 +156,10 @@ int main()
{
c_auto (cstr, s1) {
s1 = cstr_new("hell😀 w😀rld");
- cstr_replace_sv(&s1, utf8_substr(s1.str, 7, 1), c_sv("x"));
- printf("%s\n", s1.str);
+ cstr_replace_sv(&s1, utf8_substr(cstr_str(&s1), 7, 1), c_sv("x"));
+ printf("%s\n", cstr_str(&s1));
- csview sv = csview_from_s(s1);
+ csview sv = csview_from_s(&s1);
c_foreach (i, csview, sv)
printf(c_PRIsv ",", c_ARGsv(i.cp));
}