From 0468971b404cee5582d360d7d1c66bb4148e1614 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 16 Mar 2022 21:41:40 +0100 Subject: 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. --- examples/arc_containers.c | 4 ++-- examples/arc_demo.c | 4 ++-- examples/arcvec_erase.c | 4 ++-- examples/box.c | 2 +- examples/box2.c | 4 ++-- examples/music_arc.c | 2 +- examples/new_sptr.c | 2 +- examples/person_arc.c | 2 +- examples/utf8replace_c.c | 21 +++++++++++++++++++++ examples/utf8replace_rs.rs | 19 +++++++++++++++++++ 10 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 examples/utf8replace_c.c create mode 100644 examples/utf8replace_rs.rs (limited to 'examples') 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 #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 #define i_type List -#define i_val_sptr Arc // as above +#define i_val_arcbox Arc // as above #include 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 // 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 // csset_iref (like: std::set>) -#define i_val_sptr iref // note: as above. +#define i_val_arcbox iref // note: as above. #include // cvec_iref (like: std::vector>) 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 // Shared pointer to int #define i_type Vec -#define i_val_sptr Arc -#include // Vec: cvec +#define i_val_arcbox Arc +#include // Vec: cvec 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 #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 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 // 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 // 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 #define i_type SongVec -#define i_val_sptr SongPtr +#define i_val_arcbox SongPtr #include 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 -#define i_val_sptr SPtr +#define i_val_arcbox SPtr #define i_tag iptr #include 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 #define i_type Persons -#define i_val_sptr PSPtr // binds PSPtr_cmp, ... +#define i_val_arcbox PSPtr // binds PSPtr_cmp, ... #include 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 +#include +#include + +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); + } +} -- cgit v1.2.3