summaryrefslogtreecommitdiff
path: root/core/string
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2022-08-18 16:20:20 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-12-16 13:18:57 +0800
commit207e52c161a44869f1af022030c3129b8c38a5f7 (patch)
tree3df831f12e9ded2b734b37d61837d2a35afbf685 /core/string
parentf18f2740da9cce7383c2aa41fe8d081d56c8b6cf (diff)
Fix String::word_wrap() for long words
- Changes `TextServer.string_get_word_breaks()` - Returns pairs of boundary start and end offsets - Accepts `chars_per_line` to return line breaks - Removes `String::word_wrap()` Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
Diffstat (limited to 'core/string')
-rw-r--r--core/string/ustring.cpp31
-rw-r--r--core/string/ustring.h1
2 files changed, 0 insertions, 32 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 4e26b61334..adab6d07c7 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -220,37 +220,6 @@ void CharString::copy_from(const char *p_cstr) {
/* String */
/*************************************************************************/
-//kind of poor should be rewritten properly
-String String::word_wrap(int p_chars_per_line) const {
- int from = 0;
- int last_space = 0;
- String ret;
- for (int i = 0; i < length(); i++) {
- if (i - from >= p_chars_per_line) {
- if (last_space == -1) {
- ret += substr(from, i - from + 1) + "\n";
- } else {
- ret += substr(from, last_space - from) + "\n";
- i = last_space; //rewind
- }
- from = i + 1;
- last_space = -1;
- } else if (operator[](i) == ' ' || operator[](i) == '\t') {
- last_space = i;
- } else if (operator[](i) == '\n') {
- ret += substr(from, i - from) + "\n";
- from = i + 1;
- last_space = -1;
- }
- }
-
- if (from < length()) {
- ret += substr(from, length());
- }
-
- return ret;
-}
-
Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const {
// Splits the URL into scheme, host, port, path. Strip credentials when present.
String base = *this;
diff --git a/core/string/ustring.h b/core/string/ustring.h
index ed3848fb8a..559f679f0f 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -425,7 +425,6 @@ public:
String c_escape_multiline() const;
String c_unescape() const;
String json_escape() const;
- String word_wrap(int p_chars_per_line) const;
Error parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const;
String property_name_encode() const;