summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/cregex_api.md7
-rw-r--r--examples/new_arr.c6
-rw-r--r--examples/prime.c2
-rw-r--r--examples/regex_replace.c2
-rw-r--r--include/stc/carr2.h2
-rw-r--r--include/stc/cbits.h2
6 files changed, 10 insertions, 11 deletions
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index feb17a9a..f1fd7461 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -86,9 +86,9 @@ If an error occurs ```cregex_compile``` returns a negative value, see error code
### Getting the first match
```c
-#define i_implement
-#include <stc/cstr.h>
+#define i_extern // include external utf8 and cregex functions implementation.
#include <stc/cregex.h>
+#include <stc/cstr.h>
int main() {
const char* input = "start date is 2023-03-01, and end date is 2025-12-31.";
@@ -104,7 +104,7 @@ int main() {
printf("Could not find any date\n");
// Lets change all dates into US date format MM/DD/YYYY:
- cstr us_input = cregex_replace(&re, input, "$2/$3/$1");
+ cstr us_input = cregex_replace(&re, input, "$2/$3/$1", 0);
printf("US input: %s\n", cstr_str(&us_input));
// Free allocated data
@@ -112,7 +112,6 @@ int main() {
cregex_drop(&re);
}
```
-
For a single match you may use the all-in-one function:
```c
if (cregex_find_pattern(pattern, input, match, cre_default))
diff --git a/examples/new_arr.c b/examples/new_arr.c
index 51955b46..79e7c7a6 100644
--- a/examples/new_arr.c
+++ b/examples/new_arr.c
@@ -13,7 +13,7 @@ int main()
{
int w = 7, h = 5, d = 3;
- c_autodrop (carr2_int, volume, carr2_int_new_uninit(w, h))
+ c_with (carr2_int volume = carr2_int_new_uninit(w, h), carr2_int_drop(&volume))
{
int *dat = carr2_int_data(&volume);
for (size_t i = 0; i < carr2_int_size(&volume); ++i)
@@ -29,7 +29,7 @@ int main()
puts("\n");
}
- c_autodrop (carr3_int, volume, carr3_int_new_uninit(w, h, d))
+ c_with (carr3_int volume = carr3_int_new_uninit(w, h, d), carr3_int_drop(&volume))
{
int *dat = carr3_int_data(&volume);
for (size_t i = 0; i < carr3_int_size(&volume); ++i)
@@ -46,7 +46,7 @@ int main()
puts("");
}
- c_autodrop (carr2_str, text2d, carr2_str_with_size(h, d, cstr_init()))
+ c_with (carr2_str text2d = carr2_str_with_size(h, d, cstr_null), carr2_str_drop(&text2d))
{
cstr_assign(&text2d.data[2][1], "hello");
cstr_assign(&text2d.data[4][0], "world");
diff --git a/examples/prime.c b/examples/prime.c
index d2fc5efa..287fb69b 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -28,7 +28,7 @@ int main(void)
printf("computing prime numbers up to %" c_ZU "\n", n);
clock_t t1 = clock();
- c_autodrop (cbits, primes, sieveOfEratosthenes(n + 1)) {
+ c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
puts("done");
size_t np = cbits_count(&primes);
clock_t t2 = clock();
diff --git a/examples/regex_replace.c b/examples/regex_replace.c
index 4091a59e..e88c559f 100644
--- a/examples/regex_replace.c
+++ b/examples/regex_replace.c
@@ -34,7 +34,7 @@ int main()
printf("brack: %s\n", cstr_str(&str));
/* Shows how to compile RE separately */
- c_autodrop (cregex, re, cregex_from(pattern, cre_default)) {
+ c_with (cregex re = cregex_from(pattern, cre_default), cregex_drop(&re)) {
if (cregex_captures(&re) == 0)
continue; // break c_with
/* European date format. */
diff --git a/include/stc/carr2.h b/include/stc/carr2.h
index 1399b8f6..2574a933 100644
--- a/include/stc/carr2.h
+++ b/include/stc/carr2.h
@@ -35,7 +35,7 @@
int main() {
int w = 7, h = 5;
- c_autodrop (carr2_int, image, carr2_int_new_uninit(w, h))
+ c_with (carr2_int image = carr2_int_new_uninit(w, h), carr2_int_drop(&image))
{
int *dat = carr2_int_data(&image);
for (int i = 0; i < carr2_int_size(&image); ++i)
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index 3a5c63e6..031ef80c 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -27,7 +27,7 @@ Similar to boost::dynamic_bitset / std::bitset
#include "cbits.h"
int main() {
- c_autodrop (cbits, bset, cbits_with_size(23, true))
+ c_with (cbits bset = cbits_with_size(23, true), cbits_drop(&bset))
{
cbits_reset(&bset, 9);
cbits_resize(&bset, 43, false);