aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/text.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-09 15:16:27 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-09 15:16:27 -0400
commit57154250c71aee7d7827afd3c608ba876f51206a (patch)
tree00a6e6b7a24107c7c95dde5405989c4b1b2c44a0 /src/stdlib/text.h
parentd1f967ffb4dc099a34f54434be10a58eb33b81f7 (diff)
Deprecate cords from the gc library in favor of dogfooding Text from the
Tomo standard library.
Diffstat (limited to 'src/stdlib/text.h')
-rw-r--r--src/stdlib/text.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index fc336612..642a74b6 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -8,6 +8,7 @@
#include "datatypes.h"
#include "integers.h"
+#include "mapmacro.h"
#include "optionals.h"
#include "types.h"
#include "util.h"
@@ -26,10 +27,20 @@ typedef struct {
#define Text(str) ((Text_t){.length=sizeof(str)-1, .tag=TEXT_ASCII, .ascii="" str})
-//int Text$print(FILE *stream, Text_t t);
+static inline Text_t Text_from_str_literal(const char *str) {
+ return (Text_t){.length=strlen(str), .tag=TEXT_ASCII, .ascii=str};
+}
+
+static inline Text_t Text_from_text(Text_t t) {
+ return t;
+}
+
+#define convert_to_text(x) _Generic(x, Text_t: Text_from_text, char*: Text$from_str, const char*: Text$from_str)(x)
+
Text_t Text$_concat(int n, Text_t items[n]);
#define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__})
-#define Texts(...) Text$concat(__VA_ARGS__)
+#define Texts(...) Text$concat(MAP_LIST(convert_to_text, __VA_ARGS__))
+// int Text$print(FILE *stream, Text_t t);
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);