adds variadic printing function, makes String.format custom placeholder work
parent
779568c67c
commit
e74b8f593e
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <gdnative_api_struct.gen.h>
|
#include <gdnative_api_struct.gen.h>
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
|
#include "Array.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
@ -20,6 +21,11 @@ public:
|
||||||
static void gdnative_init(godot_gdnative_init_options *o);
|
static void gdnative_init(godot_gdnative_init_options *o);
|
||||||
static void gdnative_terminate(godot_gdnative_terminate_options *o);
|
static void gdnative_terminate(godot_gdnative_terminate_options *o);
|
||||||
static void nativescript_init(void *handle);
|
static void nativescript_init(void *handle);
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
static void print(const String& fmt, Args... values) {
|
||||||
|
print(fmt.format(Array::make(values...)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
int find(String what, int from = 0) const;
|
int find(String what, int from = 0) const;
|
||||||
int find_last(String what) const;
|
int find_last(String what) const;
|
||||||
int findn(String what, int from = 0) const;
|
int findn(String what, int from = 0) const;
|
||||||
|
String format(Variant values) const;
|
||||||
String format(Variant values, String placeholder) const;
|
String format(Variant values, String placeholder) const;
|
||||||
String get_base_dir() const;
|
String get_base_dir() const;
|
||||||
String get_basename() const;
|
String get_basename() const;
|
||||||
|
@ -128,6 +129,7 @@ public:
|
||||||
String to_upper() const;
|
String to_upper() const;
|
||||||
String xml_escape() const;
|
String xml_escape() const;
|
||||||
String xml_unescape() const;
|
String xml_unescape() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
String operator+(const char *a, const String &b);
|
String operator+(const char *a, const String &b);
|
||||||
|
|
|
@ -267,13 +267,22 @@ int String::findn(String what, int from) const {
|
||||||
return godot::api->godot_string_findn(&_godot_string, what._godot_string);
|
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;
|
String new_string;
|
||||||
new_string._godot_string = godot::api->godot_string_format(&_godot_string, (godot_variant *)&values);
|
new_string._godot_string = godot::api->godot_string_format(&_godot_string, (godot_variant *)&values);
|
||||||
|
|
||||||
return new_string;
|
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 String::get_base_dir() const {
|
||||||
String new_string;
|
String new_string;
|
||||||
new_string._godot_string = godot::api->godot_string_get_base_dir(&_godot_string);
|
new_string._godot_string = godot::api->godot_string_get_base_dir(&_godot_string);
|
||||||
|
|
Loading…
Reference in New Issue