summaryrefslogtreecommitdiffstats
path: root/core/string
diff options
context:
space:
mode:
authorSilicDev <83308290+SilicDev@users.noreply.github.com>2023-03-30 15:45:45 +0200
committerSilicDev <83308290+SilicDev@users.noreply.github.com>2023-05-04 00:52:35 +0200
commit6fa4f71ca686e68667f61185dcbe4ebb0f64af06 (patch)
treec951a82c9a481bad1cea96e81075f2760bdf697e /core/string
parent49a196277f86977d08cc10b6bb878427ae54a964 (diff)
downloadredot-engine-6fa4f71ca686e68667f61185dcbe4ebb0f64af06.tar.gz
Reimplement String.erase
Diffstat (limited to 'core/string')
-rw-r--r--core/string/ustring.cpp6
-rw-r--r--core/string/ustring.h1
2 files changed, 7 insertions, 0 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 773445edb6..ae8485fcbe 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -2840,6 +2840,12 @@ String String::insert(int p_at_pos, const String &p_string) const {
return pre + p_string + post;
}
+String String::erase(int p_pos, int p_chars) const {
+ ERR_FAIL_COND_V_MSG(p_pos < 0, "", vformat("Invalid starting position for `String.erase()`: %d. Starting position must be positive or zero.", p_pos));
+ ERR_FAIL_COND_V_MSG(p_chars < 0, "", vformat("Invalid character count for `String.erase()`: %d. Character count must be positive or zero.", p_chars));
+ return left(p_pos) + substr(p_pos + p_chars);
+}
+
String String::substr(int p_from, int p_chars) const {
if (p_chars == -1) {
p_chars = length() - p_from;
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 90034b1b07..42d97406bf 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -304,6 +304,7 @@ public:
String replacen(const String &p_key, const String &p_with) const;
String repeat(int p_count) const;
String insert(int p_at_pos, const String &p_string) const;
+ String erase(int p_pos, int p_chars = 1) const;
String pad_decimals(int p_digits) const;
String pad_zeros(int p_digits) const;
String trim_prefix(const String &p_prefix) const;