diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 12:51:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 12:51:19 -0400 |
| commit | 639d5ddfca562e5b3645955551be244b5e8ca9c6 (patch) | |
| tree | 2a2fba7b2d442b5cf7e9dd2e1f876e4f799a6bdf /src/stdlib/text.c | |
| parent | 0a7062e2d711b5ac7fb71e873f293a8f0d0e8bc6 (diff) | |
Make text indexing optional
Diffstat (limited to 'src/stdlib/text.c')
| -rw-r--r-- | src/stdlib/text.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/stdlib/text.c b/src/stdlib/text.c index ed4023a4..f4533be5 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -725,7 +725,10 @@ Text_t Text$reversed(Text_t text) { } public -PUREFUNC Text_t Text$cluster(Text_t text, Int_t index) { return Text$slice(text, index, index); } +PUREFUNC OptionalText_t Text$cluster(Text_t text, Int_t index) { + Text_t slice = Text$slice(text, index, index); + return slice.length <= 0 ? NONE_TEXT : slice; +} static Text_t Text$from_components(List_t graphemes, Table_t unique_clusters) { size_t blob_size = (sizeof(int32_t[unique_clusters.entries.length]) + sizeof(uint8_t[graphemes.length])); |
