diff options
author | reduz <reduzio@gmail.com> | 2020-10-13 15:59:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-10-14 15:24:30 +0200 |
commit | b8c64184c628dba6b54b4beb5a38e292a182bd6f (patch) | |
tree | 7ffaba5d7fecfb9d16e0c47a18ffdd98117a2eea /core/ustring.cpp | |
parent | bc91e088e4503bbf1c5800282f2974011a4cc8e8 (diff) | |
download | redot-engine-b8c64184c628dba6b54b4beb5a38e292a182bd6f.tar.gz |
Refactored binding system for core types
Moved to a system using variadic templates, shared with CallableBind.
New code is cleaner, faster and allows for much better optimization of core
type functions from GDScript and GDNative.
Added Variant::InternalMethod function for direct call access.
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index e382ef3746..27dab8db6e 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -4732,6 +4732,69 @@ String String::unquote() const { return substr(1, length() - 2); } +Vector<uint8_t> String::to_ascii_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + CharString charstr = s->ascii(); + + Vector<uint8_t> retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf8_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + CharString charstr = s->utf8(); + + Vector<uint8_t> retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf16_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + Char16String charstr = s->utf16(); + + Vector<uint8_t> retval; + size_t len = charstr.length() * 2; + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, (const void *)charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf32_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + + Vector<uint8_t> retval; + size_t len = s->length() * 4; + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, (const void *)s->ptr(), len); + + return retval; +} + #ifdef TOOLS_ENABLED String TTR(const String &p_text, const String &p_context) { if (TranslationServer::get_singleton()) { |