diff options
| author | Tyge Løvset <[email protected]> | 2022-04-18 00:44:51 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-18 00:44:51 +0200 |
| commit | 00804d9ff488f63468a0bb528c7b807aea7c3ea3 (patch) | |
| tree | 51b47787adc853bd1a10ec820a6ef5c184fa2498 /examples/box.c | |
| parent | 4436a1c0ac37dc2e73a2134d5ad85c010340b35d (diff) | |
| download | STC-modified-00804d9ff488f63468a0bb528c7b807aea7c3ea3.tar.gz STC-modified-00804d9ff488f63468a0bb528c7b807aea7c3ea3.zip | |
Converted all example to use cstr_str(&s) instead of s.str to allow SSO string. Fixed misc warnings.
Diffstat (limited to 'examples/box.c')
| -rw-r--r-- | examples/box.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/box.c b/examples/box.c index 00a092e2..d2d98218 100644 --- a/examples/box.c +++ b/examples/box.c @@ -8,8 +8,8 @@ Person Person_new(const char* name, const char* last) { }
int Person_cmp(const Person* a, const Person* b) {
- int c = strcmp(a->name.str, b->name.str);
- return c ? c : strcmp(a->last.str, b->last.str);
+ int c = cstr_cmp(&a->name, &b->name);
+ return c ? c : cstr_cmp(&a->last, &b->last);
}
Person Person_clone(Person p) {
@@ -19,7 +19,7 @@ Person Person_clone(Person p) { }
void Person_drop(Person* p) {
- printf("drop: %s %s\n", p->name.str, p->last.str);
+ printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->last));
c_drop(cstr, &p->name, &p->last);
}
@@ -41,8 +41,8 @@ int main() q = PBox_clone(p);
cstr_assign(&q.get->name, "Leland");
- printf("orig: %s %s\n", p.get->name.str, p.get->last.str);
- printf("copy: %s %s\n", q.get->name.str, q.get->last.str);
+ printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last));
+ printf("copy: %s %s\n", cstr_str(&q.get->name), cstr_str(&q.get->last));
Persons_push_back(&vec, PBox_from(Person_new("Dale", "Cooper")));
Persons_push_back(&vec, PBox_from(Person_new("Audrey", "Home")));
@@ -51,19 +51,19 @@ int main() c_apply(v, Persons_push_back(&vec, PBox_clone(v)), PBox, {p, q});
c_foreach (i, Persons, vec)
- printf("%s %s\n", i.ref->get->name.str, i.ref->get->last.str);
+ printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last));
puts("");
// Look-up Audrey! Use a (fake) temporary PBox for lookup.
c_autovar (Person a = Person_new("Audrey", "Home"), Person_drop(&a)) {
const PBox *v = Persons_get(&vec, a);
- if (v) printf("found: %s %s\n", v->get->name.str, v->get->last.str);
+ if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last));
}
puts("");
// Alternative to use cbox (when not placed in container).
Person *she = c_new(Person, Person_new("Shelly", "Johnson"));
- printf("%s %s\n", she->name.str, she->last.str);
+ printf("%s %s\n", cstr_str(&she->name), cstr_str(&she->last));
c_delete(Person, she); // drop and free
puts("");
}
|
