diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-19 12:43:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-19 12:43:46 +0200 |
commit | 2b52cd3e5c82bfb21774f8f850e2724da2baf234 (patch) | |
tree | f14b4d4260800b99635a6e1f2555a38d9ad38733 /core | |
parent | bb0aeb48741033f80f7576bd138189931ffbaa62 (diff) | |
parent | 0b8a785539ce7823855944aeff33aad3773aad6a (diff) |
Merge pull request #28648 from KoBeWi/substr-1
Make second parameter of substr optional
Diffstat (limited to 'core')
-rw-r--r-- | core/ustring.cpp | 3 | ||||
-rw-r--r-- | core/ustring.h | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 2 |
3 files changed, 5 insertions, 2 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 35b817b1d2..686aa6f8e3 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2331,6 +2331,9 @@ String String::insert(int p_at_pos, const String &p_string) const { } String String::substr(int p_from, int p_chars) const { + if (p_chars == -1) + p_chars = length() - p_from; + if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0) return ""; diff --git a/core/ustring.h b/core/ustring.h index 5b9be9f27c..ecf934a26b 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -201,7 +201,7 @@ public: } /* complex helpers */ - String substr(int p_from, int p_chars) const; + String substr(int p_from, int p_chars = -1) const; int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed int find_char(const CharType &p_char, int p_from = 0) const; ///< return <0 if failed diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 5d5f18926f..dc28f1ca02 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1499,7 +1499,7 @@ void register_variant_methods() { ADDFUNC1R(STRING, INT, String, casecmp_to, STRING, "to", varray()); ADDFUNC1R(STRING, INT, String, nocasecmp_to, STRING, "to", varray()); ADDFUNC0R(STRING, INT, String, length, varray()); - ADDFUNC2R(STRING, STRING, String, substr, INT, "from", INT, "len", varray()); + ADDFUNC2R(STRING, STRING, String, substr, INT, "from", INT, "len", varray(-1)); ADDFUNC2R(STRING, INT, String, find, STRING, "what", INT, "from", varray(0)); |