summaryrefslogtreecommitdiffstats
path: root/src/core/String.cpp
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2017-11-25 09:54:35 +1100
committerBastiaan Olij <mux213@gmail.com>2017-11-25 10:22:36 +1100
commitd8faa4ec76bc73ca17b8e5dd72220d16996423c3 (patch)
treebd388b6570402fdde2732dd92217ee53981209cf /src/core/String.cpp
parent0f773c2d72a4666e2ecf7235201f035773775f71 (diff)
downloadredot-cpp-d8faa4ec76bc73ca17b8e5dd72220d16996423c3.tar.gz
Added alloc_c_string
Diffstat (limited to 'src/core/String.cpp')
-rw-r--r--src/core/String.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/String.cpp b/src/core/String.cpp
index 9a7b96e..494d976 100644
--- a/src/core/String.cpp
+++ b/src/core/String.cpp
@@ -107,6 +107,22 @@ const wchar_t *String::unicode_str() const {
return godot::api->godot_string_unicode_str(&_godot_string);
}
+char *String::alloc_c_string() const {
+ int len;
+
+ // figure out the lenght of our string
+ get_c_string(NULL, &len);
+
+ // allocate our buffer
+ char * result = (char *)godot::api->godot_alloc(len + 1);
+ if (result != NULL) {
+ get_c_string(result, &len);
+ result[len] = '\0';
+ }
+
+ 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);
}