diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-05-31 15:27:53 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2019-05-31 15:49:14 +0200 |
commit | af2c742f531e6d998c69286ad162b60b42c842c1 (patch) | |
tree | 7628dcb8538b7d8fc0adf081248e0cf6e566762f /core/ustring.cpp | |
parent | 29645c81476cb2f843f36070533281ba275f9400 (diff) | |
download | redot-engine-af2c742f531e6d998c69286ad162b60b42c842c1.tar.gz |
Fix and expose String::strip_escapes(), use it in LineEdit paste
Supersedes #27736.
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 954c39c150..88b758e883 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3102,29 +3102,16 @@ String String::strip_edges(bool left, bool right) const { String String::strip_escapes() const { - int len = length(); - int beg = 0, end = len; - + String new_string; for (int i = 0; i < length(); i++) { - if (operator[](i) <= 31) - beg++; - else - break; - } - - for (int i = (int)(length() - 1); i >= 0; i--) { - - if (operator[](i) <= 31) - end--; - else - break; + // Escape characters on first page of the ASCII table, before 32 (Space). + if (operator[](i) < 32) + continue; + new_string += operator[](i); } - if (beg == 0 && end == len) - return *this; - - return substr(beg, end - beg); + return new_string; } String String::lstrip(const String &p_chars) const { |