diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-04 03:02:30 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-04 03:02:30 -0400 |
| commit | e0aca8fa72546b385bdb345fb65f4fe3b9c6f4fc (patch) | |
| tree | ba64b7b9a0bbfc7d4b92bb6f6e81f929dac400c5 /builtins/text.c | |
| parent | c3f8b40c84e09543a5fbb2adf8b9563e42650696 (diff) | |
Add method for getting a length-based string as Text
Diffstat (limited to 'builtins/text.c')
| -rw-r--r-- | builtins/text.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/builtins/text.c b/builtins/text.c index a96426f1..a3bca6fa 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -400,13 +400,13 @@ Text_t text_from_u32(uint32_t *codepoints, int64_t num_codepoints, bool normaliz return ret; } -public Text_t Text$from_str(const char *str) +public Text_t Text$from_strn(const char *str, size_t len) { int64_t ascii_span = 0; - while (str[ascii_span] && isascii(str[ascii_span])) + for (size_t i = 0; i < len && isascii(str[i]); i++) ascii_span++; - if (str[ascii_span] == '\0') { // All ASCII + if (ascii_span == (int64_t)len) { // All ASCII Text_t ret = {.length=ascii_span}; if (ascii_span <= 8) { ret.tag = TEXT_SHORT_ASCII; @@ -427,6 +427,11 @@ public Text_t Text$from_str(const char *str) } } +public Text_t Text$from_str(const char *str) +{ + return Text$from_strn(str, strlen(str)); +} + static void u8_buf_append(Text_t text, char **buf, int64_t *capacity, int64_t *i) { switch (text.tag) { |
