From c5c3be9e5d74cda08df2c36412e0a652f1433d4f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 20 May 2024 15:27:42 -0400 Subject: [PATCH] Deprecate Text.slice() --- builtins/text.c | 15 --------------- builtins/text.h | 1 - environment.c | 33 ++++++++++++++++----------------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/builtins/text.c b/builtins/text.c index a316192..e8c476a 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -128,21 +128,6 @@ public uint32_t Text$hash(const CORD *cord) return hash; } -public CORD Text$slice(CORD text, int64_t first, int64_t length) -{ - if (length == 0) return CORD_EMPTY; - int64_t len = CORD_len(text); - - if (length < -len) return CORD_EMPTY; - - if (first <= 0) first = len + first + 1; - if (first < 1) first = 1; - else if (first > len + 1) first = len + 1; - - if (length < 0) length = len + length; - return CORD_substr(text, first - 1, length); -} - public CORD Text$upper(CORD str) { if (!str) return str; diff --git a/builtins/text.h b/builtins/text.h index e97c401..d738125 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -22,7 +22,6 @@ 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$slice(CORD text, int64_t first, int64_t length); CORD Text$upper(CORD str); CORD Text$lower(CORD str); CORD Text$title(CORD str); diff --git a/environment.c b/environment.c index 03c592e..d5f6a15 100644 --- a/environment.c +++ b/environment.c @@ -174,28 +174,27 @@ env_t *new_compilation_unit(void) #undef C {"Where", where, "Where_t", "Where", {}}, {"Text", TEXT_TYPE, "Text_t", "$Text", TypedArray(ns_entry_t, - {"slice", "Text$slice", "func(text:Text, index:Int, length=Int.max)->Text"}, - {"quoted", "Text$quoted", "func(text:Text, color=no)->Text"}, - {"upper", "Text$upper", "func(text:Text)->Text"}, - {"lower", "Text$lower", "func(text:Text)->Text"}, - {"title", "Text$title", "func(text:Text)->Text"}, - {"as_c_string", "CORD_to_char_star", "func(text:Text)->CString"}, - {"from_c_string", "CORD_from_char_star", "func(str:CString)->Text"}, - {"has", "Text$has", "func(text:Text, target:Text, where=Where.Anywhere)->Bool"}, - {"without", "Text$without", "func(text:Text, target:Text, where=Where.Anywhere)->Text"}, - {"trimmed", "Text$trimmed", "func(text:Text, trim=\" {\\n\\r\\t}\", where=Where.Anywhere)->Text"}, - {"title", "Text$title", "func(text:Text)->Text"}, // {"find", "Text$find", "func(text:Text, pattern:Text)->FindResult"}, - {"replace", "Text$replace", "func(text:Text, pattern:Text, replacement:Text, limit=Int.max)->Text"}, - {"split", "Text$split", "func(text:Text, split:Text)->[Text]"}, - {"join", "Text$join", "func(glue:Text, pieces:[Text])->Text"}, + {"as_c_string", "CORD_to_char_star", "func(text:Text)->CString"}, + {"bytes", "Text$bytes", "func(text:Text)->[Int8]"}, + {"character_names", "Text$character_names", "func(text:Text)->[Text]"}, {"clusters", "Text$clusters", "func(text:Text)->[Text]"}, {"codepoints", "Text$codepoints", "func(text:Text)->[Int32]"}, - {"bytes", "Text$bytes", "func(text:Text)->[Int8]"}, + {"from_c_string", "CORD_from_char_star", "func(str:CString)->Text"}, + {"has", "Text$has", "func(text:Text, target:Text, where=Where.Anywhere)->Bool"}, + {"join", "Text$join", "func(glue:Text, pieces:[Text])->Text"}, + {"lower", "Text$lower", "func(text:Text)->Text"}, + {"num_bytes", "Text$num_bytes", "func(text:Text)->Int"}, {"num_clusters", "Text$num_clusters", "func(text:Text)->Int"}, {"num_codepoints", "Text$num_codepoints", "func(text:Text)->Int"}, - {"num_bytes", "Text$num_bytes", "func(text:Text)->Int"}, - {"character_names", "Text$character_names", "func(text:Text)->[Text]"}, + {"quoted", "Text$quoted", "func(text:Text, color=no)->Text"}, + {"replace", "Text$replace", "func(text:Text, pattern:Text, replacement:Text, limit=Int.max)->Text"}, + {"split", "Text$split", "func(text:Text, split:Text)->[Text]"}, + {"title", "Text$title", "func(text:Text)->Text"}, + {"title", "Text$title", "func(text:Text)->Text"}, + {"trimmed", "Text$trimmed", "func(text:Text, trim=\" {\\n\\r\\t}\", where=Where.Anywhere)->Text"}, + {"upper", "Text$upper", "func(text:Text)->Text"}, + {"without", "Text$without", "func(text:Text, target:Text, where=Where.Anywhere)->Text"}, )}, };