diff options
author | Bernhard Liebl <Bernhard.Liebl@gmx.org> | 2017-12-23 09:59:54 +0100 |
---|---|---|
committer | Bernhard Liebl <Bernhard.Liebl@gmx.org> | 2017-12-28 17:44:22 +0100 |
commit | b80bc553dd52259eee4c25eb7652020e75d9e814 (patch) | |
tree | 94c44db0f9d545b3ce2eb14ff224c29ce6e576da /core/ustring.cpp | |
parent | 32d8b99bc31e3762ae0dc017a05567da2802a313 (diff) | |
download | redot-engine-b80bc553dd52259eee4c25eb7652020e75d9e814.tar.gz |
Double-click word selection for RichTextLabel (i.e. docs)
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index ceafe209ea..ece3928298 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -56,6 +56,40 @@ #define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9') #define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F')) +bool is_symbol(CharType c) { + return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' '); +} + +bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) { + + const String &s = p_s; + int beg = CLAMP(p_col, 0, s.length()); + int end = beg; + + if (s[beg] > 32 || beg == s.length()) { + + bool symbol = beg < s.length() && is_symbol(s[beg]); + + while (beg > 0 && s[beg - 1] > 32 && (symbol == is_symbol(s[beg - 1]))) { + beg--; + } + while (end < s.length() && s[end + 1] > 32 && (symbol == is_symbol(s[end + 1]))) { + end++; + } + + if (end < s.length()) + end += 1; + + r_beg = beg; + r_end = end; + + return true; + } else { + + return false; + } +} + /** STRING **/ bool CharString::operator<(const CharString &p_right) const { |