2024-03-03 15:15:45 -08:00
|
|
|
#pragma once
|
2024-03-18 09:57:49 -07:00
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
// Type info and methods for Text datatype, which uses a struct inspired by
|
|
|
|
// Raku's string representation and libunistr
|
2024-03-18 09:57:49 -07:00
|
|
|
|
2024-03-03 15:15:45 -08:00
|
|
|
#include <stdbool.h>
|
2024-09-02 15:47:39 -07:00
|
|
|
#include <printf.h>
|
2024-03-03 15:15:45 -08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2024-08-12 22:30:25 -07:00
|
|
|
#include "datatypes.h"
|
|
|
|
#include "integers.h"
|
2024-03-03 15:15:45 -08:00
|
|
|
#include "types.h"
|
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
int printf_text(FILE *stream, const struct printf_info *info, const void *const args[]);
|
|
|
|
int printf_text_size(const struct printf_info *info, size_t n, int argtypes[n], int sizes[n]);
|
|
|
|
|
2024-09-03 11:48:54 -07:00
|
|
|
#define Text(str) ((Text_t){.length=sizeof(str)-1, .tag=TEXT_ASCII, .ascii="" str})
|
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
int Text$print(FILE *stream, Text_t t);
|
|
|
|
void Text$visualize(Text_t t);
|
|
|
|
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__})
|
2024-09-03 20:35:42 -07:00
|
|
|
#define Texts(...) Text$concat(__VA_ARGS__)
|
2024-09-02 15:47:39 -07:00
|
|
|
Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int);
|
|
|
|
Text_t Text$from_str(const char *str);
|
2024-09-04 00:02:30 -07:00
|
|
|
Text_t Text$from_strn(const char *str, size_t len);
|
2024-09-02 15:47:39 -07:00
|
|
|
uint64_t Text$hash(Text_t *text);
|
|
|
|
int32_t Text$compare(const Text_t *a, const Text_t *b);
|
|
|
|
bool Text$equal(const Text_t *a, const Text_t *b);
|
|
|
|
bool Text$equal_ignoring_case(Text_t a, Text_t b);
|
|
|
|
Text_t Text$upper(Text_t text);
|
|
|
|
Text_t Text$lower(Text_t text);
|
|
|
|
Text_t Text$title(Text_t text);
|
|
|
|
Text_t Text$as_text(const void *text, bool colorize, const TypeInfo *info);
|
|
|
|
Text_t Text$quoted(Text_t str, bool colorize);
|
2024-09-03 20:16:45 -07:00
|
|
|
Text_t Text$replace(Text_t str, Pattern_t pat, Text_t replacement, Pattern_t backref_pat, bool recursive);
|
|
|
|
Text_t Text$replace_all(Text_t text, table_t replacements, Pattern_t backref_pat, bool recursive);
|
2024-09-03 10:19:41 -07:00
|
|
|
array_t Text$split(Text_t text, Pattern_t pattern);
|
|
|
|
Int_t Text$find(Text_t text, Pattern_t pattern, Int_t i, int64_t *match_length);
|
|
|
|
array_t Text$find_all(Text_t text, Pattern_t pattern);
|
|
|
|
bool Text$has(Text_t text, Pattern_t pattern);
|
2024-09-03 21:34:27 -07:00
|
|
|
bool Text$matches(Text_t text, Pattern_t pattern);
|
2024-09-02 15:47:39 -07:00
|
|
|
const char *Text$as_c_string(Text_t text);
|
|
|
|
public Text_t Text$format(const char *fmt, ...);
|
2024-09-02 17:22:13 -07:00
|
|
|
array_t Text$clusters(Text_t text);
|
|
|
|
array_t Text$utf32_codepoints(Text_t text);
|
|
|
|
array_t Text$utf8_bytes(Text_t text);
|
|
|
|
array_t Text$codepoint_names(Text_t text);
|
2024-09-02 19:30:19 -07:00
|
|
|
Text_t Text$from_codepoints(array_t codepoints);
|
|
|
|
Text_t Text$from_codepoint_names(array_t codepoint_names);
|
|
|
|
Text_t Text$from_bytes(array_t bytes);
|
2024-09-02 19:57:49 -07:00
|
|
|
array_t Text$lines(Text_t text);
|
2024-09-02 20:13:02 -07:00
|
|
|
Text_t Text$join(Text_t glue, array_t pieces);
|
2024-09-04 18:02:37 -07:00
|
|
|
Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn);
|
2024-03-29 09:54:31 -07:00
|
|
|
|
|
|
|
extern const TypeInfo $Text;
|
2024-03-03 15:15:45 -08:00
|
|
|
|
2024-09-03 21:18:03 -07:00
|
|
|
#define Pattern(text) ((Pattern_t)Text(text))
|
|
|
|
#define Patterns(...) ((Pattern_t)Texts(__VA_ARGS__))
|
2024-09-03 10:19:41 -07:00
|
|
|
Pattern_t Pattern$escape_text(Text_t text);
|
|
|
|
extern const TypeInfo Pattern;
|
|
|
|
|
2024-03-03 15:15:45 -08:00
|
|
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|