diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2021-12-15 23:01:06 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2021-12-16 17:49:22 +0800 |
commit | e4e4e475f8f1a1d8b82ef7ad636da8536e8c6554 (patch) | |
tree | 584197a87c47a265d71a97df3fcd69d8e5a57783 /core/string | |
parent | edd3ca45016a4ee8cc5f7c1108e1c71bfa2a86ab (diff) |
Make `--doctool` locale aware
* Adds `indent(str)` to `String`:
* Indent the (multiline) string with the given indentation.
* This method is added in order to keep the translated XML correctly
indented.
* Moves the loading of tool/doc translation into
`editor/editor_translation.{h,cpp}`.
* This will be used from both `EditorSettings` and the doc tool from
`main`.
* Makes use of doc translation when generating XML class references, and
setup the translation locale based on `-l LOCALE` CLI parameter.
The XML class reference won't be translated if `-l LOCALE` parameter is
not given, or when it's `-l en`.
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/ustring.cpp | 21 | ||||
-rw-r--r-- | core/string/ustring.h | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index ac8e2ece12..779270fe47 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3507,6 +3507,27 @@ char32_t String::unicode_at(int p_idx) const { return operator[](p_idx); } +String String::indent(const String &p_prefix) const { + String new_string; + int line_start = 0; + + for (int i = 0; i < length(); i++) { + const char32_t c = operator[](i); + if (c == '\n') { + if (i == line_start) { + new_string += c; // Leave empty lines empty. + } else { + new_string += p_prefix + substr(line_start, i - line_start + 1); + } + line_start = i + 1; + } + } + if (line_start != length()) { + new_string += p_prefix + substr(line_start); + } + return new_string; +} + String String::dedent() const { String new_string; String indent; diff --git a/core/string/ustring.h b/core/string/ustring.h index 396c996050..780515c12e 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -356,6 +356,7 @@ public: String left(int p_pos) const; String right(int p_pos) const; + String indent(const String &p_prefix) const; String dedent() const; String strip_edges(bool left = true, bool right = true) const; String strip_escapes() const; |