diff options
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/bools.c | 16 | ||||
| -rw-r--r-- | stdlib/text.c | 24 | ||||
| -rw-r--r-- | stdlib/text.h | 8 |
3 files changed, 24 insertions, 24 deletions
diff --git a/stdlib/bools.c b/stdlib/bools.c index 5e0ade37..bf820664 100644 --- a/stdlib/bools.c +++ b/stdlib/bools.c @@ -23,15 +23,15 @@ PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo PUREFUNC public OptionalBool_t Bool$parse(Text_t text) { - if (Text$equal_ignoring_case(text, Text("yes")) - || Text$equal_ignoring_case(text, Text("on")) - || Text$equal_ignoring_case(text, Text("true")) - || Text$equal_ignoring_case(text, Text("1"))) { + if (Text$equal_ignoring_case(text, Text("yes"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("on"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("true"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("1"), NONE_TEXT)) { return yes; - } else if (Text$equal_ignoring_case(text, Text("no")) - || Text$equal_ignoring_case(text, Text("off")) - || Text$equal_ignoring_case(text, Text("false")) - || Text$equal_ignoring_case(text, Text("0"))) { + } else if (Text$equal_ignoring_case(text, Text("no"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("off"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("false"), NONE_TEXT) + || Text$equal_ignoring_case(text, Text("0"), NONE_TEXT)) { return no; } else { return NONE_BOOL; diff --git a/stdlib/text.c b/stdlib/text.c index 4ee21601..c8700739 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -968,13 +968,13 @@ PUREFUNC public bool Text$equal(const void *a, const void *b, const TypeInfo_t*) return Text$equal_values(*(Text_t*)a, *(Text_t*)b); } -PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b) +PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b, Text_t language) { if (a.length != b.length) return false; int64_t len = a.length; TextIter_t a_state = NEW_TEXT_ITER_STATE(a), b_state = NEW_TEXT_ITER_STATE(b); - const char *language = uc_locale_language(); + const char *uc_language = Text$as_c_string(language); for (int64_t i = 0; i < len; i++) { int32_t ai = Text$get_grapheme_fast(&a_state, i); int32_t bi = Text$get_grapheme_fast(&b_state, i); @@ -986,7 +986,7 @@ PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b) int64_t b_len = bi >= 0 ? 1 : NUM_GRAPHEME_CODEPOINTS(bi); int cmp = 0; - (void)u32_casecmp(a_codepoints, (size_t)a_len, b_codepoints, (size_t)b_len, language, UNINORM_NFC, &cmp); + (void)u32_casecmp(a_codepoints, (size_t)a_len, b_codepoints, (size_t)b_len, uc_language, UNINORM_NFC, &cmp); if (cmp != 0) return false; } @@ -994,40 +994,40 @@ PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b) return true; } -public Text_t Text$upper(Text_t text) +public Text_t Text$upper(Text_t text, Text_t language) { if (text.length == 0) return text; Array_t codepoints = Text$utf32_codepoints(text); - const char *language = uc_locale_language(); + const char *uc_language = Text$as_c_string(language); ucs4_t buf[128]; size_t out_len = sizeof(buf)/sizeof(buf[0]); - ucs4_t *upper = u32_toupper(codepoints.data, (size_t)codepoints.length, language, UNINORM_NFC, buf, &out_len); + ucs4_t *upper = u32_toupper(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, buf, &out_len); Text_t ret = text_from_u32(upper, (int64_t)out_len, false); if (upper != buf) free(upper); return ret; } -public Text_t Text$lower(Text_t text) +public Text_t Text$lower(Text_t text, Text_t language) { if (text.length == 0) return text; Array_t codepoints = Text$utf32_codepoints(text); - const char *language = uc_locale_language(); + const char *uc_language = Text$as_c_string(language); ucs4_t buf[128]; size_t out_len = sizeof(buf)/sizeof(buf[0]); - ucs4_t *lower = u32_tolower(codepoints.data, (size_t)codepoints.length, language, UNINORM_NFC, buf, &out_len); + ucs4_t *lower = u32_tolower(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, buf, &out_len); Text_t ret = text_from_u32(lower, (int64_t)out_len, false); if (lower != buf) free(lower); return ret; } -public Text_t Text$title(Text_t text) +public Text_t Text$title(Text_t text, Text_t language) { if (text.length == 0) return text; Array_t codepoints = Text$utf32_codepoints(text); - const char *language = uc_locale_language(); + const char *uc_language = Text$as_c_string(language); ucs4_t buf[128]; size_t out_len = sizeof(buf)/sizeof(buf[0]); - ucs4_t *title = u32_totitle(codepoints.data, (size_t)codepoints.length, language, UNINORM_NFC, buf, &out_len); + ucs4_t *title = u32_totitle(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, buf, &out_len); Text_t ret = text_from_u32(title, (int64_t)out_len, false); if (title != buf) free(title); return ret; diff --git a/stdlib/text.h b/stdlib/text.h index 64cf86f5..d3aba3f3 100644 --- a/stdlib/text.h +++ b/stdlib/text.h @@ -45,11 +45,11 @@ PUREFUNC uint64_t Text$hash(const void *text, const TypeInfo_t*); PUREFUNC int32_t Text$compare(const void *va, const void *vb, const TypeInfo_t*); PUREFUNC bool Text$equal(const void *a, const void *b, const TypeInfo_t*); PUREFUNC bool Text$equal_values(Text_t a, Text_t b); -PUREFUNC bool Text$equal_ignoring_case(Text_t a, Text_t b); +PUREFUNC bool Text$equal_ignoring_case(Text_t a, Text_t b, Text_t language); PUREFUNC bool Text$is_none(const void *t, const TypeInfo_t*); -Text_t Text$upper(Text_t text); -Text_t Text$lower(Text_t text); -Text_t Text$title(Text_t text); +Text_t Text$upper(Text_t text, Text_t language); +Text_t Text$lower(Text_t text, Text_t language); +Text_t Text$title(Text_t text, Text_t language); Text_t Text$as_text(const void *text, bool colorize, const TypeInfo_t *info); Text_t Text$quoted(Text_t str, bool colorize); PUREFUNC bool Text$starts_with(Text_t text, Text_t prefix); |
