Add Text:join() and tests
This commit is contained in:
parent
6d7e09bf18
commit
6e4be93848
@ -1449,6 +1449,17 @@ public array_t Text$split(Text_t text, Text_t pattern)
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public Text_t Text$join(Text_t glue, array_t pieces)
|
||||
{
|
||||
if (pieces.length == 0) return (Text_t){.length=0};
|
||||
|
||||
Text_t result = *(Text_t*)pieces.data;
|
||||
for (int64_t i = 1; i < pieces.length; i++) {
|
||||
result = Text$concat(result, glue, *(Text_t*)(pieces.data + i*pieces.stride));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Text_t Text$format(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
@ -17,30 +17,6 @@ typedef struct {
|
||||
int32_t index;
|
||||
} find_result_t;
|
||||
|
||||
// CORD Text$as_text(const void *str, bool colorize, const TypeInfo *info);
|
||||
// CORD Text$quoted(CORD str, bool colorize);
|
||||
// // int Text$compare(const CORD *x, const CORD *y);
|
||||
// // bool Text$equal(const CORD *x, const CORD *y);
|
||||
// // uint32_t Text$hash(const 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_t where);
|
||||
// CORD Text$without(CORD str, CORD target, Where_t where);
|
||||
// CORD Text$trimmed(CORD str, CORD skip, Where_t where);
|
||||
// find_result_t Text$find(CORD str, CORD pat);
|
||||
// CORD Text$replace(CORD text, CORD pat, CORD replacement, Int_t limit);
|
||||
// array_t Text$split(CORD str, CORD split);
|
||||
// CORD Text$join(CORD glue, array_t pieces);
|
||||
// array_t Text$clusters(CORD text);
|
||||
// array_t Text$codepoints(CORD text);
|
||||
// array_t Text$bytes(CORD text);
|
||||
// Int_t Text$num_clusters(CORD text);
|
||||
// Int_t Text$num_codepoints(CORD text);
|
||||
// Int_t Text$num_bytes(CORD text);
|
||||
// array_t Text$character_names(CORD text);
|
||||
// CORD Text$read_line(CORD prompt);
|
||||
|
||||
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]);
|
||||
|
||||
@ -73,6 +49,7 @@ 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);
|
||||
array_t Text$lines(Text_t text);
|
||||
Text_t Text$join(Text_t glue, array_t pieces);
|
||||
|
||||
extern const TypeInfo $Text;
|
||||
|
||||
|
12
test/text.tm
12
test/text.tm
@ -140,3 +140,15 @@ func main():
|
||||
|
||||
>> "abc":split("")
|
||||
= ["a", "b", "c"]
|
||||
|
||||
>> ", ":join(["one", "two", "three"])
|
||||
= "one, two, three"
|
||||
|
||||
>> "":join(["one", "two", "three"])
|
||||
= "onetwothree"
|
||||
|
||||
>> "+":join(["one"])
|
||||
= "one"
|
||||
|
||||
>> "+":join([:Text])
|
||||
= ""
|
||||
|
Loading…
Reference in New Issue
Block a user