41 #define STRING_IS_PROTECTED 0
50 STRING(
const char*
string);
51 STRING(
const char* data,
int length);
67 bool contains(
char c)
const;
68 int32_t length()
const;
69 int32_t size()
const {
73 uint32_t unsigned_size()
const {
74 const int32_t len = length();
76 return static_cast<uint32_t>(len);
78 const char* c_str()
const;
80 inline char* strdup()
const {
81 int32_t len = length() + 1;
82 return strncpy(
new char[len], GetCStr(), len);
85 #if STRING_IS_PROTECTED
86 const char& operator[](int32_t index)
const;
88 void insert_range(int32_t index,
const char* s,
int len);
89 void erase_range(int32_t index,
int len);
91 char& operator[](int32_t index)
const;
94 void truncate_at(int32_t index);
100 STRING& operator=(
const char*
string);
111 void assign(
const char* cstr,
int len);
117 void add_str_int(
const char* str,
int number);
119 void add_str_double(
const char* str,
double number);
122 inline void ensure(int32_t min_capacity) {
123 ensure_cstr(min_capacity);
127 typedef struct STRING_HEADER {
149 STRING_HEADER* data_;
152 inline STRING_HEADER* GetHeader() {
155 inline const STRING_HEADER* GetHeader()
const {
160 inline char* GetCStr() {
161 return (reinterpret_cast<char*>(data_)) +
sizeof(STRING_HEADER);
164 inline const char* GetCStr()
const {
165 return (reinterpret_cast<const char*>(data_)) +
sizeof(STRING_HEADER);
167 inline bool InvariantOk()
const {
168 #if STRING_IS_PROTECTED
169 return (GetHeader()->used_ == 0)
170 ? (c_str() ==
nullptr)
171 : (GetHeader()->used_ == (strlen(c_str()) + 1));
180 char* ensure_cstr(int32_t min_capacity);
182 void FixHeader()
const;
184 char* AllocData(
int used,
int capacity);