diff options
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index a9d0012ebe..a039ba11cd 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2867,25 +2867,29 @@ CharType String::ord_at(int p_idx) const { return operator[](p_idx); } -String String::strip_edges() const { +String String::strip_edges(bool left, bool right) const { int len=length(); int beg=0,end=len; - for (int i=0;i<length();i++) { + if(left) { + for (int i=0;i<len;i++) { - if (operator[](i)<=32) - beg++; - else - break; + if (operator[](i)<=32) + beg++; + else + break; + } } - for (int i=(int)(length()-1);i>=0;i--) { + if(right) { + for (int i=(int)(len-1);i>=0;i--) { - if (operator[](i)<=32) - end--; - else - break; + if (operator[](i)<=32) + end--; + else + break; + } } if (beg==0 && end==len) @@ -3629,13 +3633,14 @@ String String::percent_decode() const { CharString pe; - for(int i=0;i<length();i++) { + CharString cs = utf8(); + for(int i=0;i<cs.length();i++) { - uint8_t c=operator[](i); + uint8_t c = cs[i]; if (c=='%' && i<length()-2) { - uint8_t a = LOWERCASE(operator[](i+1)); - uint8_t b = LOWERCASE(operator[](i+2)); + uint8_t a = LOWERCASE(cs[i+1]); + uint8_t b = LOWERCASE(cs[i+2]); c=0; if (a>='0' && a<='9') @@ -3955,3 +3960,34 @@ String String::sprintf(const Array& values, bool* error) const { *error = false; return formatted; } + +#include "translation.h" + +#ifdef TOOLS_ENABLED +String TTR(const String& p_text) { + + if (TranslationServer::get_singleton()) { + return TranslationServer::get_singleton()->tool_translate(p_text); + } + + return p_text; +} + +#endif + +String RTR(const String& p_text) { + + + + if (TranslationServer::get_singleton()) { + String rtr = TranslationServer::get_singleton()->tool_translate(p_text); + if (rtr==String() || rtr==p_text) { + return TranslationServer::get_singleton()->translate(p_text); + } else { + return rtr; + } + } + + return p_text; +} + |