diff options
author | Noshyaar <poommetee@protonmail.com> | 2018-01-01 18:51:35 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-01 18:51:35 +0700 |
commit | a6328011d85ea285f974d354ce4e30cf8e3456de (patch) | |
tree | 05aa46a82702cd7440aa145b83a24b0b503bdeec /core/ustring.cpp | |
parent | 52deb679df547ea9634cf2cc337fa98905bb12fb (diff) | |
parent | b80bc553dd52259eee4c25eb7652020e75d9e814 (diff) | |
download | redot-engine-a6328011d85ea285f974d354ce4e30cf8e3456de.tar.gz |
Merge pull request #14973 from poke1024/docs-word-selection
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 261cc0778c..fc6312355a 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 { |