diff options
| author | Tyge Løvset <[email protected]> | 2022-03-16 21:41:40 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-03-16 21:41:40 +0100 |
| commit | 0468971b404cee5582d360d7d1c66bb4148e1614 (patch) | |
| tree | 9161ccbea490a5dab70e641f7bd568521a5da636 /examples | |
| parent | 342484f70998258022c26e6af2926ecc7635bbdd (diff) | |
| download | STC-modified-0468971b404cee5582d360d7d1c66bb4148e1614.tar.gz STC-modified-0468971b404cee5582d360d7d1c66bb4148e1614.zip | |
Bugfix: carc and cbox cmp functions had bug.
Renamed: i_key_sptr / i_val_sptr to i_key_arcbox / i_val_arcbox.
Other smaller updates.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/arc_containers.c | 4 | ||||
| -rw-r--r-- | examples/arc_demo.c | 4 | ||||
| -rw-r--r-- | examples/arcvec_erase.c | 4 | ||||
| -rw-r--r-- | examples/box.c | 2 | ||||
| -rw-r--r-- | examples/box2.c | 4 | ||||
| -rw-r--r-- | examples/music_arc.c | 2 | ||||
| -rw-r--r-- | examples/new_sptr.c | 2 | ||||
| -rw-r--r-- | examples/person_arc.c | 2 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 21 | ||||
| -rw-r--r-- | examples/utf8replace_rs.rs | 19 |
10 files changed, 52 insertions, 12 deletions
diff --git a/examples/arc_containers.c b/examples/arc_containers.c index 0873d297..ea9395e8 100644 --- a/examples/arc_containers.c +++ b/examples/arc_containers.c @@ -15,11 +15,11 @@ #include <stc/carc.h>
#define i_type Stack
-#define i_val_sptr Arc // define i_val_bind for carc/cbox value (not i_val)
+#define i_val_arcbox Arc // define i_val_bind for carc/cbox value (not i_val)
#include <stc/cstack.h>
#define i_type List
-#define i_val_sptr Arc // as above
+#define i_val_arcbox Arc // as above
#include <stc/clist.h>
int main()
diff --git a/examples/arc_demo.c b/examples/arc_demo.c index 8626e2d4..036b7a00 100644 --- a/examples/arc_demo.c +++ b/examples/arc_demo.c @@ -13,10 +13,10 @@ void int_drop(int* x) { #define i_drop int_drop // optional, just to display the elements destroyed
#include <stc/carc.h> // iref
-#define i_key_sptr iref // note: use i_key_bind instead of i_key for carc/cbox elements
+#define i_key_arcbox iref // note: use i_key_bind instead of i_key for carc/cbox elements
#include <stc/csset.h> // csset_iref (like: std::set<std::shared_ptr<int>>)
-#define i_val_sptr iref // note: as above.
+#define i_val_arcbox iref // note: as above.
#include <stc/cvec.h> // cvec_iref (like: std::vector<std::shared_ptr<int>>)
int main()
diff --git a/examples/arcvec_erase.c b/examples/arcvec_erase.c index d40d8fe7..12547f6c 100644 --- a/examples/arcvec_erase.c +++ b/examples/arcvec_erase.c @@ -12,8 +12,8 @@ void show_drop(int* x) { printf("drop: %d\n", *x); } #include <stc/carc.h> // Shared pointer to int
#define i_type Vec
-#define i_val_sptr Arc
-#include <stc/cvec.h> // Vec: cvec<Arc>
+#define i_val_arcbox Arc
+#include <stc/cvec.h> // Vec: cvec<Arc>
int main()
diff --git a/examples/box.c b/examples/box.c index d97545b6..00a092e2 100644 --- a/examples/box.c +++ b/examples/box.c @@ -28,7 +28,7 @@ void Person_drop(Person* p) { #include <stc/cbox.h>
#define i_type Persons
-#define i_val_sptr PBox // informs that PBox is a smart pointer.
+#define i_val_arcbox PBox // informs that PBox is a smart pointer.
#include <stc/cvec.h>
int main()
diff --git a/examples/box2.c b/examples/box2.c index e5b4dacd..68a9ccba 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -26,8 +26,8 @@ struct { #include <stc/cbox.h> // cbox_Rectangle
// Box in box:
-#define i_val_sptr cbox_Point // NB: adviced to use i_val_sptr when value is a cbox or carc!
- // it will auto-set i_drop, i_from, i_cmp for you.
+#define i_val_arcbox cbox_Point // NB: use i_val_arcbox when value is a cbox or carc!
+ // it will auto-set i_drop, i_from, i_cmp for you.
#define i_opt c_no_cmp
#define i_tag BoxPoint
#include <stc/cbox.h> // cbox_BoxPoint
diff --git a/examples/music_arc.c b/examples/music_arc.c index 42bb3455..b2661ffe 100644 --- a/examples/music_arc.c +++ b/examples/music_arc.c @@ -24,7 +24,7 @@ void Song_drop(Song* s) { #include <stc/carc.h>
#define i_type SongVec
-#define i_val_sptr SongPtr
+#define i_val_arcbox SongPtr
#include <stc/cvec.h>
void example3()
diff --git a/examples/new_sptr.c b/examples/new_sptr.c index 3a038629..61eaf5ae 100644 --- a/examples/new_sptr.c +++ b/examples/new_sptr.c @@ -25,7 +25,7 @@ void Person_drop(Person* p) { #define i_drop(x) printf("drop: %d\n", *(x))
#include <stc/carc.h>
-#define i_val_sptr SPtr
+#define i_val_arcbox SPtr
#define i_tag iptr
#include <stc/cstack.h>
diff --git a/examples/person_arc.c b/examples/person_arc.c index 0c22bd68..e668cda6 100644 --- a/examples/person_arc.c +++ b/examples/person_arc.c @@ -28,7 +28,7 @@ void Person_drop(Person* p) { #include <stc/carc.h>
#define i_type Persons
-#define i_val_sptr PSPtr // binds PSPtr_cmp, ...
+#define i_val_arcbox PSPtr // binds PSPtr_cmp, ...
#include <stc/cvec.h>
diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c new file mode 100644 index 00000000..e04f2cb8 --- /dev/null +++ b/examples/utf8replace_c.c @@ -0,0 +1,21 @@ +#include <stc/cstr.h> +#include <stc/csview.h> +#include <stc/utf8.h> + +int main() { + c_auto (cstr, hello) { + hello = cstr_new("hell😀 world"); + printf("%s\n", hello.str); + + cstr_replace_sv( + &hello, + utf8_substr(hello.str, 4, 1), + c_sv("🐨") + ); + printf("%s\n", hello.str); + + csview sv = csview_from_s(hello); + c_foreach (c, csview, sv) + printf(c_PRIsv ",", c_ARGsv(c.codep)); + } +} diff --git a/examples/utf8replace_rs.rs b/examples/utf8replace_rs.rs new file mode 100644 index 00000000..717978aa --- /dev/null +++ b/examples/utf8replace_rs.rs @@ -0,0 +1,19 @@ + +pub fn main() { + let mut hello = String::from("hell😀 world"); + println!("{}", hello); + + hello.replace_range( + hello + .char_indices() + .nth(4) + .map(|(pos, ch)| (pos..pos + ch.len_utf8())) + .unwrap(), + "🐨", + ); + println!("{}", hello); + + for c in hello.chars() { + print!("{},", c); + } +} |
