summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-18 00:44:51 +0200
committerTyge Løvset <[email protected]>2022-04-18 00:44:51 +0200
commit00804d9ff488f63468a0bb528c7b807aea7c3ea3 (patch)
tree51b47787adc853bd1a10ec820a6ef5c184fa2498 /examples
parent4436a1c0ac37dc2e73a2134d5ad85c010340b35d (diff)
downloadSTC-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')
-rw-r--r--examples/arc_containers.c6
-rw-r--r--examples/astar.c6
-rw-r--r--examples/books.c6
-rw-r--r--examples/box.c16
-rw-r--r--examples/convert.c14
-rw-r--r--examples/csmap_erase.c2
-rw-r--r--examples/csmap_insert.c2
-rw-r--r--examples/cstr_match.c2
-rw-r--r--examples/demos.c30
-rw-r--r--examples/ex_gauss1.c2
-rw-r--r--examples/ex_gauss2.c2
-rw-r--r--examples/hashmap.c6
-rw-r--r--examples/inits.c4
-rw-r--r--examples/make.sh3
-rw-r--r--examples/mapmap.c4
-rw-r--r--examples/mmap.c2
-rw-r--r--examples/multimap.c9
-rw-r--r--examples/music_arc.c7
-rw-r--r--examples/new_arr.c2
-rw-r--r--examples/new_map.c2
-rw-r--r--examples/new_pque.c2
-rw-r--r--examples/new_smap.c2
-rw-r--r--examples/new_sptr.c4
-rw-r--r--examples/person_arc.c14
-rw-r--r--examples/phonebook.c4
-rw-r--r--examples/rawptr_elements.c2
-rw-r--r--examples/regex1.c4
-rw-r--r--examples/replace.c20
-rw-r--r--examples/splitstr.c2
-rw-r--r--examples/sview_split.c2
-rw-r--r--examples/unordered_set.c2
-rw-r--r--examples/utf8replace_c.c6
-rw-r--r--examples/vikings.c4
-rw-r--r--examples/words.c4
34 files changed, 101 insertions, 98 deletions
diff --git a/examples/arc_containers.c b/examples/arc_containers.c
index ea9395e8..53297270 100644
--- a/examples/arc_containers.c
+++ b/examples/arc_containers.c
@@ -3,7 +3,7 @@
#define i_type Map
#define i_key_str // strings
#define i_val int
-#define i_keydrop(p) (printf("drop name: %s\n", (p)->str), cstr_drop(p))
+#define i_keydrop(p) (printf("drop name: %s\n", cstr_str(p)), cstr_drop(p))
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted type
@@ -62,13 +62,13 @@ 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/examples/astar.c b/examples/astar.c
index ee002b79..bce03716 100644
--- a/examples/astar.c
+++ b/examples/astar.c
@@ -105,7 +105,7 @@ astar(cstr* maze, int width)
point delta = deltas[i];
point next = point_init(current.x + delta.x, current.y + delta.y, width);
int new_cost = *csmap_pcost_at(&costs, current);
- if (maze->str[point_index(&next)] != '#')
+ if (cstr_str(maze)[point_index(&next)] != '#')
{
const csmap_pcost_value *cost = csmap_pcost_get(&costs, next);
if (cost == NULL || new_cost < cost->second)
@@ -160,8 +160,8 @@ main(void)
int width = cstr_find(maze, "\n") + 1;
c_autovar (cdeq_point path = astar(&maze, width), cdeq_point_drop(&path))
{
- c_foreach (it, cdeq_point, path) maze.str[point_index(it.ref)] = 'x';
- printf("%s", maze.str);
+ c_foreach (it, cdeq_point, path) cstr_data(&maze)[point_index(it.ref)] = 'x';
+ printf("%s", cstr_str(&maze));
}
}
}
diff --git a/examples/books.c b/examples/books.c
index 10b5c416..b35f5b36 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -44,17 +44,17 @@ int main()
c_forrange (i, c_arraylen(to_find)) {
const cmap_str_value* b;
if ((b = cmap_str_get(&book_reviews, to_find[i])))
- printf("%s: %s\n", b->first.str, b->second.str);
+ printf("%s: %s\n", cstr_str(&b->first), cstr_str(&b->second));
else
printf("%s is unreviewed.\n", to_find[i]);
}
// Look up the value for a key (will panic if the key is not found).
- printf("Review for Jane: %s\n", cmap_str_at(&book_reviews, "Pride and Prejudice")->str);
+ printf("Review for Jane: %s\n", cstr_str(cmap_str_at(&book_reviews, "Pride and Prejudice")));
// Iterate over everything.
c_forpair (book, review, cmap_str, book_reviews) {
- printf("%s: \"%s\"\n", _.book.str, _.review.str);
+ printf("%s: \"%s\"\n", cstr_str(&_.book), cstr_str(&_.review));
}
}
}
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("");
}
diff --git a/examples/convert.c b/examples/convert.c
index 8258e1b6..a17e41f6 100644
--- a/examples/convert.c
+++ b/examples/convert.c
@@ -23,26 +23,26 @@ int main()
});
puts("MAP:");
c_foreach (i, cmap_str, map)
- printf(" %s: %s\n", i.ref->first.str, i.ref->second.str);
+ printf(" %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
puts("\nCLONE MAP:");
mclone = cmap_str_clone(map);
c_foreach (i, cmap_str, mclone)
- printf(" %s: %s\n", i.ref->first.str, i.ref->second.str);
+ printf(" %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
puts("\nCOPY MAP TO VECS:");
c_foreach (i, cmap_str, mclone) {
- cvec_str_emplace_back(&keys, i.ref->first.str);
- cvec_str_emplace_back(&values, i.ref->second.str);
+ cvec_str_emplace_back(&keys, cstr_str(&i.ref->first));
+ cvec_str_emplace_back(&values, cstr_str(&i.ref->second));
}
c_forrange (i, cvec_str_size(keys))
- printf(" %s: %s\n", keys.data[i].str, values.data[i].str);
+ printf(" %s: %s\n", cstr_str(keys.data + i), cstr_str(values.data + i));
puts("\nCOPY VEC TO LIST:");
c_foreach (i, cvec_str, keys)
- clist_str_emplace_back(&list, i.ref->str);
+ clist_str_emplace_back(&list, cstr_str(i.ref));
c_foreach (i, clist_str, list)
- printf(" %s\n", i.ref->str);
+ printf(" %s\n", cstr_str(i.ref));
}
}
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c
index 2716ad8f..09d28d78 100644
--- a/examples/csmap_erase.c
+++ b/examples/csmap_erase.c
@@ -11,7 +11,7 @@
void printmap(mymap m)
{
c_foreach (elem, mymap, m)
- printf(" [%d, %s]", elem.ref->first, elem.ref->second.str);
+ printf(" [%d, %s]", elem.ref->first, cstr_str(&elem.ref->second));
printf("\nsize() == %" PRIuMAX "\n\n", mymap_size(m));
}
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c
index 11217de5..07fba9ed 100644
--- a/examples/csmap_insert.c
+++ b/examples/csmap_insert.c
@@ -27,7 +27,7 @@ void print_ii(csmap_ii map) {
void print_istr(csmap_istr map) {
c_foreach (e, csmap_istr, map)
- printf("(%d, %s) ", e.ref->first, e.ref->second.str);
+ printf("(%d, %s) ", e.ref->first, cstr_str(&e.ref->second));
puts("");
}
diff --git a/examples/cstr_match.c b/examples/cstr_match.c
index 057334f6..08236a0d 100644
--- a/examples/cstr_match.c
+++ b/examples/cstr_match.c
@@ -5,7 +5,7 @@ int main()
{
c_autovar (cstr ss = cstr_new("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) {
size_t pos = cstr_find_n(ss, "brown", 0, 5);
- printf("%" PRIuMAX " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
+ printf("%" PRIuMAX " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : cstr_str(&ss) + pos);
printf("equals: %d\n", cstr_equals(ss, "The quick brown fox jumps over the lazy dog.JPG"));
printf("contains: %d\n", cstr_contains(ss, "umps ove"));
printf("starts_with: %d\n", cstr_starts_with(ss, "The quick brown"));
diff --git a/examples/demos.c b/examples/demos.c
index e91be28a..022735a5 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -5,26 +5,26 @@ void stringdemo1()
printf("\nSTRINGDEMO1\n");
c_autovar (cstr cs = cstr_new("one-nine-three-seven-five"), cstr_drop(&cs))
{
- printf("%s.\n", cs.str);
+ printf("%s.\n", cstr_str(&cs));
cstr_insert(&cs, 3, "-two");
- printf("%s.\n", cs.str);
+ printf("%s.\n", cstr_str(&cs));
cstr_erase_n(&cs, 7, 5); // -nine
- printf("%s.\n", cs.str);
+ printf("%s.\n", cstr_str(&cs));
cstr_replace(&cs, cstr_find(cs, "seven"), 5, "four");
- printf("%s.\n", cs.str);
+ printf("%s.\n", cstr_str(&cs));
- cstr_take(&cs, cstr_from_fmt("%s *** %s", cs.str, cs.str));
- printf("%s.\n", cs.str);
+ cstr_take(&cs, cstr_from_fmt("%s *** %s", cstr_str(&cs), cstr_str(&cs)));
+ printf("%s.\n", cstr_str(&cs));
- printf("find \"four\": %s\n", cs.str + cstr_find(cs, "four"));
+ printf("find \"four\": %s\n", cstr_str(&cs) + cstr_find(cs, "four"));
// reassign:
cstr_assign(&cs, "one two three four five six seven");
cstr_append(&cs, " eight");
- printf("append: %s\n", cs.str);
+ printf("append: %s\n", cstr_str(&cs));
}
}
@@ -64,11 +64,11 @@ void vectordemo2()
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
cstr_assign(&names.data[1], "Jane"); // replace Joe
- printf("names[1]: %s\n", names.data[1].str);
+ printf("names[1]: %s\n", cstr_str(&names.data[1]));
cvec_str_sort(&names); // Sort the array
c_foreach (i, cvec_str, names)
- printf("sorted: %s\n", i.ref->str);
+ printf("sorted: %s\n", cstr_str(i.ref));
}
}
@@ -152,11 +152,11 @@ void mapdemo2()
// iterate the map:
for (cmap_si_iter i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
- printf("long: %s: %d\n", i.ref->first.str, i.ref->second);
+ printf("long: %s: %d\n", cstr_str(&i.ref->first), i.ref->second);
// or rather use the short form:
c_foreach (i, cmap_si, nums)
- printf("short: %s: %d\n", i.ref->first.str, i.ref->second);
+ printf("short: %s: %d\n", cstr_str(&i.ref->first), i.ref->second);
}
}
@@ -173,14 +173,14 @@ void mapdemo3()
cmap_str_emplace(&table, "Sunny", "day");
cmap_str_iter it = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
- printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(table), it.ref->second.str);
+ printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
+ printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(table), cstr_str(&it.ref->second));
//cmap_str_erase(&table, "Make");
cmap_str_erase_at(&table, it);
printf("size %" PRIuMAX "\n", cmap_str_size(table));
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
+ printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
cmap_str_drop(&table); // frees key and value cstrs, and hash table.
}
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c
index 8a39732a..63a4b45e 100644
--- a/examples/ex_gauss1.c
+++ b/examples/ex_gauss1.c
@@ -54,7 +54,7 @@ int main()
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)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));
}
}
}
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c
index 702c8ff3..f2f11a4a 100644
--- a/examples/ex_gauss2.c
+++ b/examples/ex_gauss2.c
@@ -34,7 +34,7 @@ int main()
size_t n = (size_t) (_.count * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
cstr_resize(&bar, n, '*');
- printf("%4d %s\n", _.index, bar.str);
+ printf("%4d %s\n", _.index, cstr_str(&bar));
}
}
}
diff --git a/examples/hashmap.c b/examples/hashmap.c
index c3e9afce..e81a0405 100644
--- a/examples/hashmap.c
+++ b/examples/hashmap.c
@@ -26,14 +26,14 @@ int main(void) {
const cmap_str_value* v;
if ((v = cmap_str_get(&contacts, "Daniel")))
- printf("Calling Daniel: %s\n", call(v->second.str));
+ printf("Calling Daniel: %s\n", call(cstr_str(&v->second)));
else
printf("Don't have Daniel's number.");
cmap_str_emplace(&contacts, "Daniel", "164-6743");
if ((v = cmap_str_get(&contacts, "Ashley")))
- printf("Calling Ashley: %s\n", call(v->second.str));
+ printf("Calling Ashley: %s\n", call(cstr_str(&v->second)));
else
printf("Don't have Ashley's number.");
@@ -41,7 +41,7 @@ int main(void) {
puts("");
c_forpair (contact, number, cmap_str, contacts) {
- printf("Calling %s: %s\n", _.contact.str, call(_.number.str));
+ printf("Calling %s: %s\n", cstr_str(&_.contact), call(cstr_str(&_.number)));
}
puts("");
}
diff --git a/examples/inits.c b/examples/inits.c
index 3bd7e3b4..97d86389 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -60,7 +60,7 @@ int main(void)
cmap_id_insert(&idnames, 120, cstr_from_fmt("Howdy, -%d-", year));
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));
puts("");
}
@@ -83,7 +83,7 @@ int main(void)
cmap_cnt_emplace(&countries, "Finland", 0).ref->second += 20;
c_forpair (country, health, cmap_cnt, countries)
- printf("%s: %d\n", _.country.str, _.health);
+ printf("%s: %d\n", cstr_str(&_.country), _.health);
puts("");
}
diff --git a/examples/make.sh b/examples/make.sh
index 3f2247b6..ef0468c7 100644
--- a/examples/make.sh
+++ b/examples/make.sh
@@ -1,6 +1,7 @@
#!/bin/bash
cc='gcc -s -O2 -Wall -std=c99 -pedantic'
-#cc='clang -s -O2 -Wall -std=c99 -pedantic'
+#cc='gcc -x c++ -s -O2 -Wall -std=c++20'
+#cc='clang -s -O2 -Wall -std=c99 -pedantic -DSTC_USE_SSO'
#cc='clang'
#cc='clang -c -DSTC_HEADER'
#cc='cl -O2 -nologo -W2 -MD'
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 0d6d2843..7faaffd1 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -3,7 +3,7 @@
#define i_type People
#define i_key_str
#define i_val_str
-#define i_keydrop(p) (printf("kdrop: %s\n", p->str), cstr_drop(p))
+#define i_keydrop(p) (printf("kdrop: %s\n", cstr_str(p)), cstr_drop(p))
#include <stc/csmap.h>
#define i_type Departments
@@ -55,7 +55,7 @@ int main(void)
c_foreach (i, Departments, map)
c_forpair (name, email, People, i.ref->second)
- printf("%s: %s - %s\n", i.ref->first.str, _.name.str, _.email.str);
+ printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(&_.name), cstr_str(&_.email));
puts("");
printf("found: %d\n", contains(&map, "Nick Denton"));
diff --git a/examples/mmap.c b/examples/mmap.c
index 289da616..6ffd3a5d 100644
--- a/examples/mmap.c
+++ b/examples/mmap.c
@@ -17,7 +17,7 @@ void print(const char* lbl, const Multimap mmap)
printf("%s ", lbl);
c_foreach (e, Multimap, mmap) {
c_foreach (s, clist_str, e.ref->second)
- printf("{%d,%s} ", e.ref->first, s.ref->str);
+ printf("{%d,%s} ", e.ref->first, cstr_str(s.ref));
}
puts("");
}
diff --git a/examples/multimap.c b/examples/multimap.c
index 472af8aa..08fd8ad5 100644
--- a/examples/multimap.c
+++ b/examples/multimap.c
@@ -70,7 +70,7 @@ int main()
{
const clist_OL empty = clist_OL_init();
- for (int i = 0; i < c_arraylen(ol_data); ++i)
+ for (size_t i = 0; i < c_arraylen(ol_data); ++i)
{
struct OlympicsData* d = &ol_data[i];
OlympicLocation loc = {.year = d->year,
@@ -90,9 +90,10 @@ int main()
{
// Loop the locations for a country sorted by year
c_foreach (loc, clist_OL, country.ref->second)
- printf("%s: %d, %s, %s\n", country.ref->first.str, loc.ref->year,
- loc.ref->city.str,
- loc.ref->date.str);
+ printf("%s: %d, %s, %s\n", cstr_str(&country.ref->first),
+ loc.ref->year,
+ cstr_str(&loc.ref->city),
+ cstr_str(&loc.ref->date));
}
}
}
diff --git a/examples/music_arc.c b/examples/music_arc.c
index b2661ffe..b8525022 100644
--- a/examples/music_arc.c
+++ b/examples/music_arc.c
@@ -13,7 +13,7 @@ Song Song_new(const char* artist, const char* title)
{ return (Song){cstr_from(artist), cstr_from(title)}; }
void Song_drop(Song* s) {
- printf("drop: %s\n", s->title.str);
+ printf("drop: %s\n", cstr_str(&s->title));
c_drop(cstr, &s->artist, &s->title);
}
@@ -47,8 +47,9 @@ void example3()
});
c_foreach (s, SongVec, vec2)
- printf("%s - %s: refs %lu\n", s.ref->get->artist.str, s.ref->get->title.str,
- *s.ref->use_count);
+ printf("%s - %s: refs %lu\n", cstr_str(&s.ref->get->artist),
+ cstr_str(&s.ref->get->title),
+ *s.ref->use_count);
}
}
diff --git a/examples/new_arr.c b/examples/new_arr.c
index a593536e..b44474c9 100644
--- a/examples/new_arr.c
+++ b/examples/new_arr.c
@@ -56,6 +56,6 @@ int main()
cstr_assign(&text2d.data[4][0], "world");
c_foreach (i, carr2_str, text2d)
- printf("line: %s\n", i.ref->str);
+ printf("line: %s\n", cstr_str(i.ref));
}
}
diff --git a/examples/new_map.c b/examples/new_map.c
index 97fce008..ec37a846 100644
--- a/examples/new_map.c
+++ b/examples/new_map.c
@@ -66,6 +66,6 @@ int main()
"So long, friend",
});
c_foreach (i, cset_str, sset)
- printf(" %s\n", i.ref->str);
+ printf(" %s\n", cstr_str(i.ref));
}
}
diff --git a/examples/new_pque.c b/examples/new_pque.c
index 1485e630..79e895d8 100644
--- a/examples/new_pque.c
+++ b/examples/new_pque.c
@@ -58,7 +58,7 @@ int main()
cpque_int_push(&ique, 123);
cpque_int_push(&ique, 321);
// print
- for (int i=0; i<cpque_int_size(ique); ++i)
+ for (size_t i=0; i<cpque_int_size(ique); ++i)
printf(" %d", ique.data[i]);
puts("");
}
diff --git a/examples/new_smap.c b/examples/new_smap.c
index 382d27ae..a25dcfa2 100644
--- a/examples/new_smap.c
+++ b/examples/new_smap.c
@@ -64,7 +64,7 @@ int main()
{"This is the time", "for all good things"},
});
c_forpair (i, j, SMap, smap)
- printf(" (%s: %s)\n", _.i.str, _.j.str);
+ printf(" (%s: %s)\n", cstr_str(&_.i), cstr_str(&_.j));
}
c_auto (SSet, sset) {
diff --git a/examples/new_sptr.c b/examples/new_sptr.c
index 61eaf5ae..2fb058df 100644
--- a/examples/new_sptr.c
+++ b/examples/new_sptr.c
@@ -10,7 +10,7 @@ Person Person_clone(Person p) {
return 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);
}
@@ -37,7 +37,7 @@ int main(void) {
q = carc_person_clone(p);
r = carc_person_clone(p);
s = carc_person_from(Person_clone(*p.get)); // deep copy
- printf("%s %s. uses: %lu\n", r.get->name.str, s.get->last.str, *p.use_count);
+ printf("%s %s. uses: %lu\n", cstr_str(&r.get->name), cstr_str(&s.get->last), *p.use_count);
}
c_auto (cstack_iptr, stk) {
diff --git a/examples/person_arc.c b/examples/person_arc.c
index e668cda6..2fb51be5 100644
--- a/examples/person_arc.c
+++ b/examples/person_arc.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);
}
@@ -43,8 +43,8 @@ int main()
q = PSPtr_from(Person_clone(*p.get));
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, PSPtr_from(Person_new("Dale", "Cooper")));
Persons_push_back(&vec, PSPtr_from(Person_new("Audrey", "Home")));
@@ -53,13 +53,13 @@ int main()
c_apply(v, Persons_push_back(&vec, PSPtr_clone(v)), PSPtr, {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!
c_autovar (Person a = Person_new("Audrey", "Home"), Person_drop(&a)) {
const PSPtr *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("");
diff --git a/examples/phonebook.c b/examples/phonebook.c
index fff84bec..b00a49a8 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -34,7 +34,7 @@
void print_phone_book(cmap_str phone_book)
{
c_foreach (i, cmap_str, phone_book)
- printf("%s\t- %s\n", i.ref->first.str, i.ref->second.str);
+ printf("%s\t- %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
}
int main(int argc, char **argv)
@@ -42,7 +42,7 @@ int main(int argc, char **argv)
c_auto (cset_str, names) {
c_apply(v, cset_str_emplace(&names, v), const char*,
{"Hello", "Cool", "True"});
- c_foreach (i, cset_str, names) printf("%s ", i.ref->str);
+ c_foreach (i, cset_str, names) printf("%s ", cstr_str(i.ref));
puts("");
}
diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c
index 483e7c9a..8f7dd4de 100644
--- a/examples/rawptr_elements.c
+++ b/examples/rawptr_elements.c
@@ -57,6 +57,6 @@ int main()
cmap_str_emplace(&map, "goodbye", 400);
c_forpair (name, number, cmap_str, map)
- printf("%s: %" PRIdMAX "\n", _.name.str, *_.number);
+ printf("%s: %" PRIdMAX "\n", cstr_str(&_.name), *_.number);
}
}
diff --git a/examples/regex1.c b/examples/regex1.c
index e244c984..23a28f08 100644
--- a/examples/regex1.c
+++ b/examples/regex1.c
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
if (cstr_equals(input, "q"))
break;
- if (cregex_find(&float_expr, input.str, 0, NULL, 0) > 0)
+ if (cregex_find(&float_expr, cstr_str(&input), 0, NULL, 0) > 0)
printf("Input is a float\n");
else
printf("Invalid input : Not a float\n");
@@ -29,4 +29,4 @@ int main(int argc, char* argv[])
}
}
-#include "../src/cregex.c" \ No newline at end of file
+#include "../src/cregex.c"
diff --git a/examples/replace.c b/examples/replace.c
index c425e4f8..a5bcf4d3 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -10,23 +10,23 @@ int main ()
// replace signatures used in the same order as described above:
- // Ustring positions: 0123456789*123456789*12345
- cstr s = cstr_from(base); // "this is a test string."
+ // Ustring positions: 0123456789*123456789*12345
+ cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
c_autodefer (cstr_drop(&s), cstr_drop(&m)) {
- cstr_append(&m, m.str);
- cstr_append(&m, m.str);
- printf("%s\n", m.str);
+ cstr_append(&m, cstr_str(&m));
+ cstr_append(&m, cstr_str(&m));
+ printf("%s\n", cstr_str(&m));
cstr_replace(&s, 9, 5, s2); // "this is an example string." (1)
- printf("(1) %s\n", s.str);
+ printf("(1) %s\n", cstr_str(&s));
cstr_replace_n(&s, 19, 6, s3+7, 6); // "this is an example phrase." (2)
- printf("(2) %s\n", s.str);
+ printf("(2) %s\n", cstr_str(&s));
cstr_replace(&s, 8, 10, "just a"); // "this is just a phrase." (3)
- printf("(3) %s\n", s.str);
+ printf("(3) %s\n", cstr_str(&s));
cstr_replace_n(&s, 8, 6,"a shorty", 7); // "this is a short phrase." (4)
- printf("(4) %s\n", s.str);
+ printf("(4) %s\n", cstr_str(&s));
cstr_replace(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5)
- printf("(5) %s\n", s.str);
+ printf("(5) %s\n", cstr_str(&s));
}
}
diff --git a/examples/splitstr.c b/examples/splitstr.c
index 35fe3cfa..427c61c8 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -32,5 +32,5 @@ 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));
}
diff --git a/examples/sview_split.c b/examples/sview_split.c
index 0db175ce..3e3c584b 100644
--- a/examples/sview_split.c
+++ b/examples/sview_split.c
@@ -15,6 +15,6 @@ int main()
c_auto (cstr, y, m, d) {
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);
+ printf("%s, %s, %s\n", cstr_str(&y), cstr_str(&m), cstr_str(&d));
}
}
diff --git a/examples/unordered_set.c b/examples/unordered_set.c
index f4e37cf8..2decb88c 100644
--- a/examples/unordered_set.c
+++ b/examples/unordered_set.c
@@ -36,6 +36,6 @@ int main()
// content
printf("All elements :\n");
c_foreach (itr, cset_str, stringSet)
- printf("%s\n", itr.ref->str);
+ printf("%s\n", cstr_str(itr.ref));
}
}
diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c
index 49680ecd..5ca51d22 100644
--- a/examples/utf8replace_c.c
+++ b/examples/utf8replace_c.c
@@ -5,14 +5,14 @@
int main() {
c_auto (cstr, hello) {
hello = cstr_new("hell😀 world");
- printf("%s\n", hello.str);
+ printf("%s\n", cstr_str(&hello));
cstr_replace_sv(
&hello,
- utf8_substr(hello.str, 4, 1),
+ utf8_substr(cstr_str(&hello), 4, 1),
c_sv("🐨")
);
- printf("%s\n", hello.str);
+ printf("%s\n", cstr_str(&hello));
csview sv = csview_from_s(&hello);
c_foreach (c, csview, sv)
diff --git a/examples/vikings.c b/examples/vikings.c
index 943b1f36..b093ff9b 100644
--- a/examples/vikings.c
+++ b/examples/vikings.c
@@ -30,7 +30,7 @@ static inline Viking Viking_from(RViking raw) { // note: parameter is by value
return c_make(Viking){cstr_from(raw.name), cstr_from(raw.country)};
}
static inline RViking Viking_toraw(const Viking* vk) {
- return c_make(RViking){vk->name.str, vk->country.str};
+ return c_make(RViking){cstr_str(&vk->name), cstr_str(&vk->country)};
}
// With this in place, we define the Viking => int hash map type:
@@ -63,7 +63,7 @@ int main()
Vikings_emplace(&vikings, einar, 0).ref->second += 5; // add 5 more to Einar
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);
}
}
}
diff --git a/examples/words.c b/examples/words.c
index 852207a9..28de2638 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -19,12 +19,12 @@ int main1()
});
c_foreach (w, cvec_str, words) {
- cmap_str_emplace(&word_map, w.ref->str, 0).ref->second += 1;
+ cmap_str_emplace(&word_map, cstr_str(w.ref), 0).ref->second += 1;
}
c_foreach (i, cmap_str, word_map) {
printf("%d occurrences of word '%s'\n",
- i.ref->second, i.ref->first.str);
+ i.ref->second, cstr_str(&i.ref->first));
}
}
return 0;