summaryrefslogtreecommitdiff
path: root/core/ustring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp99
1 files changed, 39 insertions, 60 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index ceafe209ea..11d83a5733 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -56,34 +56,49 @@
#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'))
-/** STRING **/
+bool is_symbol(CharType c) {
+ return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
+}
-bool CharString::operator<(const CharString &p_right) const {
+bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
- if (length() == 0) {
- return p_right.length() != 0;
+ 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;
}
+}
- const char *this_str = get_data();
- const char *that_str = p_right.get_data();
- while (true) {
+/** STRING **/
- if (*that_str == 0 && *this_str == 0)
- return false; //this can't be equal, sadly
- else if (*this_str == 0)
- return true; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*that_str == 0)
- return false; //otherwise the other one is smaller..
- else if (*this_str < *that_str) //more than
- return true;
- else if (*this_str > *that_str) //less than
- return false;
+bool CharString::operator<(const CharString &p_right) const {
- this_str++;
- that_str++;
+ if (length() == 0) {
+ return p_right.length() != 0;
}
- return false; //should never reach here anyway
+ return is_str_less(get_data(), p_right.get_data());
}
const char *CharString::get_data() const {
@@ -372,25 +387,7 @@ bool String::operator<(const CharType *p_str) const {
if (empty())
return true;
- const CharType *this_str = c_str();
- while (true) {
-
- if (*p_str == 0 && *this_str == 0)
- return false; //this can't be equal, sadly
- else if (*this_str == 0)
- return true; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*p_str == 0)
- return false; //otherwise the other one is smaller..
- else if (*this_str < *p_str) //more than
- return true;
- else if (*this_str > *p_str) //less than
- return false;
-
- this_str++;
- p_str++;
- }
-
- return false; //should never reach here anyway
+ return is_str_less(c_str(), p_str);
}
bool String::operator<=(const String &p_str) const {
@@ -405,25 +402,7 @@ bool String::operator<(const char *p_str) const {
if (empty())
return true;
- const CharType *this_str = c_str();
- while (true) {
-
- if (*p_str == 0 && *this_str == 0)
- return false; //this can't be equal, sadly
- else if (*this_str == 0)
- return true; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*p_str == 0)
- return false; //otherwise the other one is smaller..
- else if (*this_str < *p_str) //more than
- return true;
- else if (*this_str > *p_str) //less than
- return false;
-
- this_str++;
- p_str++;
- }
-
- return false; //should never reach here anyway
+ return is_str_less(c_str(), p_str);
}
bool String::operator<(const String &p_str) const {