mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
add string trim_prefix trim_suffix lstrip and rstrip methods
This commit is contained in:
@@ -2997,6 +2997,40 @@ String String::strip_escapes() const {
|
||||
return substr(beg, end - beg);
|
||||
}
|
||||
|
||||
String String::lstrip(const Vector<CharType> &p_chars) const {
|
||||
|
||||
int len = length();
|
||||
int beg;
|
||||
|
||||
for (beg = 0; beg < len; beg++) {
|
||||
|
||||
if (p_chars.find(operator[](beg)) == -1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (beg == 0)
|
||||
return *this;
|
||||
|
||||
return substr(beg, len - beg);
|
||||
}
|
||||
|
||||
String String::rstrip(const Vector<CharType> &p_chars) const {
|
||||
|
||||
int len = length();
|
||||
int end;
|
||||
|
||||
for (end = len - 1; end >= 0; end--) {
|
||||
|
||||
if (p_chars.find(operator[](end)) == -1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (end == len - 1)
|
||||
return *this;
|
||||
|
||||
return substr(0, end + 1);
|
||||
}
|
||||
|
||||
String String::simplify_path() const {
|
||||
|
||||
String s = *this;
|
||||
@@ -3448,6 +3482,24 @@ String String::pad_zeros(int p_digits) const {
|
||||
return s;
|
||||
}
|
||||
|
||||
String String::trim_prefix(const String &p_prefix) const {
|
||||
|
||||
String s = *this;
|
||||
if (s.begins_with(p_prefix)) {
|
||||
return s.substr(p_prefix.length(), s.length() - p_prefix.length());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String String::trim_suffix(const String &p_suffix) const {
|
||||
|
||||
String s = *this;
|
||||
if (s.ends_with(p_suffix)) {
|
||||
return s.substr(0, s.length() - p_suffix.length());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
bool String::is_valid_integer() const {
|
||||
|
||||
int len = length();
|
||||
|
||||
Reference in New Issue
Block a user