diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-09-24 11:50:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-24 11:50:58 +0200 |
commit | ef2a7834c9d3fbbd95a9d26ff2913e4b3c5d8f5f (patch) | |
tree | 3afbf1e30e213e0f0555aae1de1d28eb08d06cbf /core/ustring.cpp | |
parent | cefa56ef1fb1f700035bce5c7f005dab65b9dc81 (diff) | |
parent | 073f625a91969b93644321326e42bbc511348262 (diff) | |
download | redot-engine-ef2a7834c9d3fbbd95a9d26ff2913e4b3c5d8f5f.tar.gz |
Merge pull request #31883 from aole/create-string-function-repeat
Create a GDScript String function repeat
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index dee554716f..07caa3a018 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) |