diff options
| author | Tyge Løvset <[email protected]> | 2022-04-24 23:53:56 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-24 23:53:56 +0200 |
| commit | 1ebbd367675a4a25c82b27da75301846fa315f4c (patch) | |
| tree | 53c2947afaac64ac6505d45bd577a9843241f029 | |
| parent | 81b541b85f85b48660ceb461b851f1fb09d68344 (diff) | |
| download | STC-modified-1ebbd367675a4a25c82b27da75301846fa315f4c.tar.gz STC-modified-1ebbd367675a4a25c82b27da75301846fa315f4c.zip | |
Updated docs to use cstr_str(&s) instead of s.str
| -rw-r--r-- | benchmarks/misc/string_bench_STC.cpp | 10 | ||||
| -rw-r--r-- | docs/carc_api.md | 4 | ||||
| -rw-r--r-- | docs/ccommon_api.md | 12 | ||||
| -rw-r--r-- | docs/cmap_api.md | 12 | ||||
| -rw-r--r-- | docs/crandom_api.md | 2 | ||||
| -rw-r--r-- | docs/cset_api.md | 6 | ||||
| -rw-r--r-- | docs/csmap_api.md | 4 | ||||
| -rw-r--r-- | docs/csset_api.md | 6 | ||||
| -rw-r--r-- | docs/cstr_api.md | 18 | ||||
| -rw-r--r-- | docs/csview_api.md | 2 | ||||
| -rw-r--r-- | docs/cvec_api.md | 8 |
11 files changed, 42 insertions, 42 deletions
diff --git a/benchmarks/misc/string_bench_STC.cpp b/benchmarks/misc/string_bench_STC.cpp index ed0e3243..d5b3a306 100644 --- a/benchmarks/misc/string_bench_STC.cpp +++ b/benchmarks/misc/string_bench_STC.cpp @@ -69,7 +69,7 @@ void initShortStringVec(cvec_str* vs, cvec_sv* vsv) cvec_str_clear(vs); cvec_sv_clear(vsv); - *vs = read_file("names.txt"); + cvec_str_copy(vs, read_file("names.txt")); /* cvec_str_emplace_back(vs, "Susan"); cvec_str_emplace_back(vs, "Jason"); @@ -110,11 +110,11 @@ void initLongStringVec(cvec_str* vs, cvec_sv* vsv) cvec_str_clear(vs); cvec_sv_clear(vsv); - *vs = read_file("names.txt"); + cvec_str_copy(vs, read_file("names.txt")); c_foreach (i, cvec_str, *vs) { - cstr_append_s(i.ref, *i.ref); - cstr_append_s(i.ref, *i.ref); - cstr_append_s(i.ref, *i.ref); + cstr_append_s(i.ref, *i.ref); + cstr_append_s(i.ref, *i.ref); + cstr_append_s(i.ref, *i.ref); } /* cvec_str_emplace_back(vs, "Susan Susan Susan Susan Susan Susan"); diff --git a/docs/carc_api.md b/docs/carc_api.md index 90aec0ed..3f5675f0 100644 --- a/docs/carc_api.md +++ b/docs/carc_api.md @@ -135,14 +135,14 @@ int main() puts("STACKS"); c_foreach (i, Stack, stack) { c_forpair (name, year, Map, *i.ref->get) - printf(" %s:%d", _.name.str, _.year); + printf(" %s:%d", cstr_str(&_.name), _.year); puts(""); } puts("LIST"); c_foreach (i, List, list) { c_forpair (name, year, Map, *i.ref->get) - printf(" %s:%d", _.name.str, _.year); + printf(" %s:%d", cstr_str(&_.name), _.year); puts(""); } } diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index e7949b25..64c1f5fe 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -31,7 +31,7 @@ c_autovar (FILE* f = fopen(fname, "rb"), fclose(f)) c_autovar (cstr s = cstr_new("Hello"), cstr_drop(&s)) { cstr_append(&s, " world"); - printf("%s\n", s.str); + printf("%s\n", cstr_str(&s)); } c_auto (cstr, s1, s2) @@ -42,19 +42,19 @@ c_auto (cstr, s1, s2) cstr_append(&s2, "Cool"); cstr_append(&s2, " stuff"); - printf("%s %s\n", s1.str, s2.str); + printf("%s %s\n", cstr_str(&s1), cstr_str(&s2)); } MyData data; c_autoscope (mydata_init(&data), mydata_destroy(&data)) { - printf("%s\n", mydata.name.str); + printf("%s\n", cstr_str(&mydata.name)); } cstr s1 = cstr_new("Hello"), s2 = cstr_new("world"); c_autodefer (cstr_drop(&s1), cstr_drop(&s2)) { - printf("%s %s\n", s1.str, s2.str); + printf("%s %s\n", cstr_str(&s1), cstr_str(&s2)); } ``` **Example**: Load each line of a text file into a vector of strings: @@ -73,7 +73,7 @@ cvec_str readFile(const char* name) c_autovar (FILE* fp = fopen(name, "r"), fclose(fp)) c_autovar (cstr line = cstr_null, cstr_drop(&line)) while (cstr_getline(&line, fp)) - cvec_str_emplace_back(&vec, line.str); + cvec_str_emplace_back(&vec, cstr_str(&line)); return vec; } @@ -81,7 +81,7 @@ int main() { c_autovar (cvec_str x = readFile(__FILE__), cvec_str_drop(&x)) c_foreach (i, cvec_str, x) - printf("%s\n", i.ref->str); + printf("%s\n", cstr_str(i.ref)); } ``` ### The checkauto utility program (for RAII) diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 07f1c140..b3da23c2 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -131,7 +131,7 @@ int main() // Iterate and print keys and values of unordered map c_foreach (n, cmap_str, u) { - printf("Key:[%s] Value:[%s]\n", n.ref->first.str, n.ref->second.str); + printf("Key:[%s] Value:[%s]\n", cstr_str(&n.ref->first), cstr_str(&n.ref->second)); } // Add two new entries to the unordered map @@ -182,7 +182,7 @@ int main() cmap_id_emplace(&idnames, 100, "Green"); c_foreach (i, cmap_id, idnames) - printf("%d: %s\n", i.ref->first, i.ref->second.str); + printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second)); } } ``` @@ -279,7 +279,7 @@ static inline int Viking_cmp(const Viking* a, const Viking* b) { } static inline uint32_t Viking_hash(const Viking* a, int ignored) { - return c_strhash(a->name.str) ^ (c_strhash(a->country.str) >> 15); + return c_strhash(cstr_str(&a->name)) ^ (c_strhash(cstr_str(&a->country)) >> 15); } static inline Viking Viking_clone(Viking v) { @@ -319,7 +319,7 @@ int main() // Print the status of the vikings. c_forpair (viking, hp, Vikings, vikings) { - printf("%s of %s has %d hp\n", _.viking.name.str, _.viking.country.str, _.hp); + printf("%s of %s has %d hp\n", cstr_str(&_.viking.name), cstr_str(&_.viking.country), _.hp); } } } @@ -369,7 +369,7 @@ static inline Viking Viking_from(RViking raw) { return (Viking){cstr_from(raw.name), cstr_from(raw.country)}; } static inline RViking Viking_toraw(const Viking* vk) { - return (RViking){vk->name.str, vk->country.str}; + return (RViking){cstr_str(&vk->name), cstr_str(&vk->country)}; } // With this in place, we define the Viking => int hash map type: @@ -399,7 +399,7 @@ int main() if (v) v->second += 3; // add 3 hp points to Einar c_forpair (viking, health, Vikings, vikings) { - printf("%s of %s has %d hp\n", _.viking.name.str, _.viking.country.str, _.health); + printf("%s of %s has %d hp\n", cstr_str(&_.viking.name), cstr_str(&_.viking.country), _.health); } } } diff --git a/docs/crandom_api.md b/docs/crandom_api.md index 76b2379e..3e6ae8f0 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -105,7 +105,7 @@ int main() size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / N); if (n > 0) { cstr_resize(&bar, n, '*'); - printf("%4d %s\n", i.ref->first, bar.str); + printf("%4d %s\n", i.ref->first, cstr_str(&bar)); } } // Cleanup diff --git a/docs/cset_api.md b/docs/cset_api.md index d9b412da..a5067b3b 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -97,13 +97,13 @@ int main () fifth = cset_str_clone(second);
c_foreach (i, cset_str, third)
- cset_str_emplace(&fifth, i.ref->str);
+ cset_str_emplace(&fifth, cstr_str(i.ref));
c_foreach (i, cset_str, fourth)
- cset_str_emplace(&fifth, i.ref->str);
+ cset_str_emplace(&fifth, cstr_str(i.ref));
}
printf("fifth contains:\n\n");
c_foreach (i, cset_str, fifth)
- printf("%s\n", i.ref->str);
+ printf("%s\n", cstr_str(i.ref));
}
}
```
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index ab9eb2ee..d4d9e755 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -113,7 +113,7 @@ int main() // Iterate and print keys and values of sorted map c_foreach (i, csmap_str, colors) { - printf("Key:[%s] Value:[%s]\n", i.ref->first.str, i.ref->second.str); + printf("Key:[%s] Value:[%s]\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second)); } // Add two new entries to the sorted map @@ -163,7 +163,7 @@ int main() csmap_id_emplace(&idnames, 100, "Green"); c_foreach (i, csmap_id, idnames) - printf("%d: %s\n", i.ref->first, i.ref->second.str); + printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second)); } } ``` diff --git a/docs/csset_api.md b/docs/csset_api.md index 57d23ee6..d2635f81 100644 --- a/docs/csset_api.md +++ b/docs/csset_api.md @@ -93,13 +93,13 @@ c_auto (csset_str, fifth) fifth = csset_str_clone(second);
c_foreach (i, csset_str, third)
- csset_str_emplace(&fifth, i.ref->str);
+ csset_str_emplace(&fifth, cstr_str(i.ref));
c_foreach (i, csset_str, fourth)
- csset_str_emplace(&fifth, i.ref->str);
+ csset_str_emplace(&fifth, cstr_str(i.ref));
}
printf("fifth contains:\n\n");
c_foreach (i, csset_str, fifth)
- printf("%s\n", i.ref->str);
+ printf("%s\n", cstr_str(i.ref));
}
}
```
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 85a872fe..5005c6f7 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -29,8 +29,8 @@ cstr* cstr_take(cstr* self, cstr s); // take th cstr cstr_move(cstr* self); // move string to caller, leave empty string void cstr_drop(cstr *self); // destructor -const char* cstr_str(const cstr* self); // self->str -char* cstr_data(cstr* self); // self->str +const char* cstr_str(const cstr* self); // access to const char* +char* cstr_data(cstr* self); // access to char* size_t cstr_size(cstr s); size_t cstr_length(cstr s); size_t cstr_capacity(cstr s); @@ -110,27 +110,27 @@ int c_strncasecmp(const char* str1, const char* str2, size_t n); int main() { cstr s0 = cstr_new("Initialization without using strlen()."); - printf("%s\nLength: %" PRIuMAX "\n\n", s0.str, cstr_size(s0)); + printf("%s\nLength: %" PRIuMAX "\n\n", cstr_str(&s0), cstr_size(s0)); cstr s1 = cstr_new("one-nine-three-seven-five."); - printf("%s\n", s1.str); + printf("%s\n", cstr_str(&s1)); cstr_insert(&s1, 3, "-two"); - printf("%s\n", s1.str); + printf("%s\n", cstr_str(&s1)); cstr_erase_n(&s1, 7, 5); // -nine - printf("%s\n", s1.str); + printf("%s\n", cstr_str(&s1)); cstr_replace(&s1, cstr_find(s1, "seven"), 5, "four"); - printf("%s\n", s1.str); + printf("%s\n", cstr_str(&s1)); // reassign: cstr_assign(&s1, "one two three four five six seven"); cstr_append(&s1, " eight"); - printf("append: %s\n", s1.str); + printf("append: %s\n", cstr_str(&s1)); cstr full_path = cstr_from_fmt("%s/%s.%s", "directory", "filename", "ext"); - printf("%s\n", full_path.str); + printf("%s\n", cstr_str(&full_path)); c_drop(cstr, &s0, &s1, &full_path); } diff --git a/docs/csview_api.md b/docs/csview_api.md index 5211e2f6..57aa0d55 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -212,7 +212,7 @@ int main() c_autovar (cvec_str v = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cvec_str_drop(&v)) c_foreach (i, cvec_str, v) - printf("[%s]\n", i.ref->str); + printf("[%s]\n", cstr_str(i.ref)); } ``` Output: diff --git a/docs/cvec_api.md b/docs/cvec_api.md index e02a944e..f5dd11ae 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -161,10 +161,10 @@ int main() { // emplace() will not compile if adding a new cstr type. Use push_back(): cvec_str_push(&names, tmp); // tmp is moved to names, do not drop() it. - printf("%s\n", names.data[1].str); // Access the second element + printf("%s\n", cstr_str(&names.data[1])); // Access the second element c_foreach (i, cvec_str, names) - printf("item: %s\n", i.ref->str); + printf("item: %s\n", cstr_str(i.ref)); cvec_str_drop(&names); } ``` @@ -187,7 +187,7 @@ typedef struct { } User; int User_cmp(const User* a, const User* b) { - int c = strcmp(a->name.str, b->name.str); + int c = strcmp(cstr_str(&a->name), cstr_str(&b->name)); return c != 0 ? c : a->id - b->id; } void User_drop(User* self) { @@ -214,7 +214,7 @@ int main(void) { cvec_u vec2 = cvec_u_clone(vec); c_foreach (i, cvec_u, vec2) - printf("%s: %d\n", i.ref->name.str, i.ref->id); + printf("%s: %d\n", cstr_str(&i.ref->name), i.ref->id); c_drop(cvec_u, &vec, &vec2); // cleanup } |
