summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-08-08 16:13:05 +0200
committerTyge Løvset <[email protected]>2022-08-08 16:29:43 +0200
commitfea47e9b0b1f1137944a446d0d7e4b413f7bc2dd (patch)
treee62f48c37a87a732e83f1dc336ba697b47443f9d
parent1954c6aa34aae6301f90e81e546db6fb666c517a (diff)
downloadSTC-modified-fea47e9b0b1f1137944a446d0d7e4b413f7bc2dd.tar.gz
STC-modified-fea47e9b0b1f1137944a446d0d7e4b413f7bc2dd.zip
Changed *cstr_tolower*/*cstr_toupper* arg from `const cstr*` to `csview`.
-rw-r--r--docs/cstr_api.md5
-rw-r--r--examples/hashmap.c2
-rw-r--r--include/stc/cstr.h15
-rw-r--r--src/utf8code.c27
4 files changed, 20 insertions, 29 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index e4edb4c5..eb788980 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -106,8 +106,9 @@ void cstr_next(cstr_iter* it);
// utf8 functions requires linking with src/utf8code.c symbols:
bool cstr_valid_utf8(const cstr* self); // check if str is valid utf8
-cstr cstr_tolower(const cstr* self); // returns new lowercase utf8 cstr
-cstr cstr_toupper(const cstr* self); // returns new uppercase utf8 cstr
+cstr cstr_tolower_sv(csview sv); // returns new lowercase utf8 cstr
+cstr cstr_toupper_sv(csview sv); // returns new uppercase utf8 cstr
+cstr cstr_casefold_sv(csview sv); // returns new casefolded utf8 cstr
void cstr_lowercase(cstr* self); // transform cstr to lowercase utf8
void cstr_uppercase(cstr* self); // transform cstr to uppercase utf8
bool cstr_iequals(cstr s, const char* str); // utf8 case-insensitive comparison
diff --git a/examples/hashmap.c b/examples/hashmap.c
index ac4e29bc..f59ed824 100644
--- a/examples/hashmap.c
+++ b/examples/hashmap.c
@@ -30,7 +30,7 @@ int main(void) {
else
printf("Don't have Daniel's number.");
- cmap_str_emplace(&contacts, "Daniel", "164-6743");
+ cmap_str_emplace_or_assign(&contacts, "Daniel", "164-6743");
if ((v = cmap_str_get(&contacts, "Ashley")))
printf("Calling Ashley: %s\n", call(cstr_str(&v->second)));
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 68f35674..d7e5dcd4 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -172,12 +172,15 @@ STC_INLINE size_t cstr_capacity(cstr s)
// utf8 methods defined in/depending on src/utf8code.c:
-extern cstr cstr_tofold(const cstr* self);
-extern cstr cstr_tolower(const cstr* self);
-extern cstr cstr_toupper(const cstr* self);
-extern void cstr_casefold(cstr* self);
-extern void cstr_lowercase(cstr* self);
-extern void cstr_uppercase(cstr* self);
+extern cstr cstr_casefold_sv(csview sv);
+extern cstr cstr_tolower_sv(csview sv);
+extern cstr cstr_toupper_sv(csview sv);
+
+STC_INLINE void cstr_lowercase(cstr* self)
+ { cstr_take(self, cstr_tolower_sv(cstr_sv(self))); }
+
+STC_INLINE void cstr_uppercase(cstr* self)
+ { cstr_take(self, cstr_toupper_sv(cstr_sv(self))); }
STC_INLINE bool cstr_valid_utf8(const cstr* self)
{ return utf8_valid(cstr_str(self)); }
diff --git a/src/utf8code.c b/src/utf8code.c
index 6a5e513f..394597e1 100644
--- a/src/utf8code.c
+++ b/src/utf8code.c
@@ -177,8 +177,7 @@ fn_tolower = {tolower, utf8_tolower},
fn_toupper = {toupper, utf8_toupper};
-static cstr cstr_tocase(const cstr* self, struct fncase fn) {
- csview sv = cstr_sv(self);
+static cstr cstr_tocase(csview sv, struct fncase fn) {
cstr out = cstr_null;
char *buf = cstr_reserve(&out, sv.size*3/2);
uint32_t cp; size_t sz = 0;
@@ -198,26 +197,14 @@ static cstr cstr_tocase(const cstr* self, struct fncase fn) {
return out;
}
-cstr cstr_tofold(const cstr* self) {
- return cstr_tocase(self, fn_tofold);
+cstr cstr_casefold_sv(csview sv) {
+ return cstr_tocase(sv, fn_tofold);
}
-cstr cstr_tolower(const cstr* self) {
- return cstr_tocase(self, fn_tolower);
+cstr cstr_tolower_sv(csview sv) {
+ return cstr_tocase(sv, fn_tolower);
}
-cstr cstr_toupper(const cstr* self) {
- return cstr_tocase(self, fn_toupper);
+cstr cstr_toupper_sv(csview sv) {
+ return cstr_tocase(sv, fn_toupper);
}
-
-void cstr_casefold(cstr* self) {
- cstr_take(self, cstr_tocase(self, fn_tofold));
-}
-
-void cstr_lowercase(cstr* self) {
- cstr_take(self, cstr_tocase(self, fn_tolower));
-}
-
-void cstr_uppercase(cstr* self) {
- cstr_take(self, cstr_tocase(self, fn_toupper));
-} \ No newline at end of file