diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-09-03 21:35:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 21:35:27 +0200 |
commit | 27763b67bb63139319bf611590c40e48663e72d6 (patch) | |
tree | ad9a1589128f569fc6be2a99893b916491f87af1 /modules | |
parent | 4dd915028a9c8819075d7ac5683f6da7ddf58087 (diff) | |
parent | 80b8eff6aa41ba79175a5152ba5b2b9b16f6de3f (diff) |
Merge pull request #40999 from bruvzg/ctl_string_to_utf32
[Complex Test Layouts] Refactor `String` to use UTF-32 encoding.
Diffstat (limited to 'modules')
20 files changed, 862 insertions, 814 deletions
diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 26c40b625c..1fa19f4ff5 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -40,9 +40,10 @@ extern "C" { #endif +static_assert(sizeof(godot_char16_string) == sizeof(Char16String), "Char16String size mismatch"); static_assert(sizeof(godot_char_string) == sizeof(CharString), "CharString size mismatch"); static_assert(sizeof(godot_string) == sizeof(String), "String size mismatch"); -static_assert(sizeof(godot_char_type) == sizeof(CharType), "CharType size mismatch"); +static_assert(sizeof(godot_char_type) == sizeof(char32_t), "char32_t size mismatch"); godot_int GDAPI godot_char_string_length(const godot_char_string *p_cs) { const CharString *cs = (const CharString *)p_cs; @@ -62,6 +63,24 @@ void GDAPI godot_char_string_destroy(godot_char_string *p_cs) { cs->~CharString(); } +godot_int GDAPI godot_char16_string_length(const godot_char16_string *p_cs) { + const Char16String *cs = (const Char16String *)p_cs; + + return cs->length(); +} + +const char16_t GDAPI *godot_char16_string_get_data(const godot_char16_string *p_cs) { + const Char16String *cs = (const Char16String *)p_cs; + + return cs->get_data(); +} + +void GDAPI godot_char16_string_destroy(godot_char16_string *p_cs) { + Char16String *cs = (Char16String *)p_cs; + + cs->~Char16String(); +} + void GDAPI godot_string_new(godot_string *r_dest) { String *dest = (String *)r_dest; memnew_placement(dest, String); @@ -70,27 +89,97 @@ void GDAPI godot_string_new(godot_string *r_dest) { void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src) { String *dest = (String *)r_dest; const String *src = (const String *)p_src; - memnew_placement(dest, String(*src)); + memnew_placement(dest, String); + *dest = String(*src); +} + +void GDAPI godot_string_new_with_latin1_chars(godot_string *r_dest, const char *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String(p_contents); +} + +void GDAPI godot_string_new_with_utf8_chars(godot_string *r_dest, const char *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf8(p_contents); +} + +void GDAPI godot_string_new_with_utf16_chars(godot_string *r_dest, const char16_t *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf16(p_contents); +} + +void GDAPI godot_string_new_with_utf32_chars(godot_string *r_dest, const char32_t *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents); +} + +void GDAPI godot_string_new_with_wide_chars(godot_string *r_dest, const wchar_t *p_contents) { + String *dest = (String *)r_dest; + if (sizeof(wchar_t) == 2) { + // wchar_t is 16 bit, parse. + memnew_placement(dest, String); + dest->parse_utf16((const char16_t *)p_contents); + } else { + // wchar_t is 32 bit, copy. + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents); + } +} + +void GDAPI godot_string_new_with_latin1_chars_and_len(godot_string *r_dest, const char *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String(p_contents, p_size); +} + +void GDAPI godot_string_new_with_utf8_chars_and_len(godot_string *r_dest, const char *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf8(p_contents, p_size); +} + +void GDAPI godot_string_new_with_utf16_chars_and_len(godot_string *r_dest, const char16_t *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf16(p_contents, p_size); +} + +void GDAPI godot_string_new_with_utf32_chars_and_len(godot_string *r_dest, const char32_t *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents, p_size); } -void GDAPI godot_string_new_with_wide_string(godot_string *r_dest, const wchar_t *p_contents, const int p_size) { +void GDAPI godot_string_new_with_wide_chars_and_len(godot_string *r_dest, const wchar_t *p_contents, const int p_size) { String *dest = (String *)r_dest; - memnew_placement(dest, String(p_contents, p_size)); + if (sizeof(wchar_t) == 2) { + // wchar_t is 16 bit, parse. + memnew_placement(dest, String); + dest->parse_utf16((const char16_t *)p_contents, p_size); + } else { + // wchar_t is 32 bit, copy. + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents, p_size); + } } -const wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx) { +const godot_char_type GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx) { String *self = (String *)p_self; return &(self->operator[](p_idx)); } -wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx) { +godot_char_type GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx) { const String *self = (const String *)p_self; return self->operator[](p_idx); } -const wchar_t GDAPI *godot_string_wide_str(const godot_string *p_self) { +const godot_char_type GDAPI *godot_string_get_data(const godot_string *p_self) { const String *self = (const String *)p_self; - return self->c_str(); + return self->get_data(); } godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b) { @@ -162,22 +251,14 @@ godot_bool GDAPI godot_string_begins_with_char_array(const godot_string *p_self, return self->begins_with(p_char_array); } -godot_array GDAPI godot_string_bigrams(const godot_string *p_self) { +godot_packed_string_array GDAPI godot_string_bigrams(const godot_string *p_self) { const String *self = (const String *)p_self; - Vector<String> return_value = self->bigrams(); - - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - - return result; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->bigrams())); + return ret; }; -godot_string GDAPI godot_string_chr(wchar_t p_character) { +godot_string GDAPI godot_string_chr(godot_char_type p_character) { godot_string result; memnew_placement(&result, String(String::chr(p_character))); @@ -191,88 +272,73 @@ godot_bool GDAPI godot_string_ends_with(const godot_string *p_self, const godot_ return self->ends_with(*string); } -godot_int GDAPI godot_string_count(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to) { +godot_bool GDAPI godot_string_ends_with_char_array(const godot_string *p_self, const char *p_char_array) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + + return self->ends_with(p_char_array); +} + +godot_int GDAPI godot_string_count(const godot_string *p_self, const godot_string *p_what, godot_int p_from, godot_int p_to) { + const String *self = (const String *)p_self; + const String *what = (const String *)p_what; return self->count(*what, p_from, p_to); } -godot_int GDAPI godot_string_countn(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to) { +godot_int GDAPI godot_string_countn(const godot_string *p_self, const godot_string *p_what, godot_int p_from, godot_int p_to) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->countn(*what, p_from, p_to); } -godot_int GDAPI godot_string_find(const godot_string *p_self, godot_string p_what) { +godot_int GDAPI godot_string_find(const godot_string *p_self, const godot_string *p_what) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->find(*what); } -godot_int GDAPI godot_string_find_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { +godot_int GDAPI godot_string_find_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->find(*what, p_from); } -godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_array *p_keys) { +godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_packed_string_array *p_keys) { const String *self = (const String *)p_self; - - Vector<String> keys; - Array *keys_proxy = (Array *)p_keys; - keys.resize(keys_proxy->size()); - for (int i = 0; i < keys_proxy->size(); i++) { - keys.write[i] = (*keys_proxy)[i]; - } - - return self->findmk(keys); + const Vector<String> *keys = (const Vector<String> *)p_keys; + return self->findmk(*keys); } -godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_array *p_keys, godot_int p_from) { +godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_packed_string_array *p_keys, godot_int p_from) { const String *self = (const String *)p_self; - - Vector<String> keys; - Array *keys_proxy = (Array *)p_keys; - keys.resize(keys_proxy->size()); - for (int i = 0; i < keys_proxy->size(); i++) { - keys.write[i] = (*keys_proxy)[i]; - } - - return self->findmk(keys, p_from); + const Vector<String> *keys = (const Vector<String> *)p_keys; + return self->findmk(*keys, p_from); } -godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key) { +godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_packed_string_array *p_keys, godot_int p_from, godot_int *r_key) { const String *self = (const String *)p_self; - - Vector<String> keys; - Array *keys_proxy = (Array *)p_keys; - keys.resize(keys_proxy->size()); - for (int i = 0; i < keys_proxy->size(); i++) { - keys.write[i] = (*keys_proxy)[i]; - } - + const Vector<String> *keys = (const Vector<String> *)p_keys; int key; - int ret = self->findmk(keys, p_from, &key); + int ret = self->findmk(*keys, p_from, &key); if (r_key) { *r_key = key; } return ret; } -godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what) { +godot_int GDAPI godot_string_findn(const godot_string *p_self, const godot_string *p_what) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->findn(*what); } -godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { +godot_int GDAPI godot_string_findn_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->findn(*what, p_from); } @@ -303,21 +369,9 @@ godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot return result; } -godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self) { - const String *self = (const String *)p_self; - - return self->hex_to_int(); -} - -godot_int GDAPI godot_string_hex_to_int_without_prefix(const godot_string *p_self) { - const String *self = (const String *)p_self; - - return self->hex_to_int(true); -} - -godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, godot_string p_string) { +godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, const godot_string *p_string) { const String *self = (const String *)p_self; - String *content = (String *)&p_string; + const String *content = (const String *)p_string; godot_string result; memnew_placement(&result, String(self->insert(p_at_pos, *content))); @@ -440,58 +494,58 @@ godot_string GDAPI godot_string_pad_zeros(const godot_string *p_self, godot_int return result; } -godot_string GDAPI godot_string_replace(const godot_string *p_self, godot_string p_key, godot_string p_with) { +godot_string GDAPI godot_string_replace(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with) { const String *self = (const String *)p_self; - String *key = (String *)&p_key; - String *with = (String *)&p_with; + const String *key = (const String *)p_key; + const String *with = (const String *)p_with; godot_string result; memnew_placement(&result, String(self->replace(*key, *with))); return result; } -godot_string GDAPI godot_string_replacen(const godot_string *p_self, godot_string p_key, godot_string p_with) { +godot_string GDAPI godot_string_replacen(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with) { const String *self = (const String *)p_self; - String *key = (String *)&p_key; - String *with = (String *)&p_with; + const String *key = (const String *)p_key; + const String *with = (const String *)p_with; godot_string result; memnew_placement(&result, String(self->replacen(*key, *with))); return result; } -godot_int GDAPI godot_string_rfind(const godot_string *p_self, godot_string p_what) { +godot_int GDAPI godot_string_rfind(const godot_string *p_self, const godot_string *p_what) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->rfind(*what); } -godot_int GDAPI godot_string_rfindn(const godot_string *p_self, godot_string p_what) { +godot_int GDAPI godot_string_rfindn(const godot_string *p_self, const godot_string *p_what) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->rfindn(*what); } -godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { +godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->rfind(*what, p_from); } -godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { +godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from) { const String *self = (const String *)p_self; - String *what = (String *)&p_what; + const String *what = (const String *)p_what; return self->rfindn(*what, p_from); } -godot_string GDAPI godot_string_replace_first(const godot_string *p_self, godot_string p_key, godot_string p_with) { +godot_string GDAPI godot_string_replace_first(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with) { const String *self = (const String *)p_self; - String *key = (String *)&p_key; - String *with = (String *)&p_with; + const String *key = (const String *)p_key; + const String *with = (const String *)p_with; godot_string result; memnew_placement(&result, String(self->replace_first(*key, *with))); @@ -541,16 +595,16 @@ godot_string GDAPI godot_string_substr(const godot_string *p_self, godot_int p_f return result; } -double GDAPI godot_string_to_float(const godot_string *p_self) { +godot_int GDAPI godot_string_to_int(const godot_string *p_self) { const String *self = (const String *)p_self; - return self->to_float(); + return self->to_int(); } -godot_int GDAPI godot_string_to_int(const godot_string *p_self) { +double GDAPI godot_string_to_float(const godot_string *p_self) { const String *self = (const String *)p_self; - return self->to_int(); + return self->to_float(); } godot_string GDAPI godot_string_capitalize(const godot_string *p_self) { @@ -581,11 +635,15 @@ double GDAPI godot_string_char_to_float(const char *p_what) { return String::to_float(p_what); } +double GDAPI godot_string_wchar_to_float(const wchar_t *p_str, const wchar_t **r_end) { + return String::to_float(p_str, r_end); +} + godot_int GDAPI godot_string_char_to_int(const char *p_what) { return String::to_int(p_what); } -int64_t GDAPI godot_string_wchar_to_int(const wchar_t *p_str) { +godot_int GDAPI godot_string_wchar_to_int(const wchar_t *p_str) { return String::to_int(p_str); } @@ -593,42 +651,32 @@ godot_int GDAPI godot_string_char_to_int_with_len(const char *p_what, godot_int return String::to_int(p_what, p_len); } -int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_len) { +godot_int GDAPI godot_string_wchar_to_int_with_len(const wchar_t *p_str, int p_len) { return String::to_int(p_str, p_len); } -int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self) { +godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self) { const String *self = (const String *)p_self; return self->hex_to_int(false); } -int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self) { +godot_int GDAPI godot_string_hex_to_int_with_prefix(const godot_string *p_self) { const String *self = (const String *)p_self; return self->hex_to_int(); } -int64_t GDAPI godot_string_to_int64(const godot_string *p_self) { +godot_string GDAPI godot_string_get_slice(const godot_string *p_self, const godot_string *p_splitter, godot_int p_slice) { const String *self = (const String *)p_self; - - return self->to_int(); -} - -double GDAPI godot_string_unicode_char_to_float(const wchar_t *p_str, const wchar_t **r_end) { - return String::to_float(p_str, r_end); -} - -godot_string GDAPI godot_string_get_slice(const godot_string *p_self, godot_string p_splitter, godot_int p_slice) { - const String *self = (const String *)p_self; - String *splitter = (String *)&p_splitter; + const String *splitter = (const String *)p_splitter; godot_string result; memnew_placement(&result, String(self->get_slice(*splitter, p_slice))); return result; } -godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p_splitter, godot_int p_slice) { +godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, godot_char_type p_splitter, godot_int p_slice) { const String *self = (const String *)p_self; godot_string result; memnew_placement(&result, String(self->get_slicec(p_splitter, p_slice))); @@ -636,221 +684,149 @@ godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p return result; } -godot_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_string_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<String> return_value = self->split(*splitter, false); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - - return result; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->split(*splitter, false))); + return ret; } -godot_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_string_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<String> return_value = self->split(*splitter); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->split(*splitter, true))); + return ret; +} - return result; +godot_packed_string_array GDAPI godot_string_split_with_maxsplit(const godot_string *p_self, const godot_string *p_splitter, const godot_bool p_allow_empty, const godot_int p_maxsplit) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->split(*splitter, p_allow_empty, p_maxsplit))); + return ret; } -godot_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_string_array GDAPI godot_string_rsplit(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<float> return_value = self->split_floats(*splitter, false); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - return result; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->rsplit(*splitter, false))); + return ret; } -godot_array GDAPI godot_string_split_floats_allows_empty(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_string_array GDAPI godot_string_rsplit_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<float> return_value = self->split_floats(*splitter); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - return result; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->rsplit(*splitter, true))); + return ret; } -godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_array *p_splitters) { +godot_packed_string_array GDAPI godot_string_rsplit_with_maxsplit(const godot_string *p_self, const godot_string *p_splitter, const godot_bool p_allow_empty, const godot_int p_maxsplit) { const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; - Vector<String> splitters; - Array *splitter_proxy = (Array *)p_splitters; - splitters.resize(splitter_proxy->size()); - for (int i = 0; i < splitter_proxy->size(); i++) { - splitters.write[i] = (*splitter_proxy)[i]; - } - - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<float> return_value = self->split_floats_mk(splitters, false); + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->rsplit(*splitter, p_allow_empty, p_maxsplit))); + return ret; +} - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } +godot_packed_float32_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; - return result; + godot_packed_float32_array ret; + memnew_placement(&ret, Vector<float>(self->split_floats(*splitter, false))); + return ret; } -godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters) { +godot_packed_float32_array GDAPI godot_string_split_floats_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; - Vector<String> splitters; - Array *splitter_proxy = (Array *)p_splitters; - splitters.resize(splitter_proxy->size()); - for (int i = 0; i < splitter_proxy->size(); i++) { - splitters.write[i] = (*splitter_proxy)[i]; - } - - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<float> return_value = self->split_floats_mk(splitters); + godot_packed_float32_array ret; + memnew_placement(&ret, Vector<float>(self->split_floats(*splitter, true))); + return ret; +} - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } +godot_packed_float32_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_packed_string_array *p_splitters) { + const String *self = (const String *)p_self; + const Vector<String> *splitters = (const Vector<String> *)p_splitters; - return result; + godot_packed_float32_array ret; + memnew_placement(&ret, Vector<float>(self->split_floats_mk(*splitters, false))); + return ret; } -godot_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_float32_array GDAPI godot_string_split_floats_mk_allow_empty(const godot_string *p_self, const godot_packed_string_array *p_splitters) { const String *self = (const String *)p_self; - const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<int> return_value = self->split_ints(*splitter, false); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } + const Vector<String> *splitters = (const Vector<String> *)p_splitters; - return result; + godot_packed_float32_array ret; + memnew_placement(&ret, Vector<float>(self->split_floats_mk(*splitters, true))); + return ret; } -godot_array GDAPI godot_string_split_ints_allows_empty(const godot_string *p_self, const godot_string *p_splitter) { +godot_packed_int32_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; const String *splitter = (const String *)p_splitter; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<int> return_value = self->split_ints(*splitter); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - return result; + godot_packed_int32_array ret; + memnew_placement(&ret, Vector<int>(self->split_ints(*splitter, false))); + return ret; } -godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_array *p_splitters) { +godot_packed_int32_array GDAPI godot_string_split_ints_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; - Vector<String> splitters; - Array *splitter_proxy = (Array *)p_splitters; - splitters.resize(splitter_proxy->size()); - for (int i = 0; i < splitter_proxy->size(); i++) { - splitters.write[i] = (*splitter_proxy)[i]; - } - - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<int> return_value = self->split_ints_mk(splitters, false); - - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - - return result; + godot_packed_int32_array ret; + memnew_placement(&ret, Vector<int>(self->split_ints(*splitter, true))); + return ret; } -godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters) { +godot_packed_int32_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_packed_string_array *p_splitters) { const String *self = (const String *)p_self; + const Vector<String> *splitters = (const Vector<String> *)p_splitters; - Vector<String> splitters; - Array *splitter_proxy = (Array *)p_splitters; - splitters.resize(splitter_proxy->size()); - for (int i = 0; i < splitter_proxy->size(); i++) { - splitters.write[i] = (*splitter_proxy)[i]; - } - - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<int> return_value = self->split_ints_mk(splitters); + godot_packed_int32_array ret; + memnew_placement(&ret, Vector<int>(self->split_ints_mk(*splitters, false))); + return ret; +} - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } +godot_packed_int32_array GDAPI godot_string_split_ints_mk_allow_empty(const godot_string *p_self, const godot_packed_string_array *p_splitters) { + const String *self = (const String *)p_self; + const Vector<String> *splitters = (const Vector<String> *)p_splitters; - return result; + godot_packed_int32_array ret; + memnew_placement(&ret, Vector<int>(self->split_ints_mk(*splitters, true))); + return ret; } -godot_array GDAPI godot_string_split_spaces(const godot_string *p_self) { +godot_packed_string_array GDAPI godot_string_split_spaces(const godot_string *p_self) { const String *self = (const String *)p_self; - godot_array result; - memnew_placement(&result, Array); - Array *proxy = (Array *)&result; - Vector<String> return_value = self->split_spaces(); - proxy->resize(return_value.size()); - for (int i = 0; i < return_value.size(); i++) { - (*proxy)[i] = return_value[i]; - } - - return result; + godot_packed_string_array ret; + memnew_placement(&ret, Vector<String>(self->split_spaces())); + return ret; } -godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, godot_string p_splitter) { +godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, const godot_string *p_splitter) { const String *self = (const String *)p_self; - String *splitter = (String *)&p_splitter; + const String *splitter = (const String *)p_splitter; return self->get_slice_count(*splitter); } -wchar_t GDAPI godot_string_char_lowercase(wchar_t p_char) { +godot_char_type GDAPI godot_string_char_lowercase(godot_char_type p_char) { return String::char_lowercase(p_char); } -wchar_t GDAPI godot_string_char_uppercase(wchar_t p_char) { +godot_char_type GDAPI godot_string_char_uppercase(godot_char_type p_char) { return String::char_uppercase(p_char); } @@ -894,7 +870,7 @@ godot_string GDAPI godot_string_left(const godot_string *p_self, godot_int p_pos return result; } -wchar_t GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx) { +godot_char_type GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx) { const String *self = (const String *)p_self; return self->ord_at(p_idx); @@ -917,6 +893,14 @@ godot_string GDAPI godot_string_right(const godot_string *p_self, godot_int p_po return result; } +godot_string GDAPI godot_string_repeat(const godot_string *p_self, godot_int p_count) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->repeat(p_count))); + + return result; +} + godot_string GDAPI godot_string_strip_edges(const godot_string *p_self, godot_bool p_left, godot_bool p_right) { const String *self = (const String *)p_self; godot_string result; @@ -948,7 +932,7 @@ godot_char_string GDAPI godot_string_ascii(const godot_string *p_self) { return result; } -godot_char_string GDAPI godot_string_ascii_extended(const godot_string *p_self) { +godot_char_string GDAPI godot_string_latin1(const godot_string *p_self) { const String *self = (const String *)p_self; godot_char_string result; @@ -994,6 +978,42 @@ godot_string GDAPI godot_string_chars_to_utf8_with_len(const char *p_utf8, godot return result; } +godot_char16_string GDAPI godot_string_utf16(const godot_string *p_self) { + const String *self = (const String *)p_self; + + godot_char16_string result; + + memnew_placement(&result, Char16String(self->utf16())); + + return result; +} + +godot_bool GDAPI godot_string_parse_utf16(godot_string *p_self, const char16_t *p_utf16) { + String *self = (String *)p_self; + + return self->parse_utf16(p_utf16); +} + +godot_bool GDAPI godot_string_parse_utf16_with_len(godot_string *p_self, const char16_t *p_utf16, godot_int p_len) { + String *self = (String *)p_self; + + return self->parse_utf16(p_utf16, p_len); +} + +godot_string GDAPI godot_string_chars_to_utf16(const char16_t *p_utf16) { + godot_string result; + memnew_placement(&result, String(String::utf16(p_utf16))); + + return result; +} + +godot_string GDAPI godot_string_chars_to_utf16_with_len(const char16_t *p_utf16, godot_int p_len) { + godot_string result; + memnew_placement(&result, String(String::utf16(p_utf16, p_len))); + + return result; +} + uint32_t GDAPI godot_string_hash(const godot_string *p_self) { const String *self = (const String *)p_self; @@ -1014,28 +1034,18 @@ uint32_t GDAPI godot_string_hash_chars_with_len(const char *p_cstr, godot_int p_ return String::hash(p_cstr, p_len); } -uint32_t GDAPI godot_string_hash_utf8_chars(const wchar_t *p_str) { +uint32_t GDAPI godot_string_hash_wide_chars(const wchar_t *p_str) { return String::hash(p_str); } -uint32_t GDAPI godot_string_hash_utf8_chars_with_len(const wchar_t *p_str, godot_int p_len) { +uint32_t GDAPI godot_string_hash_wide_chars_with_len(const wchar_t *p_str, godot_int p_len) { return String::hash(p_str, p_len); } godot_packed_byte_array GDAPI godot_string_md5_buffer(const godot_string *p_self) { const String *self = (const String *)p_self; - Vector<uint8_t> tmp_result = self->md5_buffer(); - godot_packed_byte_array result; - memnew_placement(&result, PackedByteArray); - PackedByteArray *proxy = (PackedByteArray *)&result; - uint8_t *proxy_writer = proxy->ptrw(); - proxy->resize(tmp_result.size()); - - for (int i = 0; i < tmp_result.size(); i++) { - proxy_writer[i] = tmp_result[i]; - } - + memnew_placement(&result, PackedByteArray(self->md5_buffer())); return result; } @@ -1047,23 +1057,28 @@ godot_string GDAPI godot_string_md5_text(const godot_string *p_self) { return result; } -godot_packed_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self) { +godot_packed_byte_array GDAPI godot_string_sha1_buffer(const godot_string *p_self) { const String *self = (const String *)p_self; - Vector<uint8_t> tmp_result = self->sha256_buffer(); - godot_packed_byte_array result; - memnew_placement(&result, PackedByteArray); - PackedByteArray *proxy = (PackedByteArray *)&result; - uint8_t *proxy_writer = proxy->ptrw(); - proxy->resize(tmp_result.size()); + memnew_placement(&result, PackedByteArray(self->sha1_buffer())); + return result; +} - for (int i = 0; i < tmp_result.size(); i++) { - proxy_writer[i] = tmp_result[i]; - } +godot_string GDAPI godot_string_sha1_text(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->sha1_text())); return result; } +godot_packed_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_packed_byte_array result; + memnew_placement(&result, PackedByteArray(self->sha256_buffer())); + return result; +} + godot_string GDAPI godot_string_sha256_text(const godot_string *p_self) { const String *self = (const String *)p_self; godot_string result; @@ -1206,15 +1221,6 @@ godot_string GDAPI godot_string_json_escape(const godot_string *p_self) { return result; } -godot_string GDAPI godot_string_word_wrap(const godot_string *p_self, godot_int p_chars_per_line) { - const String *self = (const String *)p_self; - godot_string result; - String return_value = self->word_wrap(p_chars_per_line); - memnew_placement(&result, String(return_value)); - - return result; -} - godot_string GDAPI godot_string_xml_escape(const godot_string *p_self) { const String *self = (const String *)p_self; godot_string result; @@ -1260,6 +1266,22 @@ godot_string GDAPI godot_string_percent_encode(const godot_string *p_self) { return result; } +godot_string GDAPI godot_string_join(const godot_string *p_self, const godot_packed_string_array *p_parts) { + const String *self = (const String *)p_self; + const Vector<String> *parts = (const Vector<String> *)p_parts; + godot_string result; + String return_value = self->join(*parts); + memnew_placement(&result, String(return_value)); + + return result; +} + +godot_bool GDAPI godot_string_is_valid_filename(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_filename(); +} + godot_bool GDAPI godot_string_is_valid_float(const godot_string *p_self) { const String *self = (const String *)p_self; @@ -1325,31 +1347,22 @@ godot_string GDAPI godot_string_trim_suffix(const godot_string *p_self, const go return result; } -godot_string GDAPI godot_string_rstrip(const godot_string *p_self, const godot_string *p_chars) { +godot_string GDAPI godot_string_lstrip(const godot_string *p_self, const godot_string *p_chars) { const String *self = (const String *)p_self; String *chars = (String *)p_chars; godot_string result; - String return_value = self->rstrip(*chars); + String return_value = self->lstrip(*chars); memnew_placement(&result, String(return_value)); return result; } -godot_packed_string_array GDAPI godot_string_rsplit(const godot_string *p_self, const godot_string *p_divisor, - const godot_bool p_allow_empty, const godot_int p_maxsplit) { +godot_string GDAPI godot_string_rstrip(const godot_string *p_self, const godot_string *p_chars) { const String *self = (const String *)p_self; - String *divisor = (String *)p_divisor; - - godot_packed_string_array result; - memnew_placement(&result, PackedStringArray); - PackedStringArray *proxy = (PackedStringArray *)&result; - String *proxy_writer = proxy->ptrw(); - Vector<String> tmp_result = self->rsplit(*divisor, p_allow_empty, p_maxsplit); - proxy->resize(tmp_result.size()); - - for (int i = 0; i < tmp_result.size(); i++) { - proxy_writer[i] = tmp_result[i]; - } + String *chars = (String *)p_chars; + godot_string result; + String return_value = self->rstrip(*chars); + memnew_placement(&result, String(return_value)); return result; } diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 8ccf44ff1a..82bfbd23de 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -3732,6 +3732,27 @@ ] }, { + "name": "godot_char16_string_length", + "return_type": "godot_int", + "arguments": [ + ["const godot_char16_string *", "p_cs"] + ] + }, + { + "name": "godot_char16_string_get_data", + "return_type": "const char16_t *", + "arguments": [ + ["const godot_char16_string *", "p_cs"] + ] + }, + { + "name": "godot_char16_string_destroy", + "return_type": "void", + "arguments": [ + ["godot_char16_string *", "p_cs"] + ] + }, + { "name": "godot_string_new", "return_type": "void", "arguments": [ @@ -3747,7 +3768,83 @@ ] }, { - "name": "godot_string_new_with_wide_string", + "name": "godot_string_new_with_latin1_chars", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char *", "p_contents"] + ] + }, + { + "name": "godot_string_new_with_utf8_chars", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char *", "p_contents"] + ] + }, + { + "name": "godot_string_new_with_utf16_chars", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char16_t *", "p_contents"] + ] + }, + { + "name": "godot_string_new_with_utf32_chars", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char32_t *", "p_contents"] + ] + }, + { + "name": "godot_string_new_with_wide_chars", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const wchar_t *", "p_contents"] + ] + }, + { + "name": "godot_string_new_with_latin1_chars_and_len", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char *", "p_contents"], + ["const int", "p_size"] + ] + }, + { + "name": "godot_string_new_with_utf8_chars_and_len", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char *", "p_contents"], + ["const int", "p_size"] + ] + }, + { + "name": "godot_string_new_with_utf16_chars_and_len", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char16_t *", "p_contents"], + ["const int", "p_size"] + ] + }, + { + "name": "godot_string_new_with_utf32_chars_and_len", + "return_type": "void", + "arguments": [ + ["godot_string *", "r_dest"], + ["const char32_t *", "p_contents"], + ["const int", "p_size"] + ] + }, + { + "name": "godot_string_new_with_wide_chars_and_len", "return_type": "void", "arguments": [ ["godot_string *", "r_dest"], @@ -3757,7 +3854,7 @@ }, { "name": "godot_string_operator_index", - "return_type": "const wchar_t *", + "return_type": "const godot_char_type *", "arguments": [ ["godot_string *", "p_self"], ["const godot_int", "p_idx"] @@ -3765,15 +3862,15 @@ }, { "name": "godot_string_operator_index_const", - "return_type": "wchar_t", + "return_type": "godot_char_type", "arguments": [ ["const godot_string *", "p_self"], ["const godot_int", "p_idx"] ] }, { - "name": "godot_string_wide_str", - "return_type": "const wchar_t *", + "name": "godot_string_get_data", + "return_type": "const godot_char_type *", "arguments": [ ["const godot_string *", "p_self"] ] @@ -3807,7 +3904,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"], ["godot_int", "p_to"] ] @@ -3817,7 +3914,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"], ["godot_int", "p_to"] ] @@ -3878,7 +3975,7 @@ }, { "name": "godot_string_bigrams", - "return_type": "godot_array", + "return_type": "godot_packed_string_array", "arguments": [ ["const godot_string *", "p_self"] ] @@ -3887,7 +3984,7 @@ "name": "godot_string_chr", "return_type": "godot_string", "arguments": [ - ["wchar_t", "p_character"] + ["godot_char_type", "p_character"] ] }, { @@ -3899,11 +3996,19 @@ ] }, { + "name": "godot_string_ends_with_char_array", + "return_type": "godot_bool", + "arguments": [ + ["const godot_string *", "p_self"], + ["const char *", "p_char_array"] + ] + }, + { "name": "godot_string_find", "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"] + ["const godot_string *", "p_what"] ] }, { @@ -3911,7 +4016,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"] ] }, @@ -3920,7 +4025,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_keys"] + ["const godot_packed_string_array *", "p_keys"] ] }, { @@ -3928,7 +4033,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_keys"], + ["const godot_packed_string_array *", "p_keys"], ["godot_int", "p_from"] ] }, @@ -3937,7 +4042,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_keys"], + ["const godot_packed_string_array *", "p_keys"], ["godot_int", "p_from"], ["godot_int *", "r_key"] ] @@ -3947,7 +4052,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"] + ["const godot_string *", "p_what"] ] }, { @@ -3955,7 +4060,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"] ] }, @@ -3985,26 +4090,12 @@ ] }, { - "name": "godot_string_hex_to_int", - "return_type": "godot_int", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, - { - "name": "godot_string_hex_to_int_without_prefix", - "return_type": "godot_int", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, - { "name": "godot_string_insert", "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], ["godot_int", "p_at_pos"], - ["godot_string", "p_string"] + ["const godot_string *", "p_string"] ] }, { @@ -4137,8 +4228,8 @@ "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_key"], - ["godot_string", "p_with"] + ["const godot_string *", "p_key"], + ["const godot_string *", "p_with"] ] }, { @@ -4146,8 +4237,8 @@ "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_key"], - ["godot_string", "p_with"] + ["const godot_string *", "p_key"], + ["const godot_string *", "p_with"] ] }, { @@ -4155,8 +4246,8 @@ "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_key"], - ["godot_string", "p_with"] + ["const godot_string *", "p_key"], + ["const godot_string *", "p_with"] ] }, { @@ -4164,7 +4255,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"] + ["const godot_string *", "p_what"] ] }, { @@ -4172,7 +4263,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"] + ["const godot_string *", "p_what"] ] }, { @@ -4180,7 +4271,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"] ] }, @@ -4189,7 +4280,7 @@ "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_what"], + ["const godot_string *", "p_what"], ["godot_int", "p_from"] ] }, @@ -4237,15 +4328,15 @@ ] }, { - "name": "godot_string_to_float", - "return_type": "double", + "name": "godot_string_to_int", + "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"] ] }, { - "name": "godot_string_to_int", - "return_type": "godot_int", + "name": "godot_string_to_float", + "return_type": "double", "arguments": [ ["const godot_string *", "p_self"] ] @@ -4279,6 +4370,14 @@ ] }, { + "name": "godot_string_wchar_to_float", + "return_type": "double", + "arguments": [ + ["const wchar_t *", "p_str"], + ["const wchar_t **", "r_end"] + ] + }, + { "name": "godot_string_char_to_int", "return_type": "godot_int", "arguments": [ @@ -4287,7 +4386,7 @@ }, { "name": "godot_string_wchar_to_int", - "return_type": "int64_t", + "return_type": "godot_int", "arguments": [ ["const wchar_t *", "p_str"] ] @@ -4301,48 +4400,33 @@ ] }, { - "name": "godot_string_char_to_int64_with_len", - "return_type": "int64_t", + "name": "godot_string_wchar_to_int_with_len", + "return_type": "godot_int", "arguments": [ ["const wchar_t *", "p_str"], ["int", "p_len"] ] }, { - "name": "godot_string_hex_to_int64", - "return_type": "int64_t", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, - { - "name": "godot_string_hex_to_int64_with_prefix", - "return_type": "int64_t", + "name": "godot_string_hex_to_int", + "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"] ] }, { - "name": "godot_string_to_int64", - "return_type": "int64_t", + "name": "godot_string_hex_to_int_with_prefix", + "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"] ] }, { - "name": "godot_string_unicode_char_to_float", - "return_type": "double", - "arguments": [ - ["const wchar_t *", "p_str"], - ["const wchar_t **", "r_end"] - ] - }, - { "name": "godot_string_get_slice_count", "return_type": "godot_int", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_splitter"] + ["const godot_string *", "p_splitter"] ] }, { @@ -4350,7 +4434,7 @@ "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["godot_string", "p_splitter"], + ["const godot_string *", "p_splitter"], ["godot_int", "p_slice"] ] }, @@ -4359,13 +4443,13 @@ "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["wchar_t", "p_splitter"], + ["godot_char_type", "p_splitter"], ["godot_int", "p_slice"] ] }, { "name": "godot_string_split", - "return_type": "godot_array", + "return_type": "godot_packed_string_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] @@ -4373,23 +4457,59 @@ }, { "name": "godot_string_split_allow_empty", - "return_type": "godot_array", + "return_type": "godot_packed_string_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] ] }, { + "name": "godot_string_split_with_maxsplit", + "return_type": "godot_packed_string_array", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_string *", "p_splitter"], + ["const godot_bool", "p_allow_empty"], + ["const godot_int", "p_maxsplit"] + ] + }, + { + "name": "godot_string_rsplit", + "return_type": "godot_packed_string_array", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_string *", "p_splitter"] + ] + }, + { + "name": "godot_string_rsplit_allow_empty", + "return_type": "godot_packed_string_array", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_string *", "p_splitter"] + ] + }, + { + "name": "godot_string_rsplit_with_maxsplit", + "return_type": "godot_packed_string_array", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_string *", "p_splitter"], + ["const godot_bool", "p_allow_empty"], + ["const godot_int", "p_maxsplit"] + ] + }, + { "name": "godot_string_split_floats", - "return_type": "godot_array", + "return_type": "godot_packed_float32_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] ] }, { - "name": "godot_string_split_floats_allows_empty", - "return_type": "godot_array", + "name": "godot_string_split_floats_allow_empty", + "return_type": "godot_packed_float32_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] @@ -4397,31 +4517,31 @@ }, { "name": "godot_string_split_floats_mk", - "return_type": "godot_array", + "return_type": "godot_packed_float32_array", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_splitters"] + ["const godot_packed_string_array *", "p_splitters"] ] }, { - "name": "godot_string_split_floats_mk_allows_empty", - "return_type": "godot_array", + "name": "godot_string_split_floats_mk_allow_empty", + "return_type": "godot_packed_float32_array", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_splitters"] + ["const godot_packed_string_array *", "p_splitters"] ] }, { "name": "godot_string_split_ints", - "return_type": "godot_array", + "return_type": "godot_packed_int32_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] ] }, { - "name": "godot_string_split_ints_allows_empty", - "return_type": "godot_array", + "name": "godot_string_split_ints_allow_empty", + "return_type": "godot_packed_int32_array", "arguments": [ ["const godot_string *", "p_self"], ["const godot_string *", "p_splitter"] @@ -4429,29 +4549,29 @@ }, { "name": "godot_string_split_ints_mk", - "return_type": "godot_array", + "return_type": "godot_packed_int32_array", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_splitters"] + ["const godot_packed_string_array *", "p_splitters"] ] }, { - "name": "godot_string_split_ints_mk_allows_empty", - "return_type": "godot_array", + "name": "godot_string_split_ints_mk_allow_empty", + "return_type": "godot_packed_int32_array", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_array *", "p_splitters"] + ["const godot_packed_string_array *", "p_splitters"] ] }, { "name": "godot_string_split_spaces", - "return_type": "godot_array", + "return_type": "godot_packed_string_array", "arguments": [ ["const godot_string *", "p_self"] ] }, { - "name": "godot_string_rstrip", + "name": "godot_string_lstrip", "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], @@ -4459,13 +4579,11 @@ ] }, { - "name": "godot_string_rsplit", - "return_type": "godot_packed_string_array", + "name": "godot_string_rstrip", + "return_type": "godot_string", "arguments": [ ["const godot_string *", "p_self"], - ["const godot_string *", "p_divisor"], - ["const godot_bool", "p_allow_empty"], - ["const godot_int", "p_maxsplit"] + ["const godot_string *", "p_chars"] ] }, { @@ -4486,16 +4604,16 @@ }, { "name": "godot_string_char_lowercase", - "return_type": "wchar_t", + "return_type": "godot_char_type", "arguments": [ - ["wchar_t", "p_char"] + ["godot_char_type", "p_char"] ] }, { "name": "godot_string_char_uppercase", - "return_type": "wchar_t", + "return_type": "godot_char_type", "arguments": [ - ["wchar_t", "p_char"] + ["godot_char_type", "p_char"] ] }, { @@ -4536,7 +4654,7 @@ }, { "name": "godot_string_ord_at", - "return_type": "wchar_t", + "return_type": "godot_char_type", "arguments": [ ["const godot_string *", "p_self"], ["godot_int", "p_idx"] @@ -4559,6 +4677,14 @@ ] }, { + "name": "godot_string_repeat", + "return_type": "godot_string", + "arguments": [ + ["const godot_string *", "p_self"], + ["godot_int", "p_count"] + ] + }, + { "name": "godot_string_strip_edges", "return_type": "godot_string", "arguments": [ @@ -4591,7 +4717,7 @@ ] }, { - "name": "godot_string_ascii_extended", + "name": "godot_string_latin1", "return_type": "godot_char_string", "arguments": [ ["const godot_string *", "p_self"] @@ -4622,17 +4748,26 @@ ] }, { - "name": "godot_string_chars_to_utf8", - "return_type": "godot_string", + "name": "godot_string_utf16", + "return_type": "godot_char16_string", "arguments": [ - ["const char *", "p_utf8"] + ["const godot_string *", "p_self"] ] }, { - "name": "godot_string_chars_to_utf8_with_len", - "return_type": "godot_string", + "name": "godot_string_parse_utf16", + "return_type": "godot_bool", "arguments": [ - ["const char *", "p_utf8"], + ["godot_string *", "p_self"], + ["const char16_t *", "p_utf16"] + ] + }, + { + "name": "godot_string_parse_utf16_with_len", + "return_type": "godot_bool", + "arguments": [ + ["godot_string *", "p_self"], + ["const char16_t *", "p_utf16"], ["godot_int", "p_len"] ] }, @@ -4666,14 +4801,14 @@ ] }, { - "name": "godot_string_hash_utf8_chars", + "name": "godot_string_hash_wide_chars", "return_type": "uint32_t", "arguments": [ ["const wchar_t *", "p_str"] ] }, { - "name": "godot_string_hash_utf8_chars_with_len", + "name": "godot_string_hash_wide_chars_with_len", "return_type": "uint32_t", "arguments": [ ["const wchar_t *", "p_str"], @@ -4695,6 +4830,20 @@ ] }, { + "name": "godot_string_sha1_buffer", + "return_type": "godot_packed_byte_array", + "arguments": [ + ["const godot_string *", "p_self"] + ] + }, + { + "name": "godot_string_sha1_text", + "return_type": "godot_string", + "arguments": [ + ["const godot_string *", "p_self"] + ] + }, + { "name": "godot_string_sha256_buffer", "return_type": "godot_packed_byte_array", "arguments": [ @@ -4823,14 +4972,6 @@ ] }, { - "name": "godot_string_word_wrap", - "return_type": "godot_string", - "arguments": [ - ["const godot_string *", "p_self"], - ["godot_int", "p_chars_per_line"] - ] - }, - { "name": "godot_string_xml_escape", "return_type": "godot_string", "arguments": [ @@ -4866,6 +5007,21 @@ ] }, { + "name": "godot_string_join", + "return_type": "godot_string", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_packed_string_array *", "p_parts"] + ] + }, + { + "name": "godot_string_is_valid_filename", + "return_type": "godot_bool", + "arguments": [ + ["const godot_string *", "p_self"] + ] + }, + { "name": "godot_string_is_valid_float", "return_type": "godot_bool", "arguments": [ diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index d89383dc1b..0582d95f63 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -38,10 +38,11 @@ extern "C" { #include <stdint.h> #include <wchar.h> -typedef wchar_t godot_char_type; +typedef char32_t godot_char_type; #define GODOT_STRING_SIZE sizeof(void *) #define GODOT_CHAR_STRING_SIZE sizeof(void *) +#define GODOT_CHAR16_STRING_SIZE sizeof(void *) #ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED #define GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED @@ -58,6 +59,13 @@ typedef struct { } godot_char_string; #endif +#ifndef GODOT_CORE_API_GODOT_CHAR16_STRING_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_CHAR16_STRING_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_CHAR16_STRING_SIZE]; +} godot_char16_string; +#endif + // reduce extern "C" nesting for VS2013 #ifdef __cplusplus } @@ -75,13 +83,28 @@ godot_int GDAPI godot_char_string_length(const godot_char_string *p_cs); const char GDAPI *godot_char_string_get_data(const godot_char_string *p_cs); void GDAPI godot_char_string_destroy(godot_char_string *p_cs); +godot_int GDAPI godot_char16_string_length(const godot_char16_string *p_cs); +const char16_t GDAPI *godot_char16_string_get_data(const godot_char16_string *p_cs); +void GDAPI godot_char16_string_destroy(godot_char16_string *p_cs); + void GDAPI godot_string_new(godot_string *r_dest); void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src); -void GDAPI godot_string_new_with_wide_string(godot_string *r_dest, const wchar_t *p_contents, const int p_size); -const wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); -wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); -const wchar_t GDAPI *godot_string_wide_str(const godot_string *p_self); +void GDAPI godot_string_new_with_latin1_chars(godot_string *r_dest, const char *p_contents); +void GDAPI godot_string_new_with_utf8_chars(godot_string *r_dest, const char *p_contents); +void GDAPI godot_string_new_with_utf16_chars(godot_string *r_dest, const char16_t *p_contents); +void GDAPI godot_string_new_with_utf32_chars(godot_string *r_dest, const char32_t *p_contents); +void GDAPI godot_string_new_with_wide_chars(godot_string *r_dest, const wchar_t *p_contents); + +void GDAPI godot_string_new_with_latin1_chars_and_len(godot_string *r_dest, const char *p_contents, const int p_size); +void GDAPI godot_string_new_with_utf8_chars_and_len(godot_string *r_dest, const char *p_contents, const int p_size); +void GDAPI godot_string_new_with_utf16_chars_and_len(godot_string *r_dest, const char16_t *p_contents, const int p_size); +void GDAPI godot_string_new_with_utf32_chars_and_len(godot_string *r_dest, const char32_t *p_contents, const int p_size); +void GDAPI godot_string_new_with_wide_chars_and_len(godot_string *r_dest, const wchar_t *p_contents, const int p_size); + +const godot_char_type GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); +godot_char_type GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); +const godot_char_type GDAPI *godot_string_get_data(const godot_string *p_self); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b); godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b); @@ -89,7 +112,7 @@ godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const /* Standard size stuff */ -godot_int GDAPI godot_string_length(const godot_string *p_self); +/*+++*/ godot_int GDAPI godot_string_length(const godot_string *p_self); /* Helpers */ @@ -99,24 +122,25 @@ signed char GDAPI godot_string_naturalnocasecmp_to(const godot_string *p_self, c godot_bool GDAPI godot_string_begins_with(const godot_string *p_self, const godot_string *p_string); godot_bool GDAPI godot_string_begins_with_char_array(const godot_string *p_self, const char *p_char_array); -godot_array GDAPI godot_string_bigrams(const godot_string *p_self); -godot_string GDAPI godot_string_chr(wchar_t p_character); +godot_packed_string_array GDAPI godot_string_bigrams(const godot_string *p_self); +godot_string GDAPI godot_string_chr(godot_char_type p_character); godot_bool GDAPI godot_string_ends_with(const godot_string *p_self, const godot_string *p_string); -godot_int GDAPI godot_string_count(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to); -godot_int GDAPI godot_string_countn(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to); -godot_int GDAPI godot_string_find(const godot_string *p_self, godot_string p_what); -godot_int GDAPI godot_string_find_from(const godot_string *p_self, godot_string p_what, godot_int p_from); -godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_array *p_keys); -godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_array *p_keys, godot_int p_from); -godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key); -godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what); -godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_bool GDAPI godot_string_ends_with_char_array(const godot_string *p_self, const char *p_char_array); +godot_int GDAPI godot_string_count(const godot_string *p_self, const godot_string *p_what, godot_int p_from, godot_int p_to); +godot_int GDAPI godot_string_countn(const godot_string *p_self, const godot_string *p_what, godot_int p_from, godot_int p_to); +godot_int GDAPI godot_string_find(const godot_string *p_self, const godot_string *p_what); +godot_int GDAPI godot_string_find_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from); +godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_packed_string_array *p_keys); +godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_packed_string_array *p_keys, godot_int p_from); +godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_packed_string_array *p_keys, godot_int p_from, godot_int *r_key); +godot_int GDAPI godot_string_findn(const godot_string *p_self, const godot_string *p_what); +godot_int GDAPI godot_string_findn_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from); godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values); godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder); godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len); godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self); -godot_int GDAPI godot_string_hex_to_int_without_prefix(const godot_string *p_self); -godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, godot_string p_string); +godot_int GDAPI godot_string_hex_to_int_with_prefix(const godot_string *p_self); +godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, const godot_string *p_string); godot_bool GDAPI godot_string_is_numeric(const godot_string *p_self); godot_bool GDAPI godot_string_is_subsequence_of(const godot_string *p_self, const godot_string *p_string); godot_bool GDAPI godot_string_is_subsequence_ofi(const godot_string *p_self, const godot_string *p_string); @@ -133,13 +157,13 @@ godot_string GDAPI godot_string_num_scientific(double p_num); godot_string GDAPI godot_string_num_with_decimals(double p_num, godot_int p_decimals); godot_string GDAPI godot_string_pad_decimals(const godot_string *p_self, godot_int p_digits); godot_string GDAPI godot_string_pad_zeros(const godot_string *p_self, godot_int p_digits); -godot_string GDAPI godot_string_replace_first(const godot_string *p_self, godot_string p_key, godot_string p_with); -godot_string GDAPI godot_string_replace(const godot_string *p_self, godot_string p_key, godot_string p_with); -godot_string GDAPI godot_string_replacen(const godot_string *p_self, godot_string p_key, godot_string p_with); -godot_int GDAPI godot_string_rfind(const godot_string *p_self, godot_string p_what); -godot_int GDAPI godot_string_rfindn(const godot_string *p_self, godot_string p_what); -godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, godot_string p_what, godot_int p_from); -godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_string GDAPI godot_string_replace_first(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with); +godot_string GDAPI godot_string_replace(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with); +godot_string GDAPI godot_string_replacen(const godot_string *p_self, const godot_string *p_key, const godot_string *p_with); +godot_int GDAPI godot_string_rfind(const godot_string *p_self, const godot_string *p_what); +godot_int GDAPI godot_string_rfindn(const godot_string *p_self, const godot_string *p_what); +godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from); +godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, const godot_string *p_what, godot_int p_from); godot_string GDAPI godot_string_rpad(const godot_string *p_self, godot_int p_min_length); godot_string GDAPI godot_string_rpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character); godot_real GDAPI godot_string_similarity(const godot_string *p_self, const godot_string *p_string); @@ -151,64 +175,79 @@ godot_int GDAPI godot_string_to_int(const godot_string *p_self); godot_string GDAPI godot_string_camelcase_to_underscore(const godot_string *p_self); godot_string GDAPI godot_string_camelcase_to_underscore_lowercased(const godot_string *p_self); godot_string GDAPI godot_string_capitalize(const godot_string *p_self); + double GDAPI godot_string_char_to_float(const char *p_what); +double GDAPI godot_string_wchar_to_float(const wchar_t *p_str, const wchar_t **r_end); + godot_int GDAPI godot_string_char_to_int(const char *p_what); -int64_t GDAPI godot_string_wchar_to_int(const wchar_t *p_str); +godot_int GDAPI godot_string_wchar_to_int(const wchar_t *p_str); + godot_int GDAPI godot_string_char_to_int_with_len(const char *p_what, godot_int p_len); -int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_len); -int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self); -int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self); -int64_t GDAPI godot_string_to_int64(const godot_string *p_self); -double GDAPI godot_string_unicode_char_to_float(const wchar_t *p_str, const wchar_t **r_end); - -godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, godot_string p_splitter); -godot_string GDAPI godot_string_get_slice(const godot_string *p_self, godot_string p_splitter, godot_int p_slice); -godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p_splitter, godot_int p_slice); - -godot_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_floats_allows_empty(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_array *p_splitters); -godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters); -godot_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_ints_allows_empty(const godot_string *p_self, const godot_string *p_splitter); -godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_array *p_splitters); -godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters); -godot_array GDAPI godot_string_split_spaces(const godot_string *p_self); - -wchar_t GDAPI godot_string_char_lowercase(wchar_t p_char); -wchar_t GDAPI godot_string_char_uppercase(wchar_t p_char); +godot_int GDAPI godot_string_wchar_to_int_with_len(const wchar_t *p_str, int p_len); + +godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, const godot_string *p_splitter); +godot_string GDAPI godot_string_get_slice(const godot_string *p_self, const godot_string *p_splitter, godot_int p_slice); +godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, godot_char_type p_splitter, godot_int p_slice); + +godot_packed_string_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_string_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_string_array GDAPI godot_string_split_with_maxsplit(const godot_string *p_self, const godot_string *p_splitter, const godot_bool p_allow_empty, const godot_int p_maxsplit); + +godot_packed_string_array GDAPI godot_string_rsplit(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_string_array GDAPI godot_string_rsplit_allow_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_string_array GDAPI godot_string_rsplit_with_maxsplit(const godot_string *p_self, const godot_string *p_splitter, const godot_bool p_allow_empty, const godot_int p_maxsplit); + +godot_packed_float32_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_float32_array GDAPI godot_string_split_floats_allow_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_float32_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_packed_string_array *p_splitters); +godot_packed_float32_array GDAPI godot_string_split_floats_mk_allow_empty(const godot_string *p_self, const godot_packed_string_array *p_splitters); +godot_packed_int32_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_int32_array GDAPI godot_string_split_ints_allow_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_packed_int32_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_packed_string_array *p_splitters); +godot_packed_int32_array GDAPI godot_string_split_ints_mk_allow_empty(const godot_string *p_self, const godot_packed_string_array *p_splitters); + +godot_packed_string_array GDAPI godot_string_split_spaces(const godot_string *p_self); + +godot_char_type GDAPI godot_string_char_lowercase(godot_char_type p_char); +godot_char_type GDAPI godot_string_char_uppercase(godot_char_type p_char); godot_string GDAPI godot_string_to_lower(const godot_string *p_self); godot_string GDAPI godot_string_to_upper(const godot_string *p_self); godot_string GDAPI godot_string_get_basename(const godot_string *p_self); godot_string GDAPI godot_string_get_extension(const godot_string *p_self); godot_string GDAPI godot_string_left(const godot_string *p_self, godot_int p_pos); -wchar_t GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx); +godot_char_type GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx); godot_string GDAPI godot_string_plus_file(const godot_string *p_self, const godot_string *p_file); godot_string GDAPI godot_string_right(const godot_string *p_self, godot_int p_pos); +godot_string GDAPI godot_string_repeat(const godot_string *p_self, godot_int p_count); godot_string GDAPI godot_string_strip_edges(const godot_string *p_self, godot_bool p_left, godot_bool p_right); godot_string GDAPI godot_string_strip_escapes(const godot_string *p_self); void GDAPI godot_string_erase(godot_string *p_self, godot_int p_pos, godot_int p_chars); godot_char_string GDAPI godot_string_ascii(const godot_string *p_self); -godot_char_string GDAPI godot_string_ascii_extended(const godot_string *p_self); +godot_char_string GDAPI godot_string_latin1(const godot_string *p_self); + godot_char_string GDAPI godot_string_utf8(const godot_string *p_self); godot_bool GDAPI godot_string_parse_utf8(godot_string *p_self, const char *p_utf8); godot_bool GDAPI godot_string_parse_utf8_with_len(godot_string *p_self, const char *p_utf8, godot_int p_len); -godot_string GDAPI godot_string_chars_to_utf8(const char *p_utf8); -godot_string GDAPI godot_string_chars_to_utf8_with_len(const char *p_utf8, godot_int p_len); + +godot_char16_string GDAPI godot_string_utf16(const godot_string *p_self); +godot_bool GDAPI godot_string_parse_utf16(godot_string *p_self, const char16_t *p_utf16); +godot_bool GDAPI godot_string_parse_utf16_with_len(godot_string *p_self, const char16_t *p_utf16, godot_int p_len); uint32_t GDAPI godot_string_hash(const godot_string *p_self); uint64_t GDAPI godot_string_hash64(const godot_string *p_self); + uint32_t GDAPI godot_string_hash_chars(const char *p_cstr); uint32_t GDAPI godot_string_hash_chars_with_len(const char *p_cstr, godot_int p_len); -uint32_t GDAPI godot_string_hash_utf8_chars(const wchar_t *p_str); -uint32_t GDAPI godot_string_hash_utf8_chars_with_len(const wchar_t *p_str, godot_int p_len); +uint32_t GDAPI godot_string_hash_wide_chars(const wchar_t *p_str); +uint32_t GDAPI godot_string_hash_wide_chars_with_len(const wchar_t *p_str, godot_int p_len); + godot_packed_byte_array GDAPI godot_string_md5_buffer(const godot_string *p_self); godot_string GDAPI godot_string_md5_text(const godot_string *p_self); +godot_packed_byte_array GDAPI godot_string_sha1_buffer(const godot_string *p_self); +godot_string GDAPI godot_string_sha1_text(const godot_string *p_self); godot_packed_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self); godot_string GDAPI godot_string_sha256_text(const godot_string *p_self); @@ -231,14 +270,15 @@ godot_string GDAPI godot_string_c_unescape(const godot_string *p_self); godot_string GDAPI godot_string_http_escape(const godot_string *p_self); godot_string GDAPI godot_string_http_unescape(const godot_string *p_self); godot_string GDAPI godot_string_json_escape(const godot_string *p_self); -godot_string GDAPI godot_string_word_wrap(const godot_string *p_self, godot_int p_chars_per_line); godot_string GDAPI godot_string_xml_escape(const godot_string *p_self); godot_string GDAPI godot_string_xml_escape_with_quotes(const godot_string *p_self); godot_string GDAPI godot_string_xml_unescape(const godot_string *p_self); godot_string GDAPI godot_string_percent_decode(const godot_string *p_self); godot_string GDAPI godot_string_percent_encode(const godot_string *p_self); +godot_string GDAPI godot_string_join(const godot_string *p_self, const godot_packed_string_array *p_parts); +godot_bool GDAPI godot_string_is_valid_filename(const godot_string *p_self); godot_bool GDAPI godot_string_is_valid_float(const godot_string *p_self); godot_bool GDAPI godot_string_is_valid_hex_number(const godot_string *p_self, godot_bool p_with_prefix); godot_bool GDAPI godot_string_is_valid_html_color(const godot_string *p_self); @@ -249,8 +289,8 @@ godot_bool GDAPI godot_string_is_valid_ip_address(const godot_string *p_self); godot_string GDAPI godot_string_dedent(const godot_string *p_self); godot_string GDAPI godot_string_trim_prefix(const godot_string *p_self, const godot_string *p_prefix); godot_string GDAPI godot_string_trim_suffix(const godot_string *p_self, const godot_string *p_suffix); +godot_string GDAPI godot_string_lstrip(const godot_string *p_self, const godot_string *p_chars); godot_string GDAPI godot_string_rstrip(const godot_string *p_self, const godot_string *p_chars); -godot_packed_string_array GDAPI godot_string_rsplit(const godot_string *p_self, const godot_string *p_divisor, const godot_bool p_allow_empty, const godot_int p_maxsplit); void GDAPI godot_string_destroy(godot_string *p_self); diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 019fa0d1f8..8dbaec4e75 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -176,10 +176,10 @@ List<ClassAPI> generate_c_api_classes() { // Register global constants as a fake GlobalConstants singleton class { ClassAPI global_constants_api; - global_constants_api.class_name = L"GlobalConstants"; + global_constants_api.class_name = "GlobalConstants"; global_constants_api.api_type = ClassDB::API_CORE; global_constants_api.is_singleton = true; - global_constants_api.singleton_name = L"GlobalConstants"; + global_constants_api.singleton_name = "GlobalConstants"; global_constants_api.is_instanciable = false; const int constants_count = GlobalConstants::get_global_constant_count(); for (int i = 0; i < constants_count; ++i) { diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index e2038954e3..9a3273d201 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -33,15 +33,15 @@ #include "../gdscript_tokenizer.h" #include "editor/editor_settings.h" -static bool _is_char(CharType c) { +static bool _is_char(char32_t c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; } -static bool _is_hex_symbol(CharType c) { +static bool _is_hex_symbol(char32_t c) { return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); } -static bool _is_bin_symbol(CharType c) { +static bool _is_bin_symbol(char32_t c) { return (c == '0' || c == '1'); } @@ -119,7 +119,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) /* search the line */ bool match = true; - const CharType *start_key = color_regions[c].start_key.c_str(); + const char32_t *start_key = color_regions[c].start_key.get_data(); for (int k = 0; k < start_key_length; k++) { if (start_key[k] != str[from + k]) { match = false; @@ -156,7 +156,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) /* search the line */ int region_end_index = -1; int end_key_length = color_regions[in_region].end_key.length(); - const CharType *end_key = color_regions[in_region].end_key.c_str(); + const char32_t *end_key = color_regions[in_region].end_key.get_data(); for (; from < line_length; from++) { if (line_length - from < end_key_length) { break; diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index fefbf906f0..31ce63bc6e 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -635,7 +635,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case TEXT_CHAR: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - CharType result[2] = { *p_args[0], 0 }; + char32_t result[2] = { *p_args[0], 0 }; r_ret = String(result); } break; case TEXT_ORD: { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index d890103f15..e8dea8180a 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -327,7 +327,7 @@ Error GDScriptParser::parse(const String &p_source_code, const String &p_script_ bool found = false; const String &line = lines[i]; for (int j = 0; j < line.size(); j++) { - if (line[j] == CharType(0xFFFF)) { + if (line[j] == char32_t(0xFFFF)) { found = true; break; } else if (line[j] == '\t') { diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index f5cf1e29f0..ed27604aec 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -222,7 +222,7 @@ String GDScriptTokenizer::get_token_name(Token::Type p_token_type) { void GDScriptTokenizer::set_source_code(const String &p_source_code) { source = p_source_code; if (source.empty()) { - _source = L""; + _source = U""; } else { _source = source.ptr(); } @@ -263,7 +263,7 @@ bool GDScriptTokenizer::is_past_cursor() const { return true; } -CharType GDScriptTokenizer::_advance() { +char32_t GDScriptTokenizer::_advance() { if (unlikely(_is_at_end())) { return '\0'; } @@ -282,15 +282,15 @@ CharType GDScriptTokenizer::_advance() { return _peek(-1); } -void GDScriptTokenizer::push_paren(CharType p_char) { +void GDScriptTokenizer::push_paren(char32_t p_char) { paren_stack.push_back(p_char); } -bool GDScriptTokenizer::pop_paren(CharType p_expected) { +bool GDScriptTokenizer::pop_paren(char32_t p_expected) { if (paren_stack.empty()) { return false; } - CharType actual = paren_stack.back()->get(); + char32_t actual = paren_stack.back()->get(); paren_stack.pop_back(); return actual == p_expected; @@ -302,19 +302,19 @@ GDScriptTokenizer::Token GDScriptTokenizer::pop_error() { return error; } -static bool _is_alphanumeric(CharType c) { +static bool _is_alphanumeric(char32_t c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } -static bool _is_digit(CharType c) { +static bool _is_digit(char32_t c) { return (c >= '0' && c <= '9'); } -static bool _is_hex_digit(CharType c) { +static bool _is_hex_digit(char32_t c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } -static bool _is_binary_digit(CharType c) { +static bool _is_binary_digit(char32_t c) { return (c == '0' || c == '1'); } @@ -404,7 +404,7 @@ void GDScriptTokenizer::push_error(const Token &p_error) { error_stack.push_back(p_error); } -GDScriptTokenizer::Token GDScriptTokenizer::make_paren_error(CharType p_paren) { +GDScriptTokenizer::Token GDScriptTokenizer::make_paren_error(char32_t p_paren) { if (paren_stack.empty()) { return make_error(vformat("Closing \"%c\" doesn't have an opening counterpart.", p_paren)); } @@ -413,8 +413,8 @@ GDScriptTokenizer::Token GDScriptTokenizer::make_paren_error(CharType p_paren) { return error; } -GDScriptTokenizer::Token GDScriptTokenizer::check_vcs_marker(CharType p_test, Token::Type p_double_type) { - const CharType *next = _current + 1; +GDScriptTokenizer::Token GDScriptTokenizer::check_vcs_marker(char32_t p_test, Token::Type p_double_type) { + const char32_t *next = _current + 1; int chars = 2; // Two already matched. // Test before consuming characters, since we don't want to consume more than needed. @@ -602,7 +602,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() { bool has_decimal = false; bool has_exponent = false; bool has_error = false; - bool (*digit_check_func)(CharType) = _is_digit; + bool (*digit_check_func)(char32_t) = _is_digit; if (_peek(-1) == '.') { has_decimal = true; @@ -762,7 +762,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() { _advance(); } - CharType quote_char = _peek(-1); + char32_t quote_char = _peek(-1); if (_peek() == quote_char && _peek(1) == quote_char) { is_multiline = true; @@ -779,7 +779,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() { return make_error("Unterminated string."); } - CharType ch = _peek(); + char32_t ch = _peek(); if (ch == '\\') { // Escape pattern. @@ -789,13 +789,13 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() { } // Grab escape character. - CharType code = _peek(); + char32_t code = _peek(); _advance(); if (_is_at_end()) { return make_error("Unterminated string."); } - CharType escaped = 0; + char32_t escaped = 0; bool valid_escape = true; switch (code) { @@ -836,8 +836,8 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() { return make_error("Unterminated string."); } - CharType digit = _peek(); - CharType value = 0; + char32_t digit = _peek(); + char32_t value = 0; if (digit >= '0' && digit <= '9') { value = digit - '0'; } else if (digit >= 'a' && digit <= 'f') { @@ -940,7 +940,7 @@ void GDScriptTokenizer::check_indent() { } for (;;) { - CharType current_indent_char = _peek(); + char32_t current_indent_char = _peek(); int indent_count = 0; if (current_indent_char != ' ' && current_indent_char != '\t' && current_indent_char != '\r' && current_indent_char != '\n' && current_indent_char != '#') { @@ -970,7 +970,7 @@ void GDScriptTokenizer::check_indent() { // Check indent level. bool mixed = false; while (!_is_at_end()) { - CharType space = _peek(); + char32_t space = _peek(); if (space == '\t') { // Consider individual tab columns. column += tab_size - 1; @@ -1103,7 +1103,7 @@ void GDScriptTokenizer::_skip_whitespace() { } for (;;) { - CharType c = _peek(); + char32_t c = _peek(); switch (c) { case ' ': _advance(); @@ -1192,7 +1192,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::scan() { return make_token(Token::TK_EOF); } - const CharType c = _advance(); + const char32_t c = _advance(); if (c == '\\') { // Line continuation with backslash. diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index 100ed3f132..4453982d08 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -183,14 +183,14 @@ public: private: String source; - const CharType *_source = nullptr; - const CharType *_current = nullptr; + const char32_t *_source = nullptr; + const char32_t *_current = nullptr; int line = -1, column = -1; int cursor_line = -1, cursor_column = -1; int tab_size = 4; // Keep track of multichar tokens. - const CharType *_start = nullptr; + const char32_t *_start = nullptr; int start_line = 0, start_column = 0; int leftmost_column = 0, rightmost_column = 0; @@ -202,30 +202,30 @@ private: Token last_newline; int pending_indents = 0; List<int> indent_stack; - List<CharType> paren_stack; - CharType indent_char = '\0'; + List<char32_t> paren_stack; + char32_t indent_char = '\0'; int position = 0; int length = 0; _FORCE_INLINE_ bool _is_at_end() { return position >= length; } - _FORCE_INLINE_ CharType _peek(int p_offset = 0) { return position + p_offset >= 0 && position + p_offset < length ? _current[p_offset] : '\0'; } + _FORCE_INLINE_ char32_t _peek(int p_offset = 0) { return position + p_offset >= 0 && position + p_offset < length ? _current[p_offset] : '\0'; } int indent_level() const { return indent_stack.size(); } bool has_error() const { return !error_stack.empty(); } Token pop_error(); - CharType _advance(); + char32_t _advance(); void _skip_whitespace(); void check_indent(); Token make_error(const String &p_message); void push_error(const String &p_message); void push_error(const Token &p_error); - Token make_paren_error(CharType p_paren); + Token make_paren_error(char32_t p_paren); Token make_token(Token::Type p_type); Token make_literal(const Variant &p_literal); Token make_identifier(const StringName &p_identifier); - Token check_vcs_marker(CharType p_test, Token::Type p_double_type); - void push_paren(CharType p_char); - bool pop_paren(CharType p_expected); + Token check_vcs_marker(char32_t p_test, Token::Type p_double_type); + void push_paren(char32_t p_char); + bool pop_paren(char32_t p_expected); void newline(bool p_make_token); Token number(); diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 4d79d9d395..668dfd4835 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -491,7 +491,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position & int start_pos = p_position.character; for (int c = p_position.character; c >= 0; c--) { start_pos = c; - CharType ch = line[c]; + char32_t ch = line[c]; bool valid_char = (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'; if (!valid_char) { break; @@ -500,7 +500,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position & int end_pos = p_position.character; for (int c = p_position.character; c < line.length(); c++) { - CharType ch = line[c]; + char32_t ch = line[c]; bool valid_char = (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'; if (!valid_char) { break; @@ -552,7 +552,7 @@ Error ExtendGDScriptParser::get_left_function_call(const lsp::Position &p_positi } while (c >= 0) { - const CharType &character = line[c]; + const char32_t &character = line[c]; if (character == ')') { ++bracket_stack; } else if (character == '(') { diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index 430c82953e..f7d6e7e302 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -151,7 +151,7 @@ ScriptClassParser::Token ScriptClassParser::get_token() { case '"': { bool verbatim = idx != 0 && code[idx - 1] == '@'; - CharType begin_str = code[idx]; + char32_t begin_str = code[idx]; idx++; String tk_string = String(); while (true) { @@ -170,13 +170,13 @@ ScriptClassParser::Token ScriptClassParser::get_token() { } else if (code[idx] == '\\' && !verbatim) { //escaped characters... idx++; - CharType next = code[idx]; + char32_t next = code[idx]; if (next == 0) { error_str = "Unterminated String"; error = true; return TK_ERROR; } - CharType res = 0; + char32_t res = 0; switch (next) { case 'b': @@ -234,7 +234,7 @@ ScriptClassParser::Token ScriptClassParser::get_token() { if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) { //a number - const CharType *rptr; + const char32_t *rptr; double number = String::to_float(&code[idx], &rptr); idx += (rptr - &code[idx]); value = number; diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 6d7d5f76cd..c460e283ea 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -311,44 +311,6 @@ bool try_get_array_element_type(const ManagedType &p_array_type, ManagedType &r_ return false; } -String mono_to_utf8_string(MonoString *p_mono_string) { - MonoError error; - char *utf8 = mono_string_to_utf8_checked(p_mono_string, &error); - - if (!mono_error_ok(&error)) { - ERR_PRINT(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&error) + "'."); - mono_error_cleanup(&error); - return String(); - } - - String ret = String::utf8(utf8); - - mono_free(utf8); - - return ret; -} - -String mono_to_utf16_string(MonoString *p_mono_string) { - int len = mono_string_length(p_mono_string); - String ret; - - if (len == 0) { - return ret; - } - - ret.resize(len + 1); - ret.set(len, 0); - - CharType *src = (CharType *)mono_string_chars(p_mono_string); - CharType *dst = ret.ptrw(); - - for (int i = 0; i < len; i++) { - dst[i] = src[i]; - } - - return ret; -} - MonoObject *variant_to_mono_object(const Variant *p_var) { ManagedType type; diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index 4ff330fd43..a1fd975916 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -69,15 +69,11 @@ bool try_get_array_element_type(const ManagedType &p_array_type, ManagedType &r_ // String -String mono_to_utf8_string(MonoString *p_mono_string); -String mono_to_utf16_string(MonoString *p_mono_string); - _FORCE_INLINE_ String mono_string_to_godot_not_null(MonoString *p_mono_string) { - if constexpr (sizeof(CharType) == 2) { - return mono_to_utf16_string(p_mono_string); - } - - return mono_to_utf8_string(p_mono_string); + char32_t *utf32 = (char32_t *)mono_string_to_utf32(p_mono_string); + String ret = String(utf32); + mono_free(utf32); + return ret; } _FORCE_INLINE_ String mono_string_to_godot(MonoString *p_mono_string) { @@ -88,20 +84,8 @@ _FORCE_INLINE_ String mono_string_to_godot(MonoString *p_mono_string) { return mono_string_to_godot_not_null(p_mono_string); } -_FORCE_INLINE_ MonoString *mono_from_utf8_string(const String &p_string) { - return mono_string_new(mono_domain_get(), p_string.utf8().get_data()); -} - -_FORCE_INLINE_ MonoString *mono_from_utf16_string(const String &p_string) { - return mono_string_from_utf16((mono_unichar2 *)p_string.c_str()); -} - _FORCE_INLINE_ MonoString *mono_string_from_godot(const String &p_string) { - if constexpr (sizeof(CharType) == 2) { - return mono_from_utf16_string(p_string); - } - - return mono_from_utf8_string(p_string); + return mono_string_from_utf32((mono_unichar4 *)(p_string.get_data())); } // Variant diff --git a/modules/mono/utils/mono_reg_utils.cpp b/modules/mono/utils/mono_reg_utils.cpp index e0cf916a01..a619f0b975 100644 --- a/modules/mono/utils/mono_reg_utils.cpp +++ b/modules/mono/utils/mono_reg_utils.cpp @@ -71,12 +71,12 @@ LONG _RegKeyQueryString(HKEY hKey, const String &p_value_name, String &r_value) buffer.resize(512); DWORD dwBufferSize = buffer.size(); - LONG res = RegQueryValueExW(hKey, p_value_name.c_str(), 0, nullptr, (LPBYTE)buffer.ptr(), &dwBufferSize); + LONG res = RegQueryValueExW(hKey, (LPCWSTR)(p_value_name.utf16().get_data()), 0, nullptr, (LPBYTE)buffer.ptr(), &dwBufferSize); if (res == ERROR_MORE_DATA) { // dwBufferSize now contains the actual size buffer.resize(dwBufferSize); - res = RegQueryValueExW(hKey, p_value_name.c_str(), 0, nullptr, (LPBYTE)buffer.ptr(), &dwBufferSize); + res = RegQueryValueExW(hKey, (LPCWSTR)(p_value_name.utf16().get_data()), 0, nullptr, (LPBYTE)buffer.ptr(), &dwBufferSize); } if (res == ERROR_SUCCESS) { @@ -90,7 +90,7 @@ LONG _RegKeyQueryString(HKEY hKey, const String &p_value_name, String &r_value) LONG _find_mono_in_reg(const String &p_subkey, MonoRegInfo &r_info, bool p_old_reg = false) { HKEY hKey; - LONG res = _RegOpenKey(HKEY_LOCAL_MACHINE, p_subkey.c_str(), &hKey); + LONG res = _RegOpenKey(HKEY_LOCAL_MACHINE, (LPCWSTR)(p_subkey.utf16().get_data()), &hKey); if (res != ERROR_SUCCESS) goto cleanup; @@ -127,7 +127,7 @@ LONG _find_mono_in_reg_old(const String &p_subkey, MonoRegInfo &r_info) { String default_clr; HKEY hKey; - LONG res = _RegOpenKey(HKEY_LOCAL_MACHINE, p_subkey.c_str(), &hKey); + LONG res = _RegOpenKey(HKEY_LOCAL_MACHINE, (LPCWSTR)(p_subkey.utf16().get_data()), &hKey); if (res != ERROR_SUCCESS) goto cleanup; diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp index ccfaf5aba7..d91dcb5981 100644 --- a/modules/mono/utils/path_utils.cpp +++ b/modules/mono/utils/path_utils.cpp @@ -86,7 +86,7 @@ String abspath(const String &p_path) { String realpath(const String &p_path) { #ifdef WINDOWS_ENABLED // Open file without read/write access - HANDLE hFile = ::CreateFileW(p_path.c_str(), 0, + HANDLE hFile = ::CreateFileW((LPCWSTR)(p_path.utf16().get_data()), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); @@ -130,7 +130,7 @@ String join(const String &p_a, const String &p_b) { return p_b; } - const CharType a_last = p_a[p_a.length() - 1]; + const char32_t a_last = p_a[p_a.length() - 1]; if ((a_last == '/' || a_last == '\\') || (p_b.size() > 0 && (p_b[0] == '/' || p_b[0] == '\\'))) { return p_a + p_b; diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index f8d9804de4..65da4328f6 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -49,7 +49,7 @@ int sfind(const String &p_text, int p_from) { return -1; } - const CharType *src = p_text.c_str(); + const char32_t *src = p_text.get_data(); for (int i = p_from; i <= (len - src_len); i++) { bool found = true; @@ -64,7 +64,7 @@ int sfind(const String &p_text, int p_from) { found = src[read_pos] == '%'; break; case 1: { - CharType c = src[read_pos]; + char32_t c = src[read_pos]; found = src[read_pos] == 's' || (c >= '0' && c <= '4'); break; } @@ -121,7 +121,7 @@ String sformat(const String &p_text, const Variant &p1, const Variant &p2, const int result = 0; while ((result = sfind(p_text, search_from)) >= 0) { - CharType c = p_text[result + 1]; + char32_t c = p_text[result + 1]; int req_index = (c == 's' ? findex++ : c - '0'); diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index 50ca01067b..c10a276eae 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -156,26 +156,13 @@ void RegExMatch::_bind_methods() { } void RegEx::_pattern_info(uint32_t what, void *where) const { - if (sizeof(CharType) == 2) { - pcre2_pattern_info_16((pcre2_code_16 *)code, what, where); - - } else { - pcre2_pattern_info_32((pcre2_code_32 *)code, what, where); - } + pcre2_pattern_info_32((pcre2_code_32 *)code, what, where); } void RegEx::clear() { - if (sizeof(CharType) == 2) { - if (code) { - pcre2_code_free_16((pcre2_code_16 *)code); - code = nullptr; - } - - } else { - if (code) { - pcre2_code_free_32((pcre2_code_32 *)code); - code = nullptr; - } + if (code) { + pcre2_code_free_32((pcre2_code_32 *)code); + code = nullptr; } } @@ -187,39 +174,20 @@ Error RegEx::compile(const String &p_pattern) { PCRE2_SIZE offset; uint32_t flags = PCRE2_DUPNAMES; - if (sizeof(CharType) == 2) { - pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; - pcre2_compile_context_16 *cctx = pcre2_compile_context_create_16(gctx); - PCRE2_SPTR16 p = (PCRE2_SPTR16)pattern.c_str(); - - code = pcre2_compile_16(p, pattern.length(), flags, &err, &offset, cctx); + pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; + pcre2_compile_context_32 *cctx = pcre2_compile_context_create_32(gctx); + PCRE2_SPTR32 p = (PCRE2_SPTR32)pattern.get_data(); - pcre2_compile_context_free_16(cctx); + code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx); - if (!code) { - PCRE2_UCHAR16 buf[256]; - pcre2_get_error_message_16(err, buf, 256); - String message = String::num(offset) + ": " + String((const CharType *)buf); - ERR_PRINT(message.utf8()); - return FAILED; - } + pcre2_compile_context_free_32(cctx); - } else { - pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; - pcre2_compile_context_32 *cctx = pcre2_compile_context_create_32(gctx); - PCRE2_SPTR32 p = (PCRE2_SPTR32)pattern.c_str(); - - code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx); - - pcre2_compile_context_free_32(cctx); - - if (!code) { - PCRE2_UCHAR32 buf[256]; - pcre2_get_error_message_32(err, buf, 256); - String message = String::num(offset) + ": " + String((const CharType *)buf); - ERR_PRINT(message.utf8()); - return FAILED; - } + if (!code) { + PCRE2_UCHAR32 buf[256]; + pcre2_get_error_message_32(err, buf, 256); + String message = String::num(offset) + ": " + String((const char32_t *)buf); + ERR_PRINT(message.utf8()); + return FAILED; } return OK; } @@ -234,69 +202,39 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) length = p_end; } - if (sizeof(CharType) == 2) { - pcre2_code_16 *c = (pcre2_code_16 *)code; - pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; - pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx); - PCRE2_SPTR16 s = (PCRE2_SPTR16)p_subject.c_str(); - - pcre2_match_data_16 *match = pcre2_match_data_create_from_pattern_16(c, gctx); - - int res = pcre2_match_16(c, s, length, p_offset, 0, match, mctx); + pcre2_code_32 *c = (pcre2_code_32 *)code; + pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; + pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); + PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.get_data(); - if (res < 0) { - pcre2_match_data_free_16(match); - return nullptr; - } - - uint32_t size = pcre2_get_ovector_count_16(match); - PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_16(match); - - result->data.resize(size); - - for (uint32_t i = 0; i < size; i++) { - result->data.write[i].start = ovector[i * 2]; - result->data.write[i].end = ovector[i * 2 + 1]; - } - - pcre2_match_data_free_16(match); - pcre2_match_context_free_16(mctx); - - } else { - pcre2_code_32 *c = (pcre2_code_32 *)code; - pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; - pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); - PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.c_str(); + pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx); - pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx); + int res = pcre2_match_32(c, s, length, p_offset, 0, match, mctx); - int res = pcre2_match_32(c, s, length, p_offset, 0, match, mctx); - - if (res < 0) { - pcre2_match_data_free_32(match); - pcre2_match_context_free_32(mctx); + if (res < 0) { + pcre2_match_data_free_32(match); + pcre2_match_context_free_32(mctx); - return nullptr; - } + return nullptr; + } - uint32_t size = pcre2_get_ovector_count_32(match); - PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_32(match); + uint32_t size = pcre2_get_ovector_count_32(match); + PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_32(match); - result->data.resize(size); + result->data.resize(size); - for (uint32_t i = 0; i < size; i++) { - result->data.write[i].start = ovector[i * 2]; - result->data.write[i].end = ovector[i * 2 + 1]; - } - - pcre2_match_data_free_32(match); - pcre2_match_context_free_32(mctx); + for (uint32_t i = 0; i < size; i++) { + result->data.write[i].start = ovector[i * 2]; + result->data.write[i].end = ovector[i * 2 + 1]; } + pcre2_match_data_free_32(match); + pcre2_match_context_free_32(mctx); + result->subject = p_subject; uint32_t count; - const CharType *table; + const char32_t *table; uint32_t entry_size; _pattern_info(PCRE2_INFO_NAMECOUNT, &count); @@ -304,7 +242,7 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) _pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &entry_size); for (uint32_t i = 0; i < count; i++) { - CharType id = table[i * entry_size]; + char32_t id = table[i * entry_size]; if (result->data[id].start == -1) { continue; } @@ -344,7 +282,7 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a const int safety_zone = 1; PCRE2_SIZE olength = p_subject.length() + 1; // space for output string and one terminating \0 character - Vector<CharType> output; + Vector<char32_t> output; output.resize(olength + safety_zone); uint32_t flags = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH; @@ -357,55 +295,28 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a length = p_end; } - if (sizeof(CharType) == 2) { - pcre2_code_16 *c = (pcre2_code_16 *)code; - pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; - pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx); - PCRE2_SPTR16 s = (PCRE2_SPTR16)p_subject.c_str(); - PCRE2_SPTR16 r = (PCRE2_SPTR16)p_replacement.c_str(); - PCRE2_UCHAR16 *o = (PCRE2_UCHAR16 *)output.ptrw(); + pcre2_code_32 *c = (pcre2_code_32 *)code; + pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; + pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); + PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.get_data(); + PCRE2_SPTR32 r = (PCRE2_SPTR32)p_replacement.get_data(); + PCRE2_UCHAR32 *o = (PCRE2_UCHAR32 *)output.ptrw(); - pcre2_match_data_16 *match = pcre2_match_data_create_from_pattern_16(c, gctx); - - int res = pcre2_substitute_16(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); - - if (res == PCRE2_ERROR_NOMEMORY) { - output.resize(olength + safety_zone); - o = (PCRE2_UCHAR16 *)output.ptrw(); - res = pcre2_substitute_16(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); - } + pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx); - pcre2_match_data_free_16(match); - pcre2_match_context_free_16(mctx); + int res = pcre2_substitute_32(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); - if (res < 0) { - return String(); - } - - } else { - pcre2_code_32 *c = (pcre2_code_32 *)code; - pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; - pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); - PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.c_str(); - PCRE2_SPTR32 r = (PCRE2_SPTR32)p_replacement.c_str(); - PCRE2_UCHAR32 *o = (PCRE2_UCHAR32 *)output.ptrw(); - - pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx); - - int res = pcre2_substitute_32(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); - - if (res == PCRE2_ERROR_NOMEMORY) { - output.resize(olength + safety_zone); - o = (PCRE2_UCHAR32 *)output.ptrw(); - res = pcre2_substitute_32(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); - } + if (res == PCRE2_ERROR_NOMEMORY) { + output.resize(olength + safety_zone); + o = (PCRE2_UCHAR32 *)output.ptrw(); + res = pcre2_substitute_32(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength); + } - pcre2_match_data_free_32(match); - pcre2_match_context_free_32(mctx); + pcre2_match_data_free_32(match); + pcre2_match_context_free_32(mctx); - if (res < 0) { - return String(); - } + if (res < 0) { + return String(); } return String(output.ptr(), olength); @@ -435,7 +346,7 @@ Array RegEx::get_names() const { ERR_FAIL_COND_V(!is_valid(), result); uint32_t count; - const CharType *table; + const char32_t *table; uint32_t entry_size; _pattern_info(PCRE2_INFO_NAMECOUNT, &count); @@ -453,39 +364,21 @@ Array RegEx::get_names() const { } RegEx::RegEx() { - if (sizeof(CharType) == 2) { - general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr); - - } else { - general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); - } + general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); code = nullptr; } RegEx::RegEx(const String &p_pattern) { - if (sizeof(CharType) == 2) { - general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr); - - } else { - general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); - } + general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); code = nullptr; compile(p_pattern); } RegEx::~RegEx() { - if (sizeof(CharType) == 2) { - if (code) { - pcre2_code_free_16((pcre2_code_16 *)code); - } - pcre2_general_context_free_16((pcre2_general_context_16 *)general_ctx); - - } else { - if (code) { - pcre2_code_free_32((pcre2_code_32 *)code); - } - pcre2_general_context_free_32((pcre2_general_context_32 *)general_ctx); + if (code) { + pcre2_code_free_32((pcre2_code_32 *)code); } + pcre2_general_context_free_32((pcre2_general_context_32 *)general_ctx); } void RegEx::_bind_methods() { diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index a0dcd76d10..177f9192b8 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -1060,7 +1060,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::TEXT_CHAR: { - CharType result[2] = { *p_inputs[0], 0 }; + char32_t result[2] = { *p_inputs[0], 0 }; *r_return = String(result); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 2ac7793b8c..60a439b291 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -187,7 +187,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) - CharType cchar = GET_CHAR(); + char32_t cchar = GET_CHAR(); if (cchar == 0) { r_token.type = TK_EOF; return OK; @@ -329,7 +329,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { case '"': { String str; while (true) { - CharType ch = GET_CHAR(); + char32_t ch = GET_CHAR(); if (ch == 0) { _set_error("Unterminated String"); @@ -340,13 +340,13 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } else if (ch == '\\') { //escaped characters... - CharType next = GET_CHAR(); + char32_t next = GET_CHAR(); if (next == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } - CharType res = 0; + char32_t res = 0; switch (next) { case 'b': @@ -367,7 +367,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { case 'u': { // hex number for (int j = 0; j < 4; j++) { - CharType c = GET_CHAR(); + char32_t c = GET_CHAR(); if (c == 0) { _set_error("Unterminated String"); @@ -379,7 +379,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } - CharType v; + char32_t v; if (c >= '0' && c <= '9') { v = c - '0'; } else if (c >= 'a' && c <= 'f') { @@ -431,7 +431,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { #define READING_DONE 4 int reading = READING_INT; - CharType c = cchar; + char32_t c = cchar; bool exp_sign = false; bool exp_beg = false; bool is_float = false; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 87aa64211e..1b77ed3168 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -933,36 +933,36 @@ static const char *op_names[] = { }; String VisualScriptOperator::get_caption() const { - static const wchar_t *op_names[] = { + static const char32_t *op_names[] = { //comparison - L"A = B", //OP_EQUAL, - L"A \u2260 B", //OP_NOT_EQUAL, - L"A < B", //OP_LESS, - L"A \u2264 B", //OP_LESS_EQUAL, - L"A > B", //OP_GREATER, - L"A \u2265 B", //OP_GREATER_EQUAL, + U"A = B", //OP_EQUAL, + U"A \u2260 B", //OP_NOT_EQUAL, + U"A < B", //OP_LESS, + U"A \u2264 B", //OP_LESS_EQUAL, + U"A > B", //OP_GREATER, + U"A \u2265 B", //OP_GREATER_EQUAL, //mathematic - L"A + B", //OP_ADD, - L"A - B", //OP_SUBTRACT, - L"A \u00D7 B", //OP_MULTIPLY, - L"A \u00F7 B", //OP_DIVIDE, - L"\u00AC A", //OP_NEGATE, - L"+ A", //OP_POSITIVE, - L"A mod B", //OP_MODULE, - L"A .. B", //OP_STRING_CONCAT, + U"A + B", //OP_ADD, + U"A - B", //OP_SUBTRACT, + U"A \u00D7 B", //OP_MULTIPLY, + U"A \u00F7 B", //OP_DIVIDE, + U"\u00AC A", //OP_NEGATE, + U"+ A", //OP_POSITIVE, + U"A mod B", //OP_MODULE, + U"A .. B", //OP_STRING_CONCAT, //bitwise - L"A << B", //OP_SHIFT_LEFT, - L"A >> B", //OP_SHIFT_RIGHT, - L"A & B", //OP_BIT_AND, - L"A | B", //OP_BIT_OR, - L"A ^ B", //OP_BIT_XOR, - L"~A", //OP_BIT_NEGATE, + U"A << B", //OP_SHIFT_LEFT, + U"A >> B", //OP_SHIFT_RIGHT, + U"A & B", //OP_BIT_AND, + U"A | B", //OP_BIT_OR, + U"A ^ B", //OP_BIT_XOR, + U"~A", //OP_BIT_NEGATE, //logic - L"A and B", //OP_AND, - L"A or B", //OP_OR, - L"A xor B", //OP_XOR, - L"not A", //OP_NOT, - L"A in B", //OP_IN, + U"A and B", //OP_AND, + U"A or B", //OP_OR, + U"A xor B", //OP_XOR, + U"not A", //OP_NOT, + U"A in B", //OP_IN, }; return op_names[op]; |