Change behavior of String.right

This commit is contained in:
Tomasz Chabora
2020-02-13 16:42:49 +01:00
committed by kobewi
parent 78d85de13b
commit b1859510ab
16 changed files with 57 additions and 36 deletions

View File

@ -3382,14 +3382,14 @@ String String::format(const Variant &values, String placeholder) const {
if (value_arr.size() == 2) {
Variant v_key = value_arr[0];
String key = v_key;
if (key.left(1) == "\"" && key.right(key.length() - 1) == "\"") {
if (key.left(1) == "\"" && key.right(1) == "\"") {
key = key.substr(1, key.length() - 2);
}
Variant v_val = value_arr[1];
String val = v_val;
if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") {
if (val.left(1) == "\"" && val.right(1) == "\"") {
val = val.substr(1, val.length() - 2);
}
@ -3401,7 +3401,7 @@ String String::format(const Variant &values, String placeholder) const {
Variant v_val = values_arr[i];
String val = v_val;
if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") {
if (val.left(1) == "\"" && val.right(1) == "\"") {
val = val.substr(1, val.length() - 2);
}
@ -3421,11 +3421,11 @@ String String::format(const Variant &values, String placeholder) const {
String key = E->get();
String val = d[E->get()];
if (key.left(1) == "\"" && key.right(key.length() - 1) == "\"") {
if (key.left(1) == "\"" && key.right(1) == "\"") {
key = key.substr(1, key.length() - 2);
}
if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") {
if (val.left(1) == "\"" && val.right(1) == "\"") {
val = val.substr(1, val.length() - 2);
}
@ -3529,6 +3529,10 @@ String String::repeat(int p_count) const {
}
String String::left(int p_pos) const {
if (p_pos < 0) {
p_pos = length() + p_pos;
}
if (p_pos <= 0) {
return "";
}
@ -3541,15 +3545,19 @@ String String::left(int p_pos) const {
}
String String::right(int p_pos) const {
if (p_pos >= length()) {
return "";
if (p_pos < 0) {
p_pos = length() + p_pos;
}
if (p_pos <= 0) {
return "";
}
if (p_pos >= length()) {
return *this;
}
return substr(p_pos, (length() - p_pos));
return substr(length() - p_pos);
}
char32_t String::unicode_at(int p_idx) const {