summaryrefslogtreecommitdiff
path: root/core/ustring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp34
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 {