diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/README.md | 2 | ||||
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/complex.c | 2 | ||||
| -rw-r--r-- | examples/demos.c | 6 | ||||
| -rw-r--r-- | examples/inits.c | 6 | ||||
| -rw-r--r-- | examples/phonebook.c | 4 | ||||
| -rw-r--r-- | examples/ptr.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 2 | ||||
| -rw-r--r-- | examples/share_ptr.c | 8 | ||||
| -rw-r--r-- | examples/share_ptr2.c | 6 | ||||
| -rw-r--r-- | examples/words.c | 2 |
11 files changed, 21 insertions, 21 deletions
diff --git a/examples/README.md b/examples/README.md index ba6a7cfb..4c24d32a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -47,7 +47,7 @@ static inline VikingRaw viking_toRaw(Viking* vk) { VikingRaw vw = {vk->name.str, vk->country.str}; return vw;
}
static inline Viking viking_fromRaw(VikingRaw vw) { // note: parameter is by value
- Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
+ Viking vk = {cstr_from(vw.name), cstr_from(vw.country)}; return vk;
}
```
With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type:
diff --git a/examples/advanced.c b/examples/advanced.c index 8c3564f3..e9e0002b 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -47,7 +47,7 @@ VikingVw viking_toVw(Viking* vk) { VikingVw vw = {vk->name.str, vk->country.str}; return vw; } Viking viking_fromVw(VikingVw vw) { - Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk; + Viking vk = {cstr_from(vw.name), cstr_from(vw.country)}; return vk; } // Using the full using_cmap() macro to define [Viking -> int] hash map type: diff --git a/examples/complex.c b/examples/complex.c index 7cde293c..c9704d73 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -17,7 +17,7 @@ int main() { cmap_s myMap = cmap_INIT;
{ // Construct.
- carray2f table = carray2f_make(ydim, xdim, 0.f);
+ carray2f table = carray2f_init(ydim, xdim, 0.f);
printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table));
clist_y tableList = clist_INIT;
// Put in some data.
diff --git a/examples/demos.c b/examples/demos.c index 1955d229..18b0f1ef 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -8,7 +8,7 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- cstr_t cs = cstr("one-nine-three-seven-five");
+ cstr_t cs = cstr_from("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
@@ -20,7 +20,7 @@ void stringdemo1() cstr_replace(&cs, cstr_find(&cs, "seven"), 5, "four");
printf("%s.\n", cs.str);
- cstr_take(&cs, cstr_from("%s *** %s", cs.str, cs.str));
+ cstr_take(&cs, cstr_from_fmt("%s *** %s", cs.str, cs.str));
printf("%s.\n", cs.str);
printf("find \"four\": %s\n", cs.str + cstr_find(&cs, "four"));
@@ -177,7 +177,7 @@ using_carray(f, float); void arraydemo1()
{
printf("\nARRAYDEMO1\n");
- carray3f a3 = carray3f_make(30, 20, 10, 0.0f);
+ carray3f a3 = carray3f_init(30, 20, 10, 0.0f);
*carray3f_at(&a3, 5, 4, 3) = 10.2f; // a3[5][4][3]
carray2f a2 = carray3f_at1(&a3, 5); // sub-array reference: a2 = a3[5]
carray1f a1 = carray3f_at2(&a3, 5, 4); // sub-array reference: a1 = a3[5][4]
diff --git a/examples/inits.c b/examples/inits.c index ea4c61bc..3565c189 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -47,9 +47,9 @@ int main(void) int year = 2020;
cmap_id idnames = cmap_INIT;
c_push_items(&idnames, cmap_id, {
- {100, cstr("Hello")},
- {110, cstr("World")},
- {120, cstr_from("Howdy, -%d-", year)},
+ {100, cstr_from("Hello")},
+ {110, cstr_from("World")},
+ {120, cstr_from_fmt("Howdy, -%d-", year)},
});
c_foreach (i, cmap_id, idnames)
diff --git a/examples/phonebook.c b/examples/phonebook.c index cb7130c1..c7a02e74 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -47,8 +47,8 @@ int main(int argc, char **argv) printf("Phone book:\n");
print_phone_book(phone_book);
- c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1880"));
- c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1990"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_from("(551) 396-1880"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_from("(551) 396-1990"));
printf("\nPhone book after adding Zak Byers:\n");
print_phone_book(phone_book);
diff --git a/examples/ptr.c b/examples/ptr.c index dc0e5341..3ffb9292 100644 --- a/examples/ptr.c +++ b/examples/ptr.c @@ -5,7 +5,7 @@ typedef struct { cstr_t name, last; } Person;
Person* Person_make(Person* p, const char* name, const char* last) {
- p->name = cstr(name), p->last = cstr(last);
+ p->name = cstr_from(name), p->last = cstr_from(last);
return p;
}
void Person_del(Person* p) {
diff --git a/examples/replace.c b/examples/replace.c index 5c5192e2..53e916fc 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -11,7 +11,7 @@ int main () // replace signatures used in the same order as described above:
// Ustring positions: 0123456789*123456789*12345
- cstr_t s = cstr(base); // "this is a test string."
+ cstr_t s = cstr_from(base); // "this is a test string."
cstr_t m = cstr_clone(s);
cstr_append(&m, m.str);
diff --git a/examples/share_ptr.c b/examples/share_ptr.c index 28f1975c..5dd52d19 100644 --- a/examples/share_ptr.c +++ b/examples/share_ptr.c @@ -7,7 +7,7 @@ typedef struct { cstr_t name, last; } Person;
Person* Person_make(Person* p, const char* name, const char* last) {
- p->name = cstr(name), p->last = cstr(last);
+ p->name = cstr_from(name), p->last = cstr_from(last);
return p;
}
void Person_del(Person* p) {
@@ -27,15 +27,15 @@ int main() { clist_pe queue = clist_pe_init();
cvec_pe vec = cvec_pe_init();
- csptr_pe joe = csptr_pe_make((Person) {cstr("Joe"), cstr("Jordan")});
+ csptr_pe joe = csptr_pe_make((Person) {cstr_from("Joe"), cstr_from("Jordan")});
clist_pe_push_back(&queue, csptr_pe_share(joe));
cvec_pe_push_back(&vec, csptr_pe_share(joe));
puts("Push 10:");
c_forrange (i, 10) {
csptr_pe p = csptr_pe_from(c_new(Person));
- p.get->name = cstr_from("Name %d", (i * 7) % 10);
- p.get->last = cstr_from("Last %d", (i * 7) % 10);
+ p.get->name = cstr_from_fmt("Name %d", (i * 7) % 10);
+ p.get->last = cstr_from_fmt("Last %d", (i * 7) % 10);
clist_pe_push_back(&queue, p);
cvec_pe_push_back(&vec, csptr_pe_share(p)); // Don't forget to share!
}
diff --git a/examples/share_ptr2.c b/examples/share_ptr2.c index 4c589ad1..d4b536ac 100644 --- a/examples/share_ptr2.c +++ b/examples/share_ptr2.c @@ -11,7 +11,7 @@ Person* Person_from(Person* p, cstr_t name, cstr_t last) { return p;
}
Person* Person_make(Person* p, const char* name, const char* last) {
- p->name = cstr(name), p->last = cstr(last);
+ p->name = cstr_from(name), p->last = cstr_from(last);
return p;
}
void Person_del(Person* p) {
@@ -30,8 +30,8 @@ int main() { // c_try_emplace: The last argument is completely ignored if key already exist in map, so no memory leak happens!
c_forrange (i, 20) { // When i>9, all key will exist, so value arg is not executed.
c_try_emplace(&map, cmap_pe, (i * 7) % 10,
- csptr_pe_from(Person_from(c_new(Person), cstr_from("Name %d", (i * 7) % 10),
- cstr_from("Last %d", (i * 9) % 10))));
+ csptr_pe_from(Person_from(c_new(Person), cstr_from_fmt("Name %d", (i * 7) % 10),
+ cstr_from_fmt("Last %d", (i * 9) % 10))));
}
c_try_emplace(&map, cmap_pe, 11, csptr_pe_from(Person_make(c_new(Person), "Hello", "World!")));
diff --git a/examples/words.c b/examples/words.c index f95c36eb..fb8b9b8c 100644 --- a/examples/words.c +++ b/examples/words.c @@ -16,7 +16,7 @@ int main1() "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" }); - clist_str_push_back(&lwords, cstr_from("%f", 123897.0 / 23.0)); + clist_str_push_back(&lwords, cstr_from_fmt("%f", 123897.0 / 23.0)); c_foreach (w, clist_str, lwords) printf("%s\n", w.val->str); puts(""); |
