From be2ad4f155de085716cf98c629b44583b6896492 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Tue, 11 Apr 2017 14:58:59 +0200 Subject: [PATCH] [GDNative] made string functions more C-friendly --- modules/gdnative/godot/godot_string.cpp | 10 +++++----- modules/gdnative/godot/godot_string.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/gdnative/godot/godot_string.cpp b/modules/gdnative/godot/godot_string.cpp index 2a78b2c96f7..757b8510cf1 100644 --- a/modules/gdnative/godot/godot_string.cpp +++ b/modules/gdnative/godot/godot_string.cpp @@ -53,13 +53,13 @@ void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, co *p = String::utf8(p_contents, p_size); } -void GDAPI godot_string_get_data(const godot_string *p_str, wchar_t *p_dest, int *p_size) { +void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size) { String *p = (String *)p_str; if (p_size != NULL) { - *p_size = p->length(); + *p_size = p->utf8().length(); } if (p_dest != NULL) { - memcpy(p_dest, p->ptr(), *p_size * sizeof(CharType)); + memcpy(p_dest, p->utf8().get_data(), *p_size); } } @@ -75,9 +75,9 @@ wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int return &(s->operator[](p_idx)); } -const wchar_t GDAPI *godot_string_c_str(const godot_string *p_str) { +const char GDAPI *godot_string_c_str(const godot_string *p_str) { const String *s = (const String *)p_str; - return s->c_str(); + return s->utf8().get_data(); } godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b) { diff --git a/modules/gdnative/godot/godot_string.h b/modules/gdnative/godot/godot_string.h index 7cde482cce2..9289531c5e2 100644 --- a/modules/gdnative/godot/godot_string.h +++ b/modules/gdnative/godot/godot_string.h @@ -47,12 +47,12 @@ typedef struct godot_string { void GDAPI godot_string_new(godot_string *p_str); void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, const int p_size); -void GDAPI godot_string_get_data(const godot_string *p_str, wchar_t *p_dest, int *p_size); +void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size); void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_string *p_src); wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx); -const wchar_t GDAPI *godot_string_c_str(const godot_string *p_str); +const char GDAPI *godot_string_c_str(const godot_string *p_str); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b); godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b);