summaryrefslogtreecommitdiff
path: root/core/ustring.cpp
diff options
context:
space:
mode:
authorKostadin Damyanov <maxmight@gmail.com>2015-09-05 12:03:17 +0300
committerKostadin Damyanov <maxmight@gmail.com>2015-09-05 12:03:17 +0300
commitc5f574b914b3cb11d97ae616df4a0bced45bb17c (patch)
treed7b70f0842c00c480ce10039b873a1dddd894a6c /core/ustring.cpp
parent2a757a6ad4ef4e7767b7d3ef7e177ec6613ef6d1 (diff)
parentb0aa49accbd7e45dae38f1bd43b0fbdd11714211 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 3cfc1e4a3c..ff7c8984fa 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3048,6 +3048,37 @@ bool String::is_valid_identifier() const {
//kind of poor should be rewritten properly
+String String::world_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);
+ from=i+1;
+ last_space=-1;
+ }
+ }
+
+ if (from<length()) {
+ ret+=substr(from,length());
+ }
+
+ return ret;
+}
+
String String::c_unescape() const {
String escaped=*this;