Browse Source

Merge pull request #8360 from karroffel/gdnative-string-c-functions

[GDNative] made string functions more C-friendly
Thomas Herzog 8 years ago
parent
commit
faee2fbf62
2 changed files with 7 additions and 7 deletions
  1. 5 5
      modules/gdnative/godot/godot_string.cpp
  2. 2 2
      modules/gdnative/godot/godot_string.h

+ 5 - 5
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) {

+ 2 - 2
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);