diff options
author | bosak <bosakmaw@gmail.com> | 2018-04-13 17:40:27 +0300 |
---|---|---|
committer | bosak <bosakmaw@gmail.com> | 2018-04-17 14:15:43 +0300 |
commit | 79ecdee49631c1571b6629005b73b0d9aa3dbc34 (patch) | |
tree | 37538bee3cc4d44ed95e6240e457dc7fe6d29c56 /core/ustring.cpp | |
parent | ab75fae5641675a2e9c8b38c3b40231a00bb428d (diff) | |
download | redot-engine-79ecdee49631c1571b6629005b73b0d9aa3dbc34.tar.gz |
add string trim_prefix trim_suffix lstrip and rstrip methods
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index d749146998..913c98e91e 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -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(); |