Merge pull request #31883 from aole/create-string-function-repeat
Create a GDScript String function repeat
This commit is contained in:
commit
ef2a7834c9
4 changed files with 28 additions and 0 deletions
|
@ -3049,6 +3049,22 @@ String String::replacen(const String &p_key, const String &p_with) const {
|
||||||
return new_string;
|
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 {
|
String String::left(int p_pos) const {
|
||||||
|
|
||||||
if (p_pos <= 0)
|
if (p_pos <= 0)
|
||||||
|
|
|
@ -223,6 +223,7 @@ public:
|
||||||
String replace(const String &p_key, const String &p_with) const;
|
String replace(const String &p_key, const String &p_with) const;
|
||||||
String replace(const char *p_key, const char *p_with) const;
|
String replace(const char *p_key, const char *p_with) const;
|
||||||
String replacen(const String &p_key, const String &p_with) const;
|
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 insert(int p_at_pos, const String &p_string) const;
|
||||||
String pad_decimals(int p_digits) const;
|
String pad_decimals(int p_digits) const;
|
||||||
String pad_zeros(int p_digits) const;
|
String pad_zeros(int p_digits) const;
|
||||||
|
|
|
@ -256,6 +256,7 @@ struct _VariantCall {
|
||||||
VCALL_LOCALMEM2R(String, format);
|
VCALL_LOCALMEM2R(String, format);
|
||||||
VCALL_LOCALMEM2R(String, replace);
|
VCALL_LOCALMEM2R(String, replace);
|
||||||
VCALL_LOCALMEM2R(String, replacen);
|
VCALL_LOCALMEM2R(String, replacen);
|
||||||
|
VCALL_LOCALMEM1R(String, repeat);
|
||||||
VCALL_LOCALMEM2R(String, insert);
|
VCALL_LOCALMEM2R(String, insert);
|
||||||
VCALL_LOCALMEM0R(String, capitalize);
|
VCALL_LOCALMEM0R(String, capitalize);
|
||||||
VCALL_LOCALMEM3R(String, split);
|
VCALL_LOCALMEM3R(String, split);
|
||||||
|
@ -1530,6 +1531,7 @@ void register_variant_methods() {
|
||||||
ADDFUNC2R(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
|
ADDFUNC2R(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
|
||||||
ADDFUNC2R(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
|
ADDFUNC2R(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
|
||||||
ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
|
ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
|
||||||
|
ADDFUNC1R(STRING, STRING, String, repeat, INT, "count", varray());
|
||||||
ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
|
ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
|
||||||
ADDFUNC0R(STRING, STRING, String, capitalize, varray());
|
ADDFUNC0R(STRING, STRING, String, capitalize, varray());
|
||||||
ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
|
ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
|
||||||
|
|
|
@ -677,6 +677,15 @@
|
||||||
Replaces occurrences of a case-insensitive substring with the given one inside the string.
|
Replaces occurrences of a case-insensitive substring with the given one inside the string.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="repeat">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="count" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns original string repeated a number of times. The number of repetitions is given by the argument.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="rfind">
|
<method name="rfind">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
|
|
Loading…
Reference in a new issue