2023-12-22 16:09:58 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
2023-12-23 00:59:45 -05:00
|
|
|
#include <string_view>
|
|
|
|
#include <string>
|
2023-12-23 03:05:59 -05:00
|
|
|
#include <compare>
|
2023-12-22 16:09:58 -05:00
|
|
|
|
|
|
|
namespace geode::stl {
|
2023-12-23 08:36:24 -05:00
|
|
|
class StringImpl;
|
2023-12-22 16:09:58 -05:00
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
struct StringData;
|
2023-12-22 16:09:58 -05:00
|
|
|
|
|
|
|
#if defined(GEODE_IS_WINDOWS)
|
2023-12-23 08:36:24 -05:00
|
|
|
struct StringData {
|
2023-12-22 16:09:58 -05:00
|
|
|
union {
|
|
|
|
std::array<char, 16> m_smallStorage;
|
|
|
|
char* m_bigStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t m_size;
|
|
|
|
size_t m_capacity;
|
|
|
|
};
|
|
|
|
#elif defined(GEODE_IS_MACOS) || defined(GEODE_IS_ANDROID)
|
2023-12-23 08:36:24 -05:00
|
|
|
struct StringData {
|
2023-12-22 16:09:58 -05:00
|
|
|
struct Internal {
|
|
|
|
size_t m_size;
|
|
|
|
size_t m_capacity;
|
|
|
|
int m_refcount;
|
|
|
|
};
|
2023-12-23 00:59:45 -05:00
|
|
|
Internal* m_data = nullptr;
|
2023-12-22 16:09:58 -05:00
|
|
|
};
|
|
|
|
#elif defined(GEODE_IS_IOS)
|
2023-12-23 08:36:24 -05:00
|
|
|
struct StringData {
|
2023-12-22 16:09:58 -05:00
|
|
|
struct Short {
|
|
|
|
uint8_t sizex2;
|
|
|
|
std::array<char, 23> shortStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Long {
|
|
|
|
size_t capacitym1;
|
|
|
|
size_t size;
|
|
|
|
char* longStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
Short m_short;
|
|
|
|
Long m_long;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace gd {
|
2024-06-04 17:33:07 -04:00
|
|
|
#if defined(GEODE_IS_MACOS) || defined(GEODE_IS_WINDOWS)
|
2024-01-19 18:33:17 -05:00
|
|
|
// rob uses libc++ now! this will prob work fine
|
|
|
|
using string = std::string;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2023-12-22 16:09:58 -05:00
|
|
|
class GEODE_DLL string {
|
2023-12-23 08:36:24 -05:00
|
|
|
geode::stl::StringData m_data;
|
|
|
|
friend geode::stl::StringImpl;
|
2023-12-22 16:09:58 -05:00
|
|
|
public:
|
|
|
|
string();
|
|
|
|
string(string const&);
|
2023-12-23 00:59:45 -05:00
|
|
|
// string(string&&);
|
2023-12-22 16:09:58 -05:00
|
|
|
string(char const*);
|
2024-07-30 11:19:33 -04:00
|
|
|
string(char const*, size_t);
|
2023-12-22 16:09:58 -05:00
|
|
|
string(std::string const&);
|
|
|
|
// tried to add a string_view ctor, but got overload errors :(
|
|
|
|
~string();
|
|
|
|
|
|
|
|
string& operator=(string const&);
|
|
|
|
string& operator=(string&&);
|
|
|
|
string& operator=(char const*);
|
|
|
|
string& operator=(std::string const&);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
char& at(size_t pos);
|
|
|
|
char const& at(size_t pos) const;
|
|
|
|
|
|
|
|
char& operator[](size_t pos);
|
|
|
|
char const& operator[](size_t pos) const;
|
|
|
|
|
|
|
|
char* data();
|
|
|
|
char const* data() const;
|
|
|
|
char const* c_str() const;
|
|
|
|
|
|
|
|
size_t size() const;
|
|
|
|
size_t capacity() const;
|
|
|
|
bool empty() const;
|
|
|
|
|
2023-12-23 03:05:59 -05:00
|
|
|
bool operator==(string const& other) const;
|
|
|
|
bool operator==(std::string_view const other) const;
|
2024-02-19 15:44:22 -05:00
|
|
|
bool operator==(char const* other) const {
|
|
|
|
return *this == std::string_view(other);
|
|
|
|
}
|
2024-02-19 15:52:33 -05:00
|
|
|
bool operator==(std::string const& other) const {
|
|
|
|
return *this == std::string_view(other);
|
|
|
|
}
|
2023-12-23 00:59:45 -05:00
|
|
|
std::strong_ordering operator<=>(string const& other) const;
|
|
|
|
std::strong_ordering operator<=>(std::string_view const other) const;
|
2024-02-19 15:44:22 -05:00
|
|
|
std::strong_ordering operator<=>(char const* other) const {
|
|
|
|
return *this <=> std::string_view(other);
|
|
|
|
}
|
2024-02-19 15:52:33 -05:00
|
|
|
std::strong_ordering operator<=>(std::string const& other) const {
|
|
|
|
return *this <=> std::string_view(other);
|
|
|
|
}
|
2023-12-22 16:09:58 -05:00
|
|
|
|
|
|
|
operator std::string() const;
|
|
|
|
operator std::string_view() const;
|
|
|
|
};
|
2024-01-19 18:33:17 -05:00
|
|
|
|
|
|
|
#endif
|
2023-12-22 16:09:58 -05:00
|
|
|
}
|