summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/mixed/convert.c
diff options
context:
space:
mode:
author_Tradam <[email protected]>2023-09-08 01:29:47 +0000
committerGitHub <[email protected]>2023-09-08 01:29:47 +0000
commit3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch)
treeafbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/mixed/convert.c
parent0841165881871ee01b782129be681209aeed2423 (diff)
parent1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff)
downloadSTC-modified-modified.tar.gz
STC-modified-modified.zip
Merge branch 'stclib:master' into modifiedHEADmodified
Diffstat (limited to 'misc/examples/mixed/convert.c')
-rw-r--r--misc/examples/mixed/convert.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/misc/examples/mixed/convert.c b/misc/examples/mixed/convert.c
new file mode 100644
index 00000000..fa64560e
--- /dev/null
+++ b/misc/examples/mixed/convert.c
@@ -0,0 +1,57 @@
+#define i_implement
+#include <stc/cstr.h>
+
+#define i_key_str
+#define i_val_str
+#include <stc/cmap.h>
+
+#define i_key_str
+#include <stc/cvec.h>
+
+#define i_key_str
+#include <stc/clist.h>
+
+int main(void)
+{
+ cmap_str map, mclone;
+ cvec_str keys = {0}, values = {0};
+ clist_str list = {0};
+
+ c_defer(
+ cmap_str_drop(&map),
+ cmap_str_drop(&mclone),
+ cvec_str_drop(&keys),
+ cvec_str_drop(&values),
+ clist_str_drop(&list)
+ ){
+ map = c_init(cmap_str, {
+ {"green", "#00ff00"},
+ {"blue", "#0000ff"},
+ {"yellow", "#ffff00"},
+ });
+
+ puts("MAP:");
+ c_foreach (i, cmap_str, map)
+ 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", 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, 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", 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, cstr_str(i.ref));
+
+ c_foreach (i, clist_str, list)
+ printf(" %s\n", cstr_str(i.ref));
+ }
+}