diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 18:15:45 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 18:15:45 -0500 |
| commit | 8fab88c56f95c03ffcb4be178f5dbb21b239d95e (patch) | |
| tree | 3c2e721b8ea55d43b94fa9f315659580652573c5 /builtins | |
| parent | 07f0a18136a7883d1f3edd3e08253bd3020294a8 (diff) | |
Rename Str -> Text
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/string.h | 36 | ||||
| -rw-r--r-- | builtins/table.c | 4 | ||||
| -rw-r--r-- | builtins/text.c (renamed from builtins/string.c) | 46 | ||||
| -rw-r--r-- | builtins/text.h | 35 |
4 files changed, 60 insertions, 61 deletions
diff --git a/builtins/string.h b/builtins/string.h deleted file mode 100644 index c24de72d..00000000 --- a/builtins/string.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include <gc/cord.h> -#include <stdbool.h> -#include <stdint.h> - -#include "types.h" - -#define String_t CORD -#define Str_t CORD - -typedef enum { WHERE_ANYWHERE, WHERE_START, WHERE_END } where_e; - -typedef struct { - enum { FIND_FAILURE, FIND_SUCCESS } status; - int32_t index; -} find_result_t; - -CORD Str__as_str(const void *str, bool colorize, const TypeInfo *info); -CORD Str__quoted(CORD str, bool colorize); -int Str__compare(CORD *x, CORD *y); -bool Str__equal(CORD *x, CORD *y); -uint32_t Str__hash(CORD *cord); -CORD Str__upper(CORD str); -CORD Str__lower(CORD str); -CORD Str__title(CORD str); -bool Str__has(CORD str, CORD target, where_e where); -CORD Str__without(CORD str, CORD target, where_e where); -CORD Str__trimmed(CORD str, CORD skip, where_e where); -find_result_t Str__find(CORD str, CORD pat); -CORD Str__replace(CORD text, CORD pat, CORD replacement, int64_t limit); -array_t Str__split(CORD str, CORD split); -CORD Str__join(CORD glue, array_t pieces); - -extern const TypeInfo Str; - -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/table.c b/builtins/table.c index fcb64e40..523aae70 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -21,7 +21,7 @@ #include "../util.h" #include "array.h" #include "datatypes.h" -#include "string.h" +#include "text.h" #include "table.h" #include "types.h" @@ -55,7 +55,7 @@ TypeInfo StrToVoidStarTable = { .size=sizeof(table_t), .align=__alignof__(table_t), .tag=TableInfo, - .TableInfo={.key=&Str, .value=&MemoryPointer}, + .TableInfo={.key=&Text, .value=&MemoryPointer}, }; static inline size_t entry_size(const TypeInfo *info) diff --git a/builtins/string.c b/builtins/text.c index c28aa510..d85c03f0 100644 --- a/builtins/string.c +++ b/builtins/text.c @@ -14,18 +14,18 @@ #include "../SipHash/halfsiphash.h" #include "types.h" #include "array.h" -#include "string.h" +#include "text.h" #define CLAMP(x, lo, hi) MIN(hi, MAX(x,lo)) -public CORD Str__as_str(const void *str, bool colorize, const TypeInfo *info) +public CORD Text__as_str(const void *str, bool colorize, const TypeInfo *info) { (void)info; - if (!str) return "Str"; - return Str__quoted(*(CORD*)str, colorize); + if (!str) return "Text"; + return Text__quoted(*(CORD*)str, colorize); } -public CORD Str__quoted(CORD str, bool colorize) +public CORD Text__quoted(CORD str, bool colorize) { // Note: it's important to have unicode strings not get broken up with // escapes, otherwise they won't print right. @@ -84,17 +84,17 @@ public CORD Str__quoted(CORD str, bool colorize) } } -public int Str__compare(CORD *x, CORD *y) +public int Text__compare(CORD *x, CORD *y) { return CORD_cmp(*x, *y); } -public bool Str__equal(CORD *x, CORD *y) +public bool Text__equal(CORD *x, CORD *y) { return CORD_cmp(*x, *y) == 0; } -public uint32_t Str__hash(CORD *cord) +public uint32_t Text__hash(CORD *cord) { if (!*cord) return 0; @@ -106,7 +106,7 @@ public uint32_t Str__hash(CORD *cord) return hash; } -public CORD Str__upper(CORD str) +public CORD Text__upper(CORD str) { if (!str) return str; size_t len = strlen(str) + 1; @@ -114,7 +114,7 @@ public CORD Str__upper(CORD str) return (CORD)u8_toupper((const uint8_t*)str, len-1, uc_locale_language(), NULL, dest, &len); } -public CORD Str__lower(CORD str) +public CORD Text__lower(CORD str) { if (!str) return str; size_t len = strlen(str) + 1; @@ -122,7 +122,7 @@ public CORD Str__lower(CORD str) return (CORD)u8_tolower((const uint8_t*)str, len-1, uc_locale_language(), NULL, dest, &len); } -public CORD Str__title(CORD str) +public CORD Text__title(CORD str) { if (!str) return str; size_t len = strlen(str) + 1; @@ -130,7 +130,7 @@ public CORD Str__title(CORD str) return (CORD)u8_totitle((const uint8_t*)str, len-1, uc_locale_language(), NULL, dest, &len); } -public bool Str__has(CORD str, CORD target, where_e where) +public bool Text__has(CORD str, CORD target, where_e where) { if (!target) return true; if (!str) return false; @@ -147,7 +147,7 @@ public bool Str__has(CORD str, CORD target, where_e where) } } -public CORD Str__without(CORD str, CORD target, where_e where) +public CORD Text__without(CORD str, CORD target, where_e where) { if (!str || !target) return str; @@ -166,7 +166,7 @@ public CORD Str__without(CORD str, CORD target, where_e where) } } -public CORD Str__trimmed(CORD str, CORD skip, where_e where) +public CORD Text__trimmed(CORD str, CORD skip, where_e where) { if (!str || !skip) return str; const uint8_t *ustr = (const uint8_t*)CORD_to_const_char_star(str); @@ -192,14 +192,14 @@ public CORD Str__trimmed(CORD str, CORD skip, where_e where) } } -public find_result_t Str__find(CORD str, CORD pat) +public find_result_t Text__find(CORD str, CORD pat) { if (!pat) return (find_result_t){.status=FIND_SUCCESS, .index=1}; size_t pos = CORD_str(str, 0, pat); return (pos == CORD_NOT_FOUND) ? (find_result_t){.status=FIND_FAILURE} : (find_result_t){.status=FIND_SUCCESS, .index=(int32_t)pos}; } -public CORD Str__replace(CORD text, CORD pat, CORD replacement, int64_t limit) +public CORD Text__replace(CORD text, CORD pat, CORD replacement, int64_t limit) { if (!text || !pat) return text; CORD ret = NULL; @@ -212,7 +212,7 @@ public CORD Str__replace(CORD text, CORD pat, CORD replacement, int64_t limit) return CORD_cat(ret, CORD_substr(text, pos, SIZE_MAX)); } -public array_t Str__split(CORD str, CORD split) +public array_t Text__split(CORD str, CORD split) { if (!str) return (array_t){.data=GC_MALLOC(sizeof(CORD)), .atomic=1, .length=1, .stride=sizeof(CORD)}; array_t strings = {.stride=sizeof(CORD), .atomic=1}; @@ -236,7 +236,7 @@ public array_t Str__split(CORD str, CORD split) return strings; } -public CORD Str__join(CORD glue, array_t pieces) +public CORD Text__join(CORD glue, array_t pieces) { if (pieces.length == 0) return CORD_EMPTY; @@ -248,15 +248,15 @@ public CORD Str__join(CORD glue, array_t pieces) return ret; } -public const TypeInfo Str = { +public const TypeInfo Text = { .size=sizeof(CORD), .align=__alignof__(CORD), .tag=CustomInfo, .CustomInfo={ - .as_str=(void*)Str__as_str, - .compare=(void*)Str__compare, - .equal=(void*)Str__equal, - .hash=(void*)Str__hash, + .as_str=(void*)Text__as_str, + .compare=(void*)Text__compare, + .equal=(void*)Text__equal, + .hash=(void*)Text__hash, }, }; diff --git a/builtins/text.h b/builtins/text.h new file mode 100644 index 00000000..a8782d24 --- /dev/null +++ b/builtins/text.h @@ -0,0 +1,35 @@ +#pragma once +#include <gc/cord.h> +#include <stdbool.h> +#include <stdint.h> + +#include "types.h" + +#define Text_t CORD + +typedef enum { WHERE_ANYWHERE, WHERE_START, WHERE_END } where_e; + +typedef struct { + enum { FIND_FAILURE, FIND_SUCCESS } status; + int32_t index; +} find_result_t; + +CORD Text__as_str(const void *str, bool colorize, const TypeInfo *info); +CORD Text__quoted(CORD str, bool colorize); +int Text__compare(CORD *x, CORD *y); +bool Text__equal(CORD *x, CORD *y); +uint32_t Text__hash(CORD *cord); +CORD Text__upper(CORD str); +CORD Text__lower(CORD str); +CORD Text__title(CORD str); +bool Text__has(CORD str, CORD target, where_e where); +CORD Text__without(CORD str, CORD target, where_e where); +CORD Text__trimmed(CORD str, CORD skip, where_e where); +find_result_t Text__find(CORD str, CORD pat); +CORD Text__replace(CORD text, CORD pat, CORD replacement, int64_t limit); +array_t Text__split(CORD str, CORD split); +CORD Text__join(CORD glue, array_t pieces); + +extern const TypeInfo Text; + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
