aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/text.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-13 12:01:52 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-13 12:01:52 -0400
commit981da7f0c6c47f66120482e7a7885cb5719d6959 (patch)
treec0d5bf912e7e477a0486120b8ac4aea8c49833f9 /src/stdlib/text.c
parent3a8841af6d15763e4c322c2c7671582ed6c3b006 (diff)
parentb4f2d03db2cd20688d6bb537904998e997bc48aa (diff)
Merge branch 'optional-list-indexing' into dev
Diffstat (limited to 'src/stdlib/text.c')
-rw-r--r--src/stdlib/text.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index b6b7e0bb..cda7dd31 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -726,7 +726,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]));