From b8c64184c628dba6b54b4beb5a38e292a182bd6f Mon Sep 17 00:00:00 2001 From: reduz Date: Tue, 13 Oct 2020 15:59:37 -0300 Subject: 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. --- core/ustring.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'core/ustring.cpp') 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 String::to_ascii_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector(); + } + CharString charstr = s->ascii(); + + Vector retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector String::to_utf8_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector(); + } + CharString charstr = s->utf8(); + + Vector retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector String::to_utf16_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector(); + } + Char16String charstr = s->utf16(); + + Vector 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 String::to_utf32_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector(); + } + + Vector 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()) { -- cgit v1.2.3