godot-cpp/include/core/String.hpp

155 lines
4.6 KiB
C++
Raw Normal View History

2017-03-02 22:51:31 +00:00
#ifndef STRING_H
#define STRING_H
2017-10-03 10:37:34 +00:00
#include <gdnative/string.h>
2017-03-02 22:51:31 +00:00
namespace godot {
2017-03-02 22:51:31 +00:00
class NodePath;
2017-10-03 10:57:33 +00:00
class Variant;
class PoolByteArray;
Nativescript 1.1 implemented instance binding data usage This commit changes the way C++ wrapper classes work. Previously, wrapper classes were merely wrapper *interfaces*. They used the `this` pointer to store the actual foreign Godot Object. With the NativeScript 1.1 extension it is now possible to have low-overhead language binding data attached to Objects. The C++ bindings use that feature to implement *proper* wrappers and enable regular C++ inheritance usage that way. Some things might still be buggy and untested, but the C++ SimpleDemo works with those changes. new and free change, custom free will crash engine, be wary fix exporting of non-object types fix free() crash with custom resources added type tags and safe object casting fix global type registration order fix cast_to changed build system to be more self contained updated .gitignore use typeid() for type tags now fix indentation in bindings generator remove accidentally added files fix gitignore Fixed up registering tool and updated godot_headers Fix crash when calling String::split/split_floats Was casting to the wrong object type. Also adds parse_ints function to String with the same logic Better warning/error macros Change gitignore so we get our gen folders New documentation based on nativescript 1.1 Fixed GODOT_SUBCLASS macro Preventing crash when function returned null ptr Adds needed include <typeinfo> Solves this issue #168 due to not having the include of typeinfo Fix compile error of 'WARN_PRINT' and 'ERR_PRINT'. cannot pass non-trivial object of type 'godot::String' to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs] update vector3::distance_to Remove godot_api.json as its now in the godot_headers submodule (api.json)
2018-02-11 14:50:01 +00:00
class PoolIntArray;
2017-10-03 10:57:33 +00:00
class PoolRealArray;
class PoolStringArray;
class String;
class CharString {
friend class String;
godot_char_string _char_string;
public:
~CharString();
int length() const;
const char *get_data() const;
};
2017-10-03 10:57:33 +00:00
class String {
2017-03-02 22:51:31 +00:00
godot_string _godot_string;
2017-10-03 10:57:33 +00:00
friend class Dictionary;
friend class NodePath;
friend class Variant;
explicit inline String(godot_string contents) :
_godot_string(contents) {}
2017-03-02 22:51:31 +00:00
public:
String();
String(const char *contents);
String(const wchar_t *contents);
String(const wchar_t c);
2017-10-03 10:57:33 +00:00
String(const String &other);
2021-05-30 16:59:41 +00:00
String(String&& other);
~String();
static String num(double p_num, int p_decimals = -1);
static String num_scientific(double p_num);
static String num_real(double p_num);
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
static String chr(godot_char_type p_char);
static String md5(const uint8_t *p_md5);
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
2017-10-03 10:57:33 +00:00
wchar_t &operator[](const int idx);
wchar_t operator[](const int idx) const;
2017-10-03 10:57:33 +00:00
void operator=(const String &s);
2021-05-30 07:03:40 +00:00
void operator=(String&& s);
bool operator==(const String &s) const;
bool operator!=(const String &s) const;
String operator+(const String &s) const;
2017-10-03 10:57:33 +00:00
void operator+=(const String &s);
2018-05-15 20:24:53 +00:00
void operator+=(const wchar_t c);
bool operator<(const String &s) const;
bool operator<=(const String &s) const;
bool operator>(const String &s) const;
bool operator>=(const String &s) const;
operator NodePath() const;
2017-10-03 10:57:33 +00:00
int length() const;
const wchar_t *unicode_str() const;
2017-11-24 22:54:35 +00:00
char *alloc_c_string() const;
CharString utf8() const;
CharString ascii(bool p_extended = false) const;
2017-03-02 22:51:31 +00:00
2017-10-03 10:57:33 +00:00
bool begins_with(String &s) const;
bool begins_with_char_array(const char *p_char_array) const;
PoolStringArray bigrams() const;
String c_escape() const;
String c_unescape() const;
String capitalize() const;
bool empty() const;
bool ends_with(String &text) const;
2017-10-03 15:10:36 +00:00
void erase(int position, int chars);
2017-10-03 10:57:33 +00:00
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;
2017-10-03 10:57:33 +00:00
String format(Variant values, String placeholder) const;
String get_base_dir() const;
String get_basename() const;
String get_extension() const;
String get_file() const;
int hash() const;
int hex_to_int() const;
String insert(int position, String what) const;
bool is_abs_path() const;
bool is_rel_path() const;
bool is_subsequence_of(String text) const;
bool is_subsequence_ofi(String text) const;
bool is_valid_float() const;
bool is_valid_html_color() const;
bool is_valid_identifier() const;
bool is_valid_integer() const;
bool is_valid_ip_address() const;
String json_escape() const;
String left(int position) const;
bool match(String expr) const;
bool matchn(String expr) const;
PoolByteArray md5_buffer() const;
String md5_text() const;
int ord_at(int at) const;
String pad_decimals(int digits) const;
String pad_zeros(int digits) const;
String percent_decode() const;
String percent_encode() const;
String plus_file(String file) const;
String replace(String what, String forwhat) const;
String replacen(String what, String forwhat) const;
int rfind(String what, int from = -1) const;
int rfindn(String what, int from = -1) const;
String right(int position) const;
PoolByteArray sha256_buffer() const;
String sha256_text() const;
float similarity(String text) const;
PoolStringArray split(String divisor, bool allow_empty = true) const;
Nativescript 1.1 implemented instance binding data usage This commit changes the way C++ wrapper classes work. Previously, wrapper classes were merely wrapper *interfaces*. They used the `this` pointer to store the actual foreign Godot Object. With the NativeScript 1.1 extension it is now possible to have low-overhead language binding data attached to Objects. The C++ bindings use that feature to implement *proper* wrappers and enable regular C++ inheritance usage that way. Some things might still be buggy and untested, but the C++ SimpleDemo works with those changes. new and free change, custom free will crash engine, be wary fix exporting of non-object types fix free() crash with custom resources added type tags and safe object casting fix global type registration order fix cast_to changed build system to be more self contained updated .gitignore use typeid() for type tags now fix indentation in bindings generator remove accidentally added files fix gitignore Fixed up registering tool and updated godot_headers Fix crash when calling String::split/split_floats Was casting to the wrong object type. Also adds parse_ints function to String with the same logic Better warning/error macros Change gitignore so we get our gen folders New documentation based on nativescript 1.1 Fixed GODOT_SUBCLASS macro Preventing crash when function returned null ptr Adds needed include <typeinfo> Solves this issue #168 due to not having the include of typeinfo Fix compile error of 'WARN_PRINT' and 'ERR_PRINT'. cannot pass non-trivial object of type 'godot::String' to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs] update vector3::distance_to Remove godot_api.json as its now in the godot_headers submodule (api.json)
2018-02-11 14:50:01 +00:00
PoolIntArray split_ints(String divisor, bool allow_empty = true) const;
2017-10-03 10:57:33 +00:00
PoolRealArray split_floats(String divisor, bool allow_empty = true) const;
String strip_edges(bool left = true, bool right = true) const;
String substr(int from, int len) const;
float to_float() const;
int64_t to_int() const;
String to_lower() const;
String to_upper() const;
String xml_escape() const;
String xml_unescape() const;
signed char casecmp_to(String p_str) const;
signed char nocasecmp_to(String p_str) const;
signed char naturalnocasecmp_to(String p_str) const;
2019-05-22 09:06:01 +00:00
String dedent() const;
PoolStringArray rsplit(const String &divisor, const bool allow_empty = true, const int maxsplit = 0) const;
String rstrip(const String &chars) const;
String trim_prefix(const String &prefix) const;
String trim_suffix(const String &suffix) const;
2017-03-02 22:51:31 +00:00
};
2017-10-03 10:57:33 +00:00
String operator+(const char *a, const String &b);
String operator+(const wchar_t *a, const String &b);
} // namespace godot
2017-03-02 22:51:31 +00:00
#endif // STRING_H