[GDNative] made string functions more C-friendly

This commit is contained in:
Karroffel 2017-04-11 14:58:59 +02:00
parent 09ed1113fa
commit be2ad4f155
2 changed files with 7 additions and 7 deletions

View File

@ -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); *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; String *p = (String *)p_str;
if (p_size != NULL) { if (p_size != NULL) {
*p_size = p->length(); *p_size = p->utf8().length();
} }
if (p_dest != NULL) { 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)); 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; 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) { godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b) {

View File

@ -47,12 +47,12 @@ typedef struct godot_string {
void GDAPI godot_string_new(godot_string *p_str); 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_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); 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); 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_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); godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b);