summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/core/GodotGlobal.hpp6
-rw-r--r--include/core/String.hpp2
-rw-r--r--src/core/String.cpp11
3 files changed, 18 insertions, 1 deletions
diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp
index 7d28dba..a913359 100644
--- a/include/core/GodotGlobal.hpp
+++ b/include/core/GodotGlobal.hpp
@@ -3,6 +3,7 @@
#include <gdnative_api_struct.gen.h>
#include "String.hpp"
+#include "Array.hpp"
namespace godot {
@@ -20,6 +21,11 @@ public:
static void gdnative_init(godot_gdnative_init_options *o);
static void gdnative_terminate(godot_gdnative_terminate_options *o);
static void nativescript_init(void *handle);
+
+ template <class... Args>
+ static void print(const String& fmt, Args... values) {
+ print(fmt.format(Array::make(values...)));
+ }
};
diff --git a/include/core/String.hpp b/include/core/String.hpp
index de65f3c..7826fcb 100644
--- a/include/core/String.hpp
+++ b/include/core/String.hpp
@@ -81,6 +81,7 @@ public:
int find(String what, int from = 0) const;
int find_last(String what) const;
int findn(String what, int from = 0) const;
+ String format(Variant values) const;
String format(Variant values, String placeholder) const;
String get_base_dir() const;
String get_basename() const;
@@ -128,6 +129,7 @@ public:
String to_upper() const;
String xml_escape() const;
String xml_unescape() const;
+
};
String operator+(const char *a, const String &b);
diff --git a/src/core/String.cpp b/src/core/String.cpp
index 3d822b1..737c040 100644
--- a/src/core/String.cpp
+++ b/src/core/String.cpp
@@ -267,13 +267,22 @@ int String::findn(String what, int from) const {
return godot::api->godot_string_findn(&_godot_string, what._godot_string);
}
-String String::format(Variant values, String placeholder) const {
+String String::format(Variant values) const {
String new_string;
new_string._godot_string = godot::api->godot_string_format(&_godot_string, (godot_variant *)&values);
return new_string;
}
+String String::format(Variant values, String placeholder) const {
+ String new_string;
+ godot_char_string contents = godot::api->godot_string_utf8(&placeholder._godot_string);
+ new_string._godot_string = godot::api->godot_string_format_with_custom_placeholder(&_godot_string, (godot_variant *)&values, godot::api->godot_char_string_get_data(&contents));
+ godot::api->godot_char_string_destroy(&contents);
+
+ return new_string;
+}
+
String String::get_base_dir() const {
String new_string;
new_string._godot_string = godot::api->godot_string_get_base_dir(&_godot_string);