diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/GodotGlobal.cpp | 18 | ||||
| -rw-r--r-- | src/core/String.cpp | 70 |
2 files changed, 53 insertions, 35 deletions
diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp index 8566481..a2b5050 100644 --- a/src/core/GodotGlobal.cpp +++ b/src/core/GodotGlobal.cpp @@ -47,10 +47,7 @@ void Godot::print_error(const String& description, const String& function, const if (c_file != NULL) godot::api->godot_free(c_file); } -}; - -void gdnative_init(godot_gdnative_init_options *options); -extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *options) +void Godot::gdnative_init(godot_gdnative_init_options *options) { godot::api = options->api_struct; @@ -63,19 +60,16 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *opti default: break; }; }; - - gdnative_init(options); } -void gdnative_terminate(godot_gdnative_terminate_options *options); -extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options) +void Godot::gdnative_terminate(godot_gdnative_terminate_options *options) { - gdnative_terminate(options); + // reserved for future use. } -void nativescript_init(); -extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) +void Godot::nativescript_init(void *handle) { godot::_RegisterState::nativescript_handle = handle; - nativescript_init(); } + +}; diff --git a/src/core/String.cpp b/src/core/String.cpp index 494d976..a277b60 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -12,23 +12,33 @@ namespace godot { +godot::CharString::~CharString() { + godot::api->godot_char_string_destroy(&_char_string); +} + +int godot::CharString::length() const { + return godot::api->godot_char_string_length(&_char_string); +} + +const char *godot::CharString::get_data() const { + return godot::api->godot_char_string_get_data(&_char_string); +} + godot::String::String() { godot::api->godot_string_new(&_godot_string); } String::String(const char *contents) { - godot::api->godot_string_new_data(&_godot_string, contents, strlen(contents)); + godot::api->godot_string_new(&_godot_string); + godot::api->godot_string_parse_utf8(&_godot_string, contents); } String::String(const wchar_t *contents) { - // @Todo - // godot::api->godot_string_new_data(&_godot_string, contents, strlen(contents)); - godot::api->godot_string_new(&_godot_string); + godot::api->godot_string_new_with_wide_string(&_godot_string, contents, wcslen(contents)); } String::String(const wchar_t c) { - // @Todo - godot::api->godot_string_new(&_godot_string); + godot::api->godot_string_new_with_wide_string(&_godot_string, &c, 1); } String::String(const String &other) { @@ -48,9 +58,7 @@ wchar_t String::operator[](const int idx) const { } int String::length() const { - int len = 0; - godot::api->godot_string_get_data(&_godot_string, nullptr, &len); - return len; + return godot::api->godot_string_length(&_godot_string); } void String::operator=(const String &s) { @@ -68,8 +76,7 @@ bool String::operator!=(const String &s) { String String::operator+(const String &s) { String new_string = *this; - new_string._godot_string = - godot::api->godot_string_operator_plus(&new_string._godot_string, &s._godot_string); + new_string._godot_string = godot::api->godot_string_operator_plus(&new_string._godot_string, &s._godot_string); return new_string; } @@ -104,27 +111,44 @@ String::operator NodePath() const { } const wchar_t *String::unicode_str() const { - return godot::api->godot_string_unicode_str(&_godot_string); + return godot::api->godot_string_wide_str(&_godot_string); } char *String::alloc_c_string() const { - int len; - // figure out the lenght of our string - get_c_string(NULL, &len); + godot_char_string contents = godot::api->godot_string_utf8(&_godot_string); - // allocate our buffer - char * result = (char *)godot::api->godot_alloc(len + 1); - if (result != NULL) { - get_c_string(result, &len); - result[len] = '\0'; + int length = godot::api->godot_char_string_length(&contents); + + char *result = (char *) godot::api->godot_alloc(length + 1); + + if (result) { + memcpy(result, godot::api->godot_char_string_get_data(&contents), length + 1); } - + + godot::api->godot_char_string_destroy(&contents); + return result; } -void String::get_c_string(char *p_dest, int *p_size) const { - godot::api->godot_string_get_data(&_godot_string, p_dest, p_size); +CharString String::utf8() const { + CharString ret; + + ret._char_string = godot::api->godot_string_utf8(&_godot_string); + + return ret; +} + +CharString String::ascii(bool p_extended) const { + + CharString ret; + + if (p_extended) + ret._char_string = godot::api->godot_string_ascii_extended(&_godot_string); + else + ret._char_string = godot::api->godot_string_ascii(&_godot_string); + + return ret; } String operator+(const char *a, const String &b) { |
