aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/text.h
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.h
parent3a8841af6d15763e4c322c2c7671582ed6c3b006 (diff)
parentb4f2d03db2cd20688d6bb537904998e997bc48aa (diff)
Merge branch 'optional-list-indexing' into dev
Diffstat (limited to 'src/stdlib/text.h')
-rw-r--r--src/stdlib/text.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 4d2f16b8..281c1880 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -53,7 +53,17 @@ Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int);
Text_t Text$from(Text_t text, Int_t first);
Text_t Text$to(Text_t text, Int_t last);
Text_t Text$reversed(Text_t text);
-Text_t Text$cluster(Text_t text, Int_t index_int);
+OptionalText_t Text$cluster(Text_t text, Int_t index_int);
+#define Text$cluster_checked(text_expr, index_expr, start, end) \
+ ({ \
+ const Text_t text = text_expr; \
+ Int_t index = index_expr; \
+ OptionalText_t cluster = Text$cluster(text, index); \
+ if (unlikely(cluster.length < 0)) \
+ fail_source(__SOURCE_FILE__, start, end, "Invalid text index: ", index, " (text has length ", \
+ (int64_t)text.length, ")\n"); \
+ cluster; \
+ })
OptionalText_t Text$from_str(const char *str);
OptionalText_t Text$from_strn(const char *str, size_t len);
PUREFUNC uint64_t Text$hash(const void *text, const TypeInfo_t *);