diff options
author | Unknown <m.hilbrunner@gmail.com> | 2017-10-28 23:46:20 +0200 |
---|---|---|
committer | mhilbrunner <m.hilbrunner@gmail.com> | 2017-10-30 21:58:32 +0100 |
commit | 7683ff3e42539a24bc333573e271e2ae77eb5c61 (patch) | |
tree | b5cb42d625f0da9b1bf565e85cc08703ef78aa1f /core | |
parent | c93a3c1bd90c3416048e41328e7d787419828722 (diff) |
Fix get_node() and $ autocompletion when using single quotes
Diffstat (limited to 'core')
-rw-r--r-- | core/ustring.cpp | 22 | ||||
-rw-r--r-- | core/ustring.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index b85996e3d1..80881f1adb 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2476,6 +2476,11 @@ bool String::begins_with(const char *p_string) const { return *p_string == 0; } +bool String::is_enclosed_in(const String &p_string) const { + + return begins_with(p_string) && ends_with(p_string); +} + bool String::is_subsequence_of(const String &p_string) const { return _base_is_subsequence_of(p_string, false); @@ -2486,6 +2491,11 @@ bool String::is_subsequence_ofi(const String &p_string) const { return _base_is_subsequence_of(p_string, true); } +bool String::is_quoted() const { + + return is_enclosed_in("\"") || is_enclosed_in("'"); +} + bool String::_base_is_subsequence_of(const String &p_string, bool case_insensitive) const { int len = length(); @@ -3906,6 +3916,18 @@ String String::sprintf(const Array &values, bool *error) const { return formatted; } +String String::quote(String quotechar) const { + return quotechar + *this + quotechar; +} + +String String::unquote() const { + if (!is_quoted()) { + return *this; + } + + return substr(1, length() - 2); +} + #include "translation.h" #ifdef TOOLS_ENABLED diff --git a/core/ustring.h b/core/ustring.h index ab4e325f2c..aa4a5c910d 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -118,8 +118,10 @@ public: bool begins_with(const String &p_string) const; bool begins_with(const char *p_string) const; bool ends_with(const String &p_string) const; + bool is_enclosed_in(const String &p_string) const; bool is_subsequence_of(const String &p_string) const; bool is_subsequence_ofi(const String &p_string) const; + bool is_quoted() const; Vector<String> bigrams() const; float similarity(const String &p_string) const; String format(const Variant &values, String placeholder = "{_}") const; @@ -132,6 +134,8 @@ public: String lpad(int min_length, const String &character = " ") const; String rpad(int min_length, const String &character = " ") const; String sprintf(const Array &values, bool *error) const; + String quote(String quotechar = "\"") const; + String unquote() const; static String num(double p_num, int p_decimals = -1); static String num_scientific(double p_num); static String num_real(double p_num); |