diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-13 16:18:12 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-03-21 15:39:54 +0200 |
commit | d72b5632505a308e7f7a8a534d308884e80936db (patch) | |
tree | 58d4b1117b9a31f9133748becf41b0c06b1693ed /core/variant/variant_call.cpp | |
parent | 2a05522283fbd8ce9c887b17548debf4bcd3e8a4 (diff) | |
download | redot-engine-d72b5632505a308e7f7a8a534d308884e80936db.tar.gz |
Add GDScript `to_wchar_buffer` and `get_string_from_wchar` functions.
Diffstat (limited to 'core/variant/variant_call.cpp')
-rw-r--r-- | core/variant/variant_call.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 0c0c8f657a..ae15158836 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -700,6 +700,19 @@ struct _VariantCall { return s; } + static String func_PackedByteArray_get_string_from_wchar(PackedByteArray *p_instance) { + String s; + if (p_instance->size() > 0) { + const uint8_t *r = p_instance->ptr(); +#ifdef WINDOWS_ENABLED + s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); +#else + s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t))); +#endif + } + return s; + } + static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) { PackedByteArray compressed; @@ -1721,6 +1734,7 @@ static void _register_variant_builtin_methods() { bind_string_method(to_utf8_buffer, sarray(), varray()); bind_string_method(to_utf16_buffer, sarray(), varray()); bind_string_method(to_utf32_buffer, sarray(), varray()); + bind_string_method(to_wchar_buffer, sarray(), varray()); bind_static_method(String, num_scientific, sarray("number"), varray()); bind_static_method(String, num, sarray("number", "decimals"), varray(-1)); @@ -2258,6 +2272,7 @@ static void _register_variant_builtin_methods() { bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); bind_function(PackedByteArray, get_string_from_utf16, _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray()); bind_function(PackedByteArray, get_string_from_utf32, _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray()); + bind_function(PackedByteArray, get_string_from_wchar, _VariantCall::func_PackedByteArray_get_string_from_wchar, sarray(), varray()); bind_function(PackedByteArray, hex_encode, _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray()); bind_function(PackedByteArray, compress, _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0)); bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0)); |