diff options
author | Vedat Günel <gunel15@itu.edu.tr> | 2021-01-19 15:14:25 +0300 |
---|---|---|
committer | Vedat Günel <gunel15@itu.edu.tr> | 2021-01-19 15:33:41 +0300 |
commit | 1d0437c95b7d91ad91b9cd14026b7c7996ef9358 (patch) | |
tree | c509a3564fa4b30eb40a0bef2b1077c117c6eaf2 /core | |
parent | 7dea83c623eded9ddcdbbb0bbaa7e8229c5ec74f (diff) |
Fix String.ends_with() for empty string arguments
Diffstat (limited to 'core')
-rw-r--r-- | core/string/ustring.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 21336a99ec..6b6d0a8ab4 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3074,11 +3074,16 @@ int String::rfindn(const String &p_str, int p_from) const { } bool String::ends_with(const String &p_string) const { + int l = p_string.length(); + if (l == 0) { + return true; + } + int pos = rfind(p_string); if (pos == -1) { return false; } - return pos + p_string.length() == length(); + return pos + l == length(); } bool String::begins_with(const String &p_string) const { |