summaryrefslogtreecommitdiffstats
path: root/core/string
diff options
context:
space:
mode:
Diffstat (limited to 'core/string')
-rw-r--r--core/string/locales.h6
-rw-r--r--core/string/node_path.cpp8
-rw-r--r--core/string/print_string.cpp2
-rw-r--r--core/string/string_name.cpp4
-rw-r--r--core/string/translation.cpp9
-rw-r--r--core/string/translation.h3
-rw-r--r--core/string/ustring.cpp37
-rw-r--r--core/string/ustring.h1
8 files changed, 51 insertions, 19 deletions
diff --git a/core/string/locales.h b/core/string/locales.h
index 8a7efb4fd1..840fca65a7 100644
--- a/core/string/locales.h
+++ b/core/string/locales.h
@@ -1057,8 +1057,8 @@ static const char *script_list[][2] = {
{ "Hangul", "Hang" },
{ "Han", "Hani" },
{ "Hanunoo", "Hano" },
- { "Simplified", "Hans" },
- { "Traditional", "Hant" },
+ { "Simplified Han", "Hans" },
+ { "Traditional Han", "Hant" },
{ "Hatran", "Hatr" },
{ "Hebrew", "Hebr" },
{ "Hiragana", "Hira" },
@@ -1110,7 +1110,7 @@ static const char *script_list[][2] = {
{ "Mro", "Mroo" },
{ "Meitei Mayek", "Mtei" },
{ "Multani", "Mult" },
- { "Myanmar (Burmese)", "Mymr" },
+ { "Myanmar / Burmese", "Mymr" },
{ "​Nag Mundari", "Nagm" },
{ "Nandinagari", "Nand" },
{ "Old North Arabian", "Narb" },
diff --git a/core/string/node_path.cpp b/core/string/node_path.cpp
index af7c18741d..32e4564c5e 100644
--- a/core/string/node_path.cpp
+++ b/core/string/node_path.cpp
@@ -73,7 +73,7 @@ int NodePath::get_name_count() const {
}
StringName NodePath::get_name(int p_idx) const {
- ERR_FAIL_COND_V(!data, StringName());
+ ERR_FAIL_NULL_V(data, StringName());
ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName());
return data->path[p_idx];
}
@@ -87,7 +87,7 @@ int NodePath::get_subname_count() const {
}
StringName NodePath::get_subname(int p_idx) const {
- ERR_FAIL_COND_V(!data, StringName());
+ ERR_FAIL_NULL_V(data, StringName());
ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName());
return data->subpath[p_idx];
}
@@ -200,7 +200,7 @@ Vector<StringName> NodePath::get_subnames() const {
}
StringName NodePath::get_concatenated_names() const {
- ERR_FAIL_COND_V(!data, StringName());
+ ERR_FAIL_NULL_V(data, StringName());
if (!data->concatenated_path) {
int pc = data->path.size();
@@ -215,7 +215,7 @@ StringName NodePath::get_concatenated_names() const {
}
StringName NodePath::get_concatenated_subnames() const {
- ERR_FAIL_COND_V(!data, StringName());
+ ERR_FAIL_NULL_V(data, StringName());
if (!data->concatenated_subpath) {
int spc = data->subpath.size();
diff --git a/core/string/print_string.cpp b/core/string/print_string.cpp
index dcdde3c175..e3614be359 100644
--- a/core/string/print_string.cpp
+++ b/core/string/print_string.cpp
@@ -65,7 +65,7 @@ void remove_print_handler(const PrintHandlerList *p_handler) {
//OS::get_singleton()->print("print handler list is %p\n",print_handler_list);
_global_unlock();
- ERR_FAIL_COND(l == nullptr);
+ ERR_FAIL_NULL(l);
}
void __print_line(String p_string) {
diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp
index 6099fea13f..4402e44ad4 100644
--- a/core/string/string_name.cpp
+++ b/core/string/string_name.cpp
@@ -390,7 +390,7 @@ StringName::StringName(const String &p_name, bool p_static) {
StringName StringName::search(const char *p_name) {
ERR_FAIL_COND_V(!configured, StringName());
- ERR_FAIL_COND_V(!p_name, StringName());
+ ERR_FAIL_NULL_V(p_name, StringName());
if (!p_name[0]) {
return StringName();
}
@@ -426,7 +426,7 @@ StringName StringName::search(const char *p_name) {
StringName StringName::search(const char32_t *p_name) {
ERR_FAIL_COND_V(!configured, StringName());
- ERR_FAIL_COND_V(!p_name, StringName());
+ ERR_FAIL_NULL_V(p_name, StringName());
if (!p_name[0]) {
return StringName();
}
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index 3ca2e5ccdf..02380c92bb 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -82,6 +82,15 @@ void Translation::_set_messages(const Dictionary &p_messages) {
void Translation::set_locale(const String &p_locale) {
locale = TranslationServer::get_singleton()->standardize_locale(p_locale);
+ if (Thread::is_main_thread()) {
+ _notify_translation_changed_if_applies();
+ } else {
+ // Avoid calling non-thread-safe functions here.
+ callable_mp(this, &Translation::_notify_translation_changed_if_applies).call_deferred();
+ }
+}
+
+void Translation::_notify_translation_changed_if_applies() {
if (OS::get_singleton()->get_main_loop() && TranslationServer::get_singleton()->get_loaded_locales().has(get_locale())) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
}
diff --git a/core/string/translation.h b/core/string/translation.h
index 01d239f81c..3f9dbcc476 100644
--- a/core/string/translation.h
+++ b/core/string/translation.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class Translation : public Resource {
GDCLASS(Translation, Resource);
@@ -47,6 +46,8 @@ class Translation : public Resource {
virtual Dictionary _get_messages() const;
virtual void _set_messages(const Dictionary &p_messages);
+ void _notify_translation_changed_if_applies();
+
protected:
static void _bind_methods();
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 12e6423724..f6a17cf1a7 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -1493,9 +1493,9 @@ String String::num(double p_num, int p_decimals) {
if (p_decimals < 0) {
p_decimals = 14;
- const double abs_num = ABS(p_num);
+ const double abs_num = Math::abs(p_num);
if (abs_num > 10) {
- // We want to align the digits to the above sane default, so we only
+ // We want to align the digits to the above reasonable default, so we only
// need to subtract log10 for numbers with a positive power of ten.
p_decimals -= (int)floor(log10(abs_num));
}
@@ -1750,7 +1750,7 @@ Vector<uint8_t> String::hex_decode() const {
void String::print_unicode_error(const String &p_message, bool p_critical) const {
if (p_critical) {
- print_error(vformat("Unicode parsing error, some characters were replaced with � (U+FFFD): %s", p_message));
+ print_error(vformat(U"Unicode parsing error, some characters were replaced with � (U+FFFD): %s", p_message));
} else {
print_error(vformat("Unicode parsing error: %s", p_message));
}
@@ -3635,6 +3635,23 @@ String String::repeat(int p_count) const {
return new_string;
}
+String String::reverse() const {
+ int len = length();
+ if (len <= 1) {
+ return *this;
+ }
+ String new_string;
+ new_string.resize(len + 1);
+
+ const char32_t *src = ptr();
+ char32_t *dst = new_string.ptrw();
+ for (int i = 0; i < len; i++) {
+ dst[i] = src[len - i - 1];
+ }
+ dst[len] = _null;
+ return new_string;
+}
+
String String::left(int p_len) const {
if (p_len < 0) {
p_len = length() + p_len;
@@ -3648,7 +3665,9 @@ String String::left(int p_len) const {
return *this;
}
- return substr(0, p_len);
+ String s;
+ s.copy_from_unchecked(&get_data()[0], p_len);
+ return s;
}
String String::right(int p_len) const {
@@ -3664,7 +3683,9 @@ String String::right(int p_len) const {
return *this;
}
- return substr(length() - p_len);
+ String s;
+ s.copy_from_unchecked(&get_data()[length() - p_len], p_len);
+ return s;
}
char32_t String::unicode_at(int p_idx) const {
@@ -4869,8 +4890,8 @@ String String::sprintf(const Array &values, bool *error) const {
}
double value = values[value_index];
- bool is_negative = (value < 0);
- String str = String::num(ABS(value), min_decimals);
+ bool is_negative = signbit(value);
+ String str = String::num(Math::abs(value), min_decimals);
const bool is_finite = Math::is_finite(value);
// Pad decimals out.
@@ -4932,7 +4953,7 @@ String String::sprintf(const Array &values, bool *error) const {
String str = "(";
for (int i = 0; i < count; i++) {
double val = vec[i];
- String number_str = String::num(ABS(val), min_decimals);
+ String number_str = String::num(Math::abs(val), min_decimals);
const bool is_finite = Math::is_finite(val);
// Pad decimals out.
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 295625395d..f45392eee1 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -305,6 +305,7 @@ public:
String replace(const char *p_key, const char *p_with) const;
String replacen(const String &p_key, const String &p_with) const;
String repeat(int p_count) const;
+ String reverse() const;
String insert(int p_at_pos, const String &p_string) const;
String erase(int p_pos, int p_chars = 1) const;
String pad_decimals(int p_digits) const;