diff options
| author | George Marques | 2016-06-12 00:25:01 -0300 |
|---|---|---|
| committer | George Marques | 2016-06-12 14:52:54 -0300 |
| commit | a6c37d2b5d058d3bad2a942d965564c5054424c5 (patch) | |
| tree | ad46111fbbbb07a23ed0c302ec4e47f96426562a /core/ustring.cpp | |
| parent | e8209b9c5cd40649e0ab87515d20b4aab6c9feb0 (diff) | |
| download | godot-a6c37d2b5d058d3bad2a942d965564c5054424c5.tar.gz godot-a6c37d2b5d058d3bad2a942d965564c5054424c5.tar.zst godot-a6c37d2b5d058d3bad2a942d965564c5054424c5.zip | |
Diffstat (limited to 'core/ustring.cpp')
| -rw-r--r-- | core/ustring.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index a039ba11c..309b9e08f 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2752,6 +2752,50 @@ bool String::begins_with(const char* p_string) const { } +bool String::is_subsequence_of(const String& p_string) const { + + return _base_is_subsequence_of(p_string, false); +} + +bool String::is_subsequence_ofi(const String& p_string) const { + + return _base_is_subsequence_of(p_string, true); +} + +bool String::_base_is_subsequence_of(const String& p_string, bool case_insensitive) const { + + int len=length(); + if (len == 0) { + // Technically an empty string is subsequence of any string + return true; + } + + if (len > p_string.length()) { + return false; + } + + const CharType *src = &operator[](0); + const CharType *tgt = &p_string[0]; + + for (;*src && *tgt;tgt++) { + bool match = false; + if (case_insensitive) { + CharType srcc = _find_lower(*src); + CharType tgtc = _find_lower(*tgt); + match = srcc == tgtc; + } else { + match = *src == *tgt; + } + if (match) { + src++; + if(!*src) { + return true; + } + } + } + + return false; +} static bool _wildcard_match(const CharType* p_pattern, const CharType* p_string,bool p_case_sensitive) { switch (*p_pattern) { |
