Use String.repeat() in more places
This commit is contained in:
parent
10d22a4b35
commit
6b84e258d2
12 changed files with 37 additions and 94 deletions
|
|
@ -909,18 +909,11 @@ String TranslationServer::wrap_with_fakebidi_characters(String &p_message) const
|
|||
}
|
||||
|
||||
String TranslationServer::add_padding(const String &p_message, int p_length) const {
|
||||
String res;
|
||||
String prefix = pseudolocalization_prefix;
|
||||
String suffix;
|
||||
for (int i = 0; i < p_length * expansion_ratio / 2; i++) {
|
||||
prefix += "_";
|
||||
suffix += "_";
|
||||
}
|
||||
suffix += pseudolocalization_suffix;
|
||||
res += prefix;
|
||||
res += p_message;
|
||||
res += suffix;
|
||||
return res;
|
||||
String underscores = String("_").repeat(p_length * expansion_ratio / 2);
|
||||
String prefix = pseudolocalization_prefix + underscores;
|
||||
String suffix = underscores + pseudolocalization_suffix;
|
||||
|
||||
return prefix + p_message + suffix;
|
||||
}
|
||||
|
||||
const char32_t *TranslationServer::get_accented_version(char32_t p_character) const {
|
||||
|
|
|
|||
|
|
@ -3470,6 +3470,14 @@ String String::replacen(const String &p_key, const String &p_with) const {
|
|||
String String::repeat(int p_count) const {
|
||||
ERR_FAIL_COND_V_MSG(p_count < 0, "", "Parameter count should be a positive number.");
|
||||
|
||||
if (p_count == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (p_count == 1) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
int len = length();
|
||||
String new_string = *this;
|
||||
new_string.resize(p_count * len + 1);
|
||||
|
|
@ -4107,13 +4115,11 @@ String String::pad_decimals(int p_digits) const {
|
|||
}
|
||||
|
||||
if (s.length() - (c + 1) > p_digits) {
|
||||
s = s.substr(0, c + p_digits + 1);
|
||||
return s.substr(0, c + p_digits + 1);
|
||||
} else {
|
||||
while (s.length() - (c + 1) < p_digits) {
|
||||
s += "0";
|
||||
}
|
||||
int zeros_to_add = p_digits - s.length() + (c + 1);
|
||||
return s + String("0").repeat(zeros_to_add);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String String::pad_zeros(int p_digits) const {
|
||||
|
|
@ -4138,12 +4144,8 @@ String String::pad_zeros(int p_digits) const {
|
|||
return s;
|
||||
}
|
||||
|
||||
while (end - begin < p_digits) {
|
||||
s = s.insert(begin, "0");
|
||||
end++;
|
||||
}
|
||||
|
||||
return s;
|
||||
int zeros_to_add = p_digits - (end - begin);
|
||||
return s.insert(begin, String("0").repeat(zeros_to_add));
|
||||
}
|
||||
|
||||
String String::trim_prefix(const String &p_prefix) const {
|
||||
|
|
@ -4322,11 +4324,8 @@ String String::path_to(const String &p_path) const {
|
|||
|
||||
common_parent--;
|
||||
|
||||
String dir;
|
||||
|
||||
for (int i = src_dirs.size() - 1; i > common_parent; i--) {
|
||||
dir += "../";
|
||||
}
|
||||
int dirs_to_backtrack = (src_dirs.size() - 1) - common_parent;
|
||||
String dir = String("../").repeat(dirs_to_backtrack);
|
||||
|
||||
for (int i = common_parent + 1; i < dst_dirs.size(); i++) {
|
||||
dir += dst_dirs[i] + "/";
|
||||
|
|
@ -4547,11 +4546,8 @@ String String::rpad(int min_length, const String &character) const {
|
|||
String s = *this;
|
||||
int padding = min_length - s.length();
|
||||
if (padding > 0) {
|
||||
for (int i = 0; i < padding; i++) {
|
||||
s = s + character;
|
||||
}
|
||||
s += character.repeat(padding);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
@ -4560,11 +4556,8 @@ String String::lpad(int min_length, const String &character) const {
|
|||
String s = *this;
|
||||
int padding = min_length - s.length();
|
||||
if (padding > 0) {
|
||||
for (int i = 0; i < padding; i++) {
|
||||
s = character + s;
|
||||
}
|
||||
s = character.repeat(padding) + s;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue