diff options
| author | Tyge Løvset <[email protected]> | 2022-07-27 15:22:38 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-07-27 15:22:38 +0200 |
| commit | c37abf4f78b97244e92cba6c352501a4d22110cf (patch) | |
| tree | 12c49ad74db06641bd7764ea64f5cb56e9fa3f26 /examples | |
| parent | 2bae847079852eb808e50a136659e98898616bef (diff) | |
| download | STC-modified-c37abf4f78b97244e92cba6c352501a4d22110cf.tar.gz STC-modified-c37abf4f78b97244e92cba6c352501a4d22110cf.zip | |
VERSION 3.8 BETA: Some changes in cstr / csview APIs: replace* / find*, *_u8(). . See README.md
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/cstr_match.c | 8 | ||||
| -rw-r--r-- | examples/demos.c | 2 | ||||
| -rw-r--r-- | examples/regex_replace.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 18 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 11 |
5 files changed, 22 insertions, 19 deletions
diff --git a/examples/cstr_match.c b/examples/cstr_match.c index fd420f62..9c4fa2d3 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_from(ss, 0, "brown"); + size_t pos = cstr_find_at(ss, 0, "brown"); 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")); @@ -14,9 +14,9 @@ int main() printf("ends_with: %d\n", cstr_ends_with(ss, ".JPG")); cstr s1 = cstr_new("hell😀 w😀rl🐨"); - csview ch1 = cstr_chr_u8(&s1, 7); - csview ch2 = cstr_chr_u8(&s1, 10); - printf("%s\nsize: %" PRIuMAX ", %" PRIuMAX "\n", cstr_str(&s1), cstr_u8size(s1), cstr_size(s1)); + csview ch1 = cstr_u8_chr(&s1, 7); + csview ch2 = cstr_u8_chr(&s1, 10); + printf("%s\nsize: %" PRIuMAX ", %" PRIuMAX "\n", cstr_str(&s1), cstr_u8_size(s1), cstr_size(s1)); printf("ch1: %" c_PRIsv "\n", c_ARGsv(ch1)); printf("ch2: %" c_PRIsv "\n", c_ARGsv(ch2)); } diff --git a/examples/demos.c b/examples/demos.c index 4cb50082..052c4e32 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -13,7 +13,7 @@ void stringdemo1() cstr_erase_n(&cs, 7, 5); // -nine printf("%s.\n", cstr_str(&cs)); - cstr_replace(&cs, "seven", "four"); + cstr_replace(&cs, "seven", "four", 1); printf("%s.\n", cstr_str(&cs)); cstr_take(&cs, cstr_from_fmt("%s *** %s", cstr_str(&cs), cstr_str(&cs))); diff --git a/examples/regex_replace.c b/examples/regex_replace.c index 21252236..3dcb965d 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -41,7 +41,7 @@ int main() cregex_drop(&re); printf("euros: %s\n", cstr_str(&str)); - /* Wrap all words in {} */ + /* Wrap all words in ${} */ cstr_take(&str, cregex_replace_p("[52] apples and [31] mangoes", "[a-z]+", "$${$0}")); printf("curly: %s\n", cstr_str(&str)); } diff --git a/examples/replace.c b/examples/replace.c index 2926977c..13b6eaaf 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -8,23 +8,27 @@ 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, cstr_str(&m)); cstr_append(&m, cstr_str(&m)); printf("%s\n", cstr_str(&m)); - cstr_replace_at(&s, 9, 5, s2); // "this is an example string." (1) + cstr_replace_at(&s, 9, 5, s2); // "this is an example string." (1) printf("(1) %s\n", cstr_str(&s)); - cstr_replace_with_n(&s, 19, 6, s3+7, 6); // "this is an example phrase." (2) + + cstr_replace_at_sv(&s, 19, 6, c_sv(s3+7, 6)); // "this is an example phrase." (2) printf("(2) %s\n", cstr_str(&s)); - cstr_replace_at(&s, 8, 10, "just a"); // "this is just a phrase." (3) + + cstr_replace_at(&s, 8, 10, "just a"); // "this is just a phrase." (3) printf("(3) %s\n", cstr_str(&s)); - cstr_replace_with_n(&s, 8, 6,"a shorty", 7); // "this is a short phrase." (4) + + cstr_replace_at_sv(&s, 8, 6, c_sv("a shorty", 7)); // "this is a short phrase." (4) printf("(4) %s\n", cstr_str(&s)); - cstr_replace_at(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) + + cstr_replace_at(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) printf("(5) %s\n", cstr_str(&s)); } } diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index c38b37e4..86d8bd69 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -1,3 +1,4 @@ +#define i_implement #include <stc/cstr.h> #include <stc/csview.h> @@ -6,14 +7,12 @@ int main() { hello = cstr_new("hell😀 w😀rld"); printf("%s\n", cstr_str(&hello)); - cstr_replace_sv( - &hello, - csview_substr_u8(cstr_sv(&hello), 7, 1), - c_sv("🐨") - ); + /* replace second smiley at utf8 codepoint pos 7 */ + cstr_u8_replace_at(&hello, 7, 1, c_sv("🐨")); + printf("%s\n", cstr_str(&hello)); - cstr_replace(&hello, "🐨", "ø"); + cstr_replace(&hello, "🐨", "ø", 1); printf("%s\n", cstr_str(&hello)); c_foreach (c, cstr, hello) |
