2017-03-06 07:49:24 +00:00
|
|
|
#include "String.hpp"
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
#include "Array.hpp"
|
2017-04-06 00:32:24 +00:00
|
|
|
#include "NodePath.hpp"
|
2017-10-03 10:57:33 +00:00
|
|
|
#include "PoolArrays.hpp"
|
|
|
|
#include "Variant.hpp"
|
2017-04-06 00:32:24 +00:00
|
|
|
|
2017-10-03 10:37:34 +00:00
|
|
|
#include <gdnative/string.h>
|
2017-03-06 02:30:46 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-04-17 22:38:09 +00:00
|
|
|
namespace godot {
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
godot::String::String() {
|
2017-03-06 02:30:46 +00:00
|
|
|
godot_string_new(&_godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::String(const char *contents) {
|
2017-03-06 02:30:46 +00:00
|
|
|
godot_string_new_data(&_godot_string, contents, strlen(contents));
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::String(const wchar_t *contents) {
|
2017-03-06 02:30:46 +00:00
|
|
|
// @Todo
|
|
|
|
// godot_string_new_data(&_godot_string, contents, strlen(contents));
|
|
|
|
godot_string_new(&_godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::String(const wchar_t c) {
|
2017-03-06 02:30:46 +00:00
|
|
|
// @Todo
|
|
|
|
godot_string_new(&_godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::String(const String &other) {
|
2017-06-18 11:21:18 +00:00
|
|
|
godot_string_new_copy(&_godot_string, &other._godot_string);
|
2017-03-06 02:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::~String() {
|
2017-03-06 02:30:46 +00:00
|
|
|
godot_string_destroy(&_godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
wchar_t &String::operator[](const int idx) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return *godot_string_operator_index(&_godot_string, idx);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
wchar_t String::operator[](const int idx) const {
|
|
|
|
return *godot_string_operator_index((godot_string *)&_godot_string, idx);
|
2017-03-06 02:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
int String::length() const {
|
2017-03-06 02:30:46 +00:00
|
|
|
int len = 0;
|
|
|
|
godot_string_get_data(&_godot_string, nullptr, &len);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
void String::operator=(const String &s) {
|
2017-06-18 11:21:18 +00:00
|
|
|
godot_string_destroy(&_godot_string);
|
|
|
|
godot_string_new_copy(&_godot_string, &s._godot_string);
|
2017-03-18 14:23:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator==(const String &s) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return godot_string_operator_equal(&_godot_string, &s._godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator!=(const String &s) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return !(*this == s);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String String::operator+(const String &s) {
|
2017-06-18 11:21:18 +00:00
|
|
|
String new_string = *this;
|
2017-10-03 10:57:33 +00:00
|
|
|
new_string._godot_string =
|
|
|
|
godot_string_operator_plus(&new_string._godot_string, &s._godot_string);
|
2017-03-06 02:30:46 +00:00
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
void String::operator+=(const String &s) {
|
2017-07-22 13:41:38 +00:00
|
|
|
_godot_string = godot_string_operator_plus(&_godot_string, &s._godot_string);
|
2017-03-06 02:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
void String::operator+=(const wchar_t c) {
|
2017-03-06 02:30:46 +00:00
|
|
|
// @Todo
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator<(const String &s) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return godot_string_operator_less(&_godot_string, &s._godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator<=(const String &s) {
|
|
|
|
return godot_string_operator_less(&_godot_string, &s._godot_string) ||
|
|
|
|
(*this == s);
|
2017-03-06 02:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator>(const String &s) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return !(*this <= s);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::operator>=(const String &s) {
|
2017-03-06 02:30:46 +00:00
|
|
|
return !(*this < s);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String::operator NodePath() const {
|
2017-04-06 00:32:24 +00:00
|
|
|
return NodePath(*this);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
const char *String::c_string() const {
|
2017-03-06 02:30:46 +00:00
|
|
|
return godot_string_c_str(&_godot_string);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
String operator+(const char *a, const String &b) {
|
2017-03-15 22:19:58 +00:00
|
|
|
return String(a) + b;
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
bool String::begins_with(String &p_string) const {
|
|
|
|
return godot_string_begins_with(&_godot_string, &p_string._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::begins_with_char_array(const char *p_char_array) const {
|
|
|
|
return godot_string_begins_with_char_array(&_godot_string, p_char_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolStringArray String::bigrams() const {
|
|
|
|
godot_array arr = godot_string_bigrams(&_godot_string);
|
|
|
|
|
|
|
|
return *(PoolStringArray *)&arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::c_escape() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_c_escape(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::c_unescape() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_c_unescape(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::capitalize() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_capitalize(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::empty() const {
|
|
|
|
return godot_string_empty(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::ends_with(String &p_string) const {
|
|
|
|
return godot_string_ends_with(&_godot_string, &p_string._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void String::erase(int position, int chars) const {
|
|
|
|
godot_string_erase(&_godot_string, position, chars);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::find(String p_what, int p_from) const {
|
|
|
|
return godot_string_find(&_godot_string, p_what._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::find_last(String what) const {
|
|
|
|
return godot_string_find_last(&_godot_string, what._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::findn(String what, int from) const {
|
|
|
|
return godot_string_findn(&_godot_string, what._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::format(Variant values, String placeholder) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_format(&_godot_string, (godot_variant *)&values);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_base_dir() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_get_base_dir(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_basename() const {
|
|
|
|
godot_string new_string = godot_string_get_basename(&_godot_string);
|
|
|
|
return *(String *)&new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_extension() const {
|
|
|
|
godot_string new_string = godot_string_get_extension(&_godot_string);
|
|
|
|
return *(String *)&new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_file() const {
|
|
|
|
godot_string new_string = godot_string_get_file(&_godot_string);
|
|
|
|
return *(String *)&new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::hash() const {
|
|
|
|
return godot_string_hash(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::hex_to_int() const {
|
|
|
|
return godot_string_hex_to_int(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::insert(int position, String what) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_insert(&_godot_string, position, what._godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_abs_path() const {
|
|
|
|
return godot_string_is_abs_path(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_rel_path() const {
|
|
|
|
return godot_string_is_rel_path(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_subsequence_of(String text) const {
|
|
|
|
return godot_string_is_subsequence_of(&_godot_string, &text._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_subsequence_ofi(String text) const {
|
|
|
|
return godot_string_is_subsequence_ofi(&_godot_string, &text._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_float() const {
|
|
|
|
return godot_string_is_valid_float(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_html_color() const {
|
|
|
|
return godot_string_is_valid_html_color(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_identifier() const {
|
|
|
|
return godot_string_is_valid_identifier(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_integer() const {
|
|
|
|
return godot_string_is_numeric(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_ip_address() const {
|
|
|
|
return godot_string_is_valid_ip_address(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::json_escape() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_json_escape(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::left(int position) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_left(&_godot_string, position);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::match(String expr) const {
|
|
|
|
return godot_string_match(&_godot_string, &expr._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::matchn(String expr) const {
|
|
|
|
return godot_string_match(&_godot_string, &expr._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolByteArray String::md5_buffer() const {
|
|
|
|
godot_pool_byte_array arr = godot_string_md5_buffer(&_godot_string);
|
|
|
|
return *(PoolByteArray *)&arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::md5_text() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_md5_text(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::ord_at(int at) const {
|
|
|
|
return godot_string_ord_at(&_godot_string, at);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::pad_decimals(int digits) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_pad_decimals(&_godot_string, digits);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::pad_zeros(int digits) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_pad_zeros(&_godot_string, digits);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::percent_decode() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_percent_decode(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::percent_encode() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_percent_encode(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::plus_file(String file) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_plus_file(&_godot_string, &file._godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::replace(String p_key, String p_with) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_replace(&_godot_string, p_key._godot_string, p_with._godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::replacen(String what, String forwhat) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_replacen(&_godot_string, what._godot_string, forwhat._godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::rfind(String what, int from) const {
|
|
|
|
return godot_string_rfind(&_godot_string, what._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::rfindn(String what, int from) const {
|
|
|
|
// From -1
|
|
|
|
return godot_string_rfindn(&_godot_string, what._godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::right(int position) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_right(&_godot_string, position);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolByteArray String::sha256_buffer() const {
|
|
|
|
godot_pool_byte_array arr = godot_string_sha256_buffer(&_godot_string);
|
|
|
|
|
|
|
|
return *(PoolByteArray *)&arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::sha256_text() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_sha256_text(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
float String::similarity(String text) const {
|
|
|
|
return godot_string_similarity(&_godot_string, &text._godot_string);
|
|
|
|
}
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
PoolStringArray String::split(String divisor, bool allow_empty) const {
|
|
|
|
godot_array arr = godot_string_split(&_godot_string, &divisor._godot_string);
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2017-10-03 10:57:33 +00:00
|
|
|
return *(PoolStringArray *)&arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolRealArray String::split_floats(String divisor, bool allow_empty) const {
|
|
|
|
godot_array arr = godot_string_split_floats(&_godot_string, &divisor._godot_string);
|
|
|
|
|
|
|
|
return *(PoolRealArray *)&arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::strip_edges(bool left, bool right) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_strip_edges(&_godot_string, left, right);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::substr(int from, int len) const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_substr(&_godot_string, from, len);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
float String::to_float() const {
|
|
|
|
return godot_string_to_float(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t String::to_int() const {
|
|
|
|
return godot_string_to_int(&_godot_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::to_lower() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_to_lower(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::to_upper() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_to_upper(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::xml_escape() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_xml_escape(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::xml_unescape() const {
|
|
|
|
String new_string;
|
|
|
|
new_string._godot_string = godot_string_xml_unescape(&_godot_string);
|
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
2017-03-06 02:30:46 +00:00
|
|
|
}
|