2022-10-30 14:24:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-30 10:43:44 -05:00
|
|
|
#include <Geode/binding/GDString.hpp>
|
2023-01-19 06:27:42 -05:00
|
|
|
#include <cstring>
|
2022-10-30 14:59:20 -04:00
|
|
|
#include <string>
|
2022-11-22 07:59:46 -05:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
2022-10-30 14:59:20 -04:00
|
|
|
#include <vector>
|
2023-12-20 21:14:53 -05:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <set>
|
2022-10-30 14:24:06 -04:00
|
|
|
|
|
|
|
namespace gd {
|
2022-10-30 14:59:20 -04:00
|
|
|
struct InternalString {
|
|
|
|
union {
|
|
|
|
char m_storage[16];
|
|
|
|
char* m_pointer;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t m_length;
|
|
|
|
size_t m_capacity;
|
|
|
|
};
|
|
|
|
|
2022-11-22 07:59:46 -05:00
|
|
|
class string : GDString {
|
2022-10-30 14:59:20 -04:00
|
|
|
private:
|
|
|
|
InternalString m_data;
|
|
|
|
|
2022-11-22 07:59:46 -05:00
|
|
|
char* get_data() {
|
|
|
|
if (m_data.m_capacity < 16) return m_data.m_storage;
|
|
|
|
return m_data.m_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_data() const {
|
|
|
|
if (m_data.m_capacity < 16) return m_data.m_storage;
|
|
|
|
return m_data.m_pointer;
|
|
|
|
}
|
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
public:
|
2023-01-19 06:31:32 -05:00
|
|
|
string() {
|
|
|
|
m_data.m_storage[0] = 0;
|
|
|
|
m_data.m_length = 0;
|
|
|
|
m_data.m_capacity = 15;
|
|
|
|
}
|
|
|
|
|
2023-01-19 06:27:42 -05:00
|
|
|
string(string const& param) : string() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
2023-01-19 06:27:42 -05:00
|
|
|
|
|
|
|
string(string&& param) : string() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2023-01-19 06:27:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
string(char const* param) : string() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param, std::strlen(param));
|
2023-01-19 06:27:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
string(std::string const& param) : string() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2023-01-19 06:27:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
string& operator=(string const& param) {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2023-01-19 06:27:42 -05:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
string& operator=(string&& param) {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2022-11-22 08:47:04 -05:00
|
|
|
return *this;
|
2022-11-22 08:46:03 -05:00
|
|
|
}
|
2023-01-19 06:27:42 -05:00
|
|
|
|
|
|
|
string& operator=(char const* param) {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param, std::strlen(param));
|
2023-01-19 06:27:42 -05:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
string& operator=(std::string const& param) {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winAssign(param.c_str(), param.size());
|
2023-01-19 06:27:42 -05:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winDtor();
|
2023-01-19 06:27:42 -05:00
|
|
|
}
|
2022-11-22 08:46:03 -05:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
~string() {
|
2023-12-20 21:14:53 -05:00
|
|
|
// (void)this->winDtor();
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char& at(size_t pos) {
|
|
|
|
if (pos >= m_data.m_length) throw std::out_of_range("gd::string::at");
|
2022-11-22 07:59:46 -05:00
|
|
|
return (*this)[pos];
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char const& at(size_t pos) const {
|
|
|
|
if (pos >= m_data.m_length) throw std::out_of_range("gd::string::at");
|
2022-11-22 07:59:46 -05:00
|
|
|
return (*this)[pos];
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char& operator[](size_t pos) {
|
2022-11-22 07:59:46 -05:00
|
|
|
return this->get_data()[pos];
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char const& operator[](size_t pos) const {
|
2022-11-22 07:59:46 -05:00
|
|
|
return this->get_data()[pos];
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char* data() {
|
2022-11-22 07:59:46 -05:00
|
|
|
return this->get_data();
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* data() const {
|
2022-11-22 07:59:46 -05:00
|
|
|
return this->get_data();
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* c_str() const {
|
2022-11-22 07:59:46 -05:00
|
|
|
return this->get_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() const {
|
|
|
|
return m_data.m_length;
|
|
|
|
}
|
|
|
|
|
2023-08-27 12:49:32 -04:00
|
|
|
bool operator<(const gd::string& other) const {
|
|
|
|
return std::string_view(this->c_str(), this->size()) < std::string_view(other.c_str(), other.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return this->size() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const {
|
|
|
|
return !this->empty();
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:59:46 -05:00
|
|
|
operator std::string() const {
|
|
|
|
return std::string(this->c_str(), this->size());
|
2022-10-30 14:59:20 -04:00
|
|
|
}
|
2023-08-27 12:49:32 -04:00
|
|
|
|
|
|
|
operator std::string_view() const {
|
|
|
|
return std::string_view(this->c_str(), this->size());
|
|
|
|
}
|
2022-10-30 14:59:20 -04:00
|
|
|
};
|
2022-10-30 14:24:06 -04:00
|
|
|
|
2022-11-22 07:59:46 -05:00
|
|
|
template <class T>
|
|
|
|
using vector = std::vector<T>;
|
|
|
|
|
|
|
|
template <class K, class V>
|
|
|
|
using map = std::map<K, V>;
|
2023-12-20 21:14:53 -05:00
|
|
|
|
|
|
|
template <class K, class V>
|
|
|
|
using unordered_map = std::unordered_map<K, V>;
|
|
|
|
|
|
|
|
template <class K>
|
|
|
|
using set = std::set<K>;
|
|
|
|
|
|
|
|
template <class K>
|
|
|
|
using unordered_set = std::unordered_set<K>;
|
2022-11-22 07:59:46 -05:00
|
|
|
}
|