2023-05-23 19:01:39 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* String.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
2023-10-23 14:07:57 +02:00
|
|
|
/* PANDEMONIUM ENGINE */
|
|
|
|
/* https://pandemoniumengine.org */
|
2023-05-23 19:01:39 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
2023-10-23 14:07:57 +02:00
|
|
|
/* Copyright (c) 2014-2022 Pandemonium Engine contributors (cf. AUTHORS.md). */
|
2023-05-23 19:01:39 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "String.hpp"
|
|
|
|
|
|
|
|
#include "Array.hpp"
|
2023-10-23 14:07:57 +02:00
|
|
|
#include "PandemoniumGlobal.hpp"
|
2023-05-23 19:01:39 +02:00
|
|
|
#include "NodePath.hpp"
|
|
|
|
#include "PoolArrays.hpp"
|
|
|
|
#include "Variant.hpp"
|
|
|
|
|
2023-05-31 13:28:14 +02:00
|
|
|
#include <gdn/string.h>
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
namespace pandemonium {
|
2023-05-23 19:01:39 +02:00
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::CharString::~CharString() {
|
|
|
|
pandemonium::api->pandemonium_char_string_destroy(&_char_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
int pandemonium::CharString::length() const {
|
|
|
|
return pandemonium::api->pandemonium_char_string_length(&_char_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
const char *pandemonium::CharString::get_data() const {
|
|
|
|
return pandemonium::api->pandemonium_char_string_get_data(&_char_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::num(double p_num, int p_decimals) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_num_with_decimals(p_num, p_decimals));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::num_scientific(double p_num) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_num_scientific(p_num));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::num_real(double p_num) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_num_real(p_num));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_num_int64_capitalized(p_num, base, capitalize_hex));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 13:31:45 +02:00
|
|
|
String String::chr(pandemonium_char_type p_char) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_chr(p_char));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::md5(const uint8_t *p_md5) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_md5(p_md5));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::hex_encode_buffer(const uint8_t *p_buffer, int p_len) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_hex_encode_buffer(p_buffer, p_len));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::String::String() {
|
|
|
|
pandemonium::api->pandemonium_string_new(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::String(const char *contents) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_new(&_pandemonium_string);
|
|
|
|
pandemonium::api->pandemonium_string_parse_utf8(&_pandemonium_string, contents);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::String(const wchar_t *contents) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_new_wchar_clip_to_len(&_pandemonium_string, contents, wcslen(contents));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::String(const wchar_t c) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_new_wchar_clip_to_len(&_pandemonium_string, &c, 1);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::String(const String &other) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_new_copy(&_pandemonium_string, &other._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::String(String &&other) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_new_copy(&_pandemonium_string, &other._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String::~String() {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_destroy(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 15:39:37 +02:00
|
|
|
char32_t &String::operator[](const int idx) {
|
2023-10-23 14:07:57 +02:00
|
|
|
return *const_cast<char32_t *>(pandemonium::api->pandemonium_string_operator_index(&_pandemonium_string, idx));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 15:39:37 +02:00
|
|
|
char32_t String::operator[](const int idx) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return *pandemonium::api->pandemonium_string_operator_index((pandemonium_string *)&_pandemonium_string, idx);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::length() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_length(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void String::operator=(const String &s) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_destroy(&_pandemonium_string);
|
|
|
|
pandemonium::api->pandemonium_string_new_copy(&_pandemonium_string, &s._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void String::operator=(String &&s) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_destroy(&_pandemonium_string);
|
|
|
|
pandemonium::api->pandemonium_string_new_copy(&_pandemonium_string, &s._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator==(const String &s) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_operator_equal(&_pandemonium_string, &s._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator!=(const String &s) const {
|
|
|
|
return !(*this == s);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::operator+(const String &s) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_operator_plus(&_pandemonium_string, &s._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void String::operator+=(const String &s) {
|
2023-10-23 14:07:57 +02:00
|
|
|
*this = String(pandemonium::api->pandemonium_string_operator_plus(&_pandemonium_string, &s._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 15:39:37 +02:00
|
|
|
void String::operator+=(const char32_t c) {
|
2023-05-23 19:01:39 +02:00
|
|
|
String _to_be_added = String(c);
|
2023-10-23 14:07:57 +02:00
|
|
|
*this = String(pandemonium::api->pandemonium_string_operator_plus(&_pandemonium_string, &_to_be_added._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator<(const String &s) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_operator_less(&_pandemonium_string, &s._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator<=(const String &s) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_operator_less(&_pandemonium_string, &s._pandemonium_string) ||
|
2023-05-23 19:01:39 +02:00
|
|
|
(*this == s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator>(const String &s) const {
|
|
|
|
return !(*this <= s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::operator>=(const String &s) const {
|
|
|
|
return !(*this < s);
|
|
|
|
}
|
|
|
|
|
|
|
|
String::operator NodePath() const {
|
|
|
|
return NodePath(*this);
|
|
|
|
}
|
|
|
|
|
2023-05-31 15:39:37 +02:00
|
|
|
const char32_t *String::unicode_str() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_get_data(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *String::alloc_c_string() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_char_string contents = pandemonium::api->pandemonium_string_utf8(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
int length = pandemonium::api->pandemonium_char_string_length(&contents);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
char *result = (char *)pandemonium::api->pandemonium_alloc(length + 1);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
if (result) {
|
2023-10-23 14:07:57 +02:00
|
|
|
memcpy(result, pandemonium::api->pandemonium_char_string_get_data(&contents), length + 1);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_char_string_destroy(&contents);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharString String::utf8() const {
|
|
|
|
CharString ret;
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
ret._char_string = pandemonium::api->pandemonium_string_utf8(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharString String::ascii(bool p_extended) const {
|
|
|
|
CharString ret;
|
|
|
|
|
|
|
|
if (p_extended)
|
2023-10-23 14:07:57 +02:00
|
|
|
ret._char_string = pandemonium::api->pandemonium_string_ascii_extended(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
else
|
2023-10-23 14:07:57 +02:00
|
|
|
ret._char_string = pandemonium::api->pandemonium_string_ascii(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
String operator+(const char *a, const String &b) {
|
|
|
|
return String(a) + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
String operator+(const wchar_t *a, const String &b) {
|
|
|
|
return String(a) + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::begins_with(const String &p_string) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_begins_with(&_pandemonium_string, &p_string._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::begins_with_char_array(const char *p_char_array) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_begins_with_char_array(&_pandemonium_string, p_char_array);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PoolStringArray String::bigrams() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_array arr = pandemonium::api->pandemonium_string_bigrams(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return Array(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::c_escape() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_c_escape(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::c_unescape() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_c_unescape(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::capitalize() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_capitalize(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::empty() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_empty(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::ends_with(const String &p_string) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_ends_with(&_pandemonium_string, &p_string._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void String::erase(int position, int chars) {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_erase(&_pandemonium_string, position, chars);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::find(String p_what, int p_from) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_find_from(&_pandemonium_string, p_what._pandemonium_string, p_from);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::find_last(String p_what) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_find_last(&_pandemonium_string, p_what._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::findn(String p_what, int p_from) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_findn_from(&_pandemonium_string, p_what._pandemonium_string, p_from);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::format(Variant values) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_format(&_pandemonium_string, (pandemonium_variant *)&values));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::format(Variant values, String placeholder) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_char_string contents = pandemonium::api->pandemonium_string_utf8(&placeholder._pandemonium_string);
|
|
|
|
String new_string(pandemonium::api->pandemonium_string_format_with_custom_placeholder(&_pandemonium_string, (pandemonium_variant *)&values, pandemonium::api->pandemonium_char_string_get_data(&contents)));
|
|
|
|
pandemonium::api->pandemonium_char_string_destroy(&contents);
|
2023-05-23 19:01:39 +02:00
|
|
|
|
|
|
|
return new_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_base_dir() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_get_base_dir(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_basename() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_get_basename(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_extension() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_get_extension(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::get_file() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_get_file(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::hash() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_hash(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::hex_to_int() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_hex_to_int(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::insert(int position, String what) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_insert(&_pandemonium_string, position, what._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_abs_path() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_abs_path(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_rel_path() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_rel_path(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_subsequence_of(String text) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_subsequence_of(&_pandemonium_string, &text._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_subsequence_ofi(String text) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_subsequence_ofi(&_pandemonium_string, &text._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_float() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_valid_float(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_html_color() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_valid_html_color(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_identifier() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_valid_identifier(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_integer() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_numeric(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::is_valid_ip_address() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_is_valid_ip_address(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::json_escape() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_json_escape(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::left(int position) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_left(&_pandemonium_string, position));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::match(String expr) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_match(&_pandemonium_string, &expr._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool String::matchn(String expr) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_match(&_pandemonium_string, &expr._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PoolByteArray String::md5_buffer() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_pool_byte_array arr = pandemonium::api->pandemonium_string_md5_buffer(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return PoolByteArray(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::md5_text() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_md5_text(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::ord_at(int at) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_ord_at(&_pandemonium_string, at);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::pad_decimals(int digits) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_pad_decimals(&_pandemonium_string, digits));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::pad_zeros(int digits) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_pad_zeros(&_pandemonium_string, digits));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::percent_decode() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_percent_decode(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::percent_encode() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_percent_encode(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::plus_file(String file) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_plus_file(&_pandemonium_string, &file._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::replace(String p_key, String p_with) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_replace(&_pandemonium_string, p_key._pandemonium_string, p_with._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::replacen(String what, String forwhat) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_replacen(&_pandemonium_string, what._pandemonium_string, forwhat._pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::rfind(String p_what, int p_from) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_rfind_from(&_pandemonium_string, p_what._pandemonium_string, p_from);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int String::rfindn(String p_what, int p_from) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_rfindn_from(&_pandemonium_string, p_what._pandemonium_string, p_from);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::right(int position) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_right(&_pandemonium_string, position));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PoolByteArray String::sha256_buffer() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_pool_byte_array arr = pandemonium::api->pandemonium_string_sha256_buffer(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return PoolByteArray(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::sha256_text() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_sha256_text(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float String::similarity(String text) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_similarity(&_pandemonium_string, &text._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Suport allow_empty
|
|
|
|
PoolStringArray String::split(String divisor, bool /*allow_empty*/) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_pool_string_array arr = pandemonium::api->pandemonium_string_split(&_pandemonium_string, &divisor._pandemonium_string);
|
2023-05-31 15:39:37 +02:00
|
|
|
return PoolStringArray(arr);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Suport allow_empty
|
|
|
|
PoolIntArray String::split_ints(String divisor, bool /*allow_empty*/) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_array arr = pandemonium::api->pandemonium_string_split_floats(&_pandemonium_string, &divisor._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return Array(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Suport allow_empty
|
|
|
|
PoolRealArray String::split_floats(String divisor, bool /*allow_empty*/) const {
|
2023-05-31 13:31:45 +02:00
|
|
|
// TODO The GDNative API returns pandemonium_array, when according to the doc, it should have been pandemonium_pool_real_array
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_array arr = pandemonium::api->pandemonium_string_split_floats(&_pandemonium_string, &divisor._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
Array wrapped_array(arr);
|
|
|
|
return PoolRealArray(wrapped_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::strip_edges(bool left, bool right) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_strip_edges(&_pandemonium_string, left, right));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::substr(int from, int len) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_substr(&_pandemonium_string, from, len));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float String::to_float() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_to_float(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t String::to_int() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_to_int(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::to_lower() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_to_lower(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::to_upper() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_to_upper(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::xml_escape() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_xml_escape(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::xml_unescape() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return String(pandemonium::api->pandemonium_string_xml_unescape(&_pandemonium_string));
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
signed char String::casecmp_to(String p_str) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_casecmp_to(&_pandemonium_string, &p_str._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
signed char String::nocasecmp_to(String p_str) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_nocasecmp_to(&_pandemonium_string, &p_str._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
signed char String::naturalnocasecmp_to(String p_str) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
return pandemonium::api->pandemonium_string_naturalnocasecmp_to(&_pandemonium_string, &p_str._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String String::dedent() const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_string s = pandemonium::api->pandemonium_string_dedent(&_pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return String(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolStringArray String::rsplit(const String &divisor, const bool allow_empty, const int maxsplit) const {
|
2023-05-31 13:31:45 +02:00
|
|
|
pandemonium_pool_string_array arr =
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium::api->pandemonium_string_rsplit_maxsplit(&_pandemonium_string, &divisor._pandemonium_string, allow_empty, maxsplit);
|
2023-05-23 19:01:39 +02:00
|
|
|
return PoolStringArray(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::rstrip(const String &chars) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_string s = pandemonium::api->pandemonium_string_rstrip(&_pandemonium_string, &chars._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return String(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::trim_prefix(const String &prefix) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_string s = pandemonium::api->pandemonium_string_trim_prefix(&_pandemonium_string, &prefix._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return String(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
String String::trim_suffix(const String &suffix) const {
|
2023-10-23 14:07:57 +02:00
|
|
|
pandemonium_string s = pandemonium::api->pandemonium_string_trim_suffix(&_pandemonium_string, &suffix._pandemonium_string);
|
2023-05-23 19:01:39 +02:00
|
|
|
return String(s);
|
|
|
|
}
|
|
|
|
|
2023-10-23 14:07:57 +02:00
|
|
|
} // namespace pandemonium
|