From 639d5ddfca562e5b3645955551be244b5e8ca9c6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 1 Sep 2025 12:51:19 -0400 Subject: Make text indexing optional --- src/stdlib/text.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/stdlib/text.c') 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])); -- cgit v1.2.3