2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _RSTL_STRING
|
|
|
|
#define _RSTL_STRING
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
#include "rstl/rmemory_allocator.hpp"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-10-14 10:01:20 +00:00
|
|
|
class CInputStream;
|
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
namespace rstl {
|
|
|
|
template < typename _CharTp >
|
|
|
|
struct char_traits {};
|
|
|
|
|
2022-09-18 06:05:46 +00:00
|
|
|
template < typename _CharTp, typename Traits = char_traits< _CharTp >,
|
|
|
|
typename Alloc = rmemory_allocator >
|
2022-04-10 00:17:06 +00:00
|
|
|
class basic_string {
|
|
|
|
struct COWData {
|
2022-10-09 05:37:23 +00:00
|
|
|
uint x0_capacity;
|
|
|
|
uint x4_refCount;
|
2022-04-10 00:17:06 +00:00
|
|
|
_CharTp* x8_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
const _CharTp* x0_ptr;
|
|
|
|
COWData* x4_cow;
|
2022-10-09 05:37:23 +00:00
|
|
|
uint x8_size;
|
|
|
|
uint _pad; // Alloc?
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
// void internal_allocate(int size)
|
|
|
|
// {
|
2022-10-09 05:37:23 +00:00
|
|
|
// x4_cow = reinterpret_cast<COWData*>(new uchar[size * sizeof(_CharTp) +
|
|
|
|
// 8]); x0_ptr = x4_cow->x8_data; x4_cow->x0_capacity = uint(size);
|
2022-04-10 00:17:06 +00:00
|
|
|
// x4_cow->x4_refCount = 1;
|
|
|
|
// }
|
|
|
|
|
|
|
|
void internal_dereference();
|
|
|
|
// {
|
|
|
|
// if (x4_cow && --x4_cow->x4_refCount == 0)
|
|
|
|
// delete[] x4_cow;
|
|
|
|
// }
|
|
|
|
|
2022-10-16 16:35:43 +00:00
|
|
|
static const _CharTp mNull;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct literal_t {};
|
|
|
|
|
2022-10-16 16:35:43 +00:00
|
|
|
basic_string() : x0_ptr(&mNull), x4_cow(nullptr), x8_size(0) {}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
basic_string(literal_t, const _CharTp* data);
|
|
|
|
// {
|
|
|
|
// x0_ptr = data;
|
|
|
|
// x4_cow = nullptr;
|
|
|
|
|
|
|
|
// const _CharTp* it = data;
|
|
|
|
// while (*it)
|
|
|
|
// ++it;
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
// x8_size = uint((it - data) / sizeof(_CharTp));
|
2022-04-10 00:17:06 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
basic_string(const basic_string& str);
|
|
|
|
// {
|
|
|
|
// x0_ptr = str.x0_ptr;
|
|
|
|
// x4_cow = str.x4_cow;
|
|
|
|
// x8_size = str.x8_size;
|
|
|
|
// if (x4_cow)
|
|
|
|
// ++x4_cow->x4_refCount;
|
|
|
|
// }
|
|
|
|
|
2022-10-14 10:01:20 +00:00
|
|
|
basic_string(CInputStream& in, const Alloc& = rmemory_allocator());
|
|
|
|
|
2022-10-08 08:46:42 +00:00
|
|
|
basic_string(const _CharTp* data, int size = -1, const Alloc& = rmemory_allocator());
|
2022-04-10 00:17:06 +00:00
|
|
|
// {
|
|
|
|
// if (size <= 0 && !data)
|
|
|
|
// {
|
2022-10-16 16:35:43 +00:00
|
|
|
// x0_ptr = &mNull;
|
2022-04-10 00:17:06 +00:00
|
|
|
// x4_cow = nullptr;
|
|
|
|
// x8_size = 0;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const _CharTp* it = data;
|
2022-10-09 05:37:23 +00:00
|
|
|
// uint len = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
// while (*it)
|
|
|
|
// {
|
|
|
|
// if (size != -1 && len >= size)
|
|
|
|
// break;
|
|
|
|
// ++it;
|
|
|
|
// ++len;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// internal_allocate(len + 1);
|
|
|
|
// x8_size = len;
|
|
|
|
// for (int i = 0; i < len; ++i)
|
|
|
|
// x4_cow->x8_data[i] = data[i];
|
|
|
|
// x4_cow->x8_data[len] = 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
~basic_string() { internal_dereference(); }
|
|
|
|
|
2022-10-23 04:49:41 +00:00
|
|
|
size_t size() const { return x8_size; }
|
2022-10-16 16:35:43 +00:00
|
|
|
void assign(const basic_string&);
|
2022-10-30 19:47:50 +00:00
|
|
|
basic_string& operator=(const basic_string& other) {
|
|
|
|
assign(other);
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
basic_string operator+(const basic_string&);
|
2022-10-11 17:32:10 +00:00
|
|
|
basic_string operator+(const _CharTp*);
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
const char* data() const { return x0_ptr; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// template <>
|
2022-10-16 16:35:43 +00:00
|
|
|
// const char basic_string<char>::mNull = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
// template <>
|
2022-10-16 16:35:43 +00:00
|
|
|
// const wchar_t basic_string<wchar_t>::mNull = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
typedef basic_string< wchar_t > wstring;
|
|
|
|
typedef basic_string< char > string;
|
|
|
|
|
|
|
|
wstring wstring_l(const wchar_t* data);
|
|
|
|
// {
|
|
|
|
// return wstring(wstring::literal_t(), data);
|
|
|
|
// }
|
|
|
|
|
|
|
|
string string_l(const char* data);
|
|
|
|
// {
|
|
|
|
// return string(string::literal_t(), data);
|
|
|
|
// }
|
2022-08-13 01:26:00 +00:00
|
|
|
|
2022-10-31 23:46:20 +00:00
|
|
|
string operator+(const string&, const string&);
|
|
|
|
|
2022-08-13 01:26:00 +00:00
|
|
|
CHECK_SIZEOF(string, 0x10)
|
2022-04-10 00:17:06 +00:00
|
|
|
} // namespace rstl
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _RSTL_STRING
|