summaryrefslogtreecommitdiffstats
path: root/core/ustring.cpp
diff options
context:
space:
mode:
authorBhupendra Aole <bhupendra.aole@gmail.com>2019-09-01 23:49:55 -0400
committerBhupendra Aole <aole@users.noreply.github.com>2019-09-03 13:06:13 -0400
commit073f625a91969b93644321326e42bbc511348262 (patch)
tree82d6051bd9822bee096dae383e48d2cb47959029 /core/ustring.cpp
parent00aabec8bb598592b8a8702797b51fc9f6ca6169 (diff)
downloadredot-engine-073f625a91969b93644321326e42bbc511348262.tar.gz
Create a GDScript String function repeat
Fixes #30610
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 3f5e198281..2f72a1f08e 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3049,6 +3049,22 @@ String String::replacen(const String &p_key, const String &p_with) const {
return new_string;
}
+String String::repeat(int p_count) const {
+
+ ERR_FAIL_COND_V_MSG(p_count < 0, "", "Parameter count should be a positive number.");
+
+ String new_string;
+ const CharType *src = this->c_str();
+
+ new_string.resize(length() * p_count + 1);
+
+ for (int i = 0; i < p_count; i++)
+ for (int j = 0; j < length(); j++)
+ new_string[i * length() + j] = src[j];
+
+ return new_string;
+}
+
String String::left(int p_pos) const {
if (p_pos <= 0)