41 #define STRING_IS_PROTECTED 0 50 STRING(
const char *
string);
51 STRING(
const char *data,
int length);
67 bool contains(
const char c)
const;
68 int32_t length()
const;
69 int32_t
size()
const {
return length(); }
72 const int32_t len = length();
74 return static_cast<uint32_t
>(len);
76 const char *string()
const;
77 const char *c_str()
const;
80 int32_t len = length() + 1;
81 return strncpy(
new char[len], GetCStr(), len);
84 #if STRING_IS_PROTECTED 85 const char &operator[] (int32_t index)
const;
87 void insert_range(int32_t index,
const char*s,
int len);
88 void erase_range(int32_t index,
int len);
90 char &operator[] (int32_t index)
const;
93 void truncate_at(int32_t index);
95 bool operator== (
const STRING &
string)
const;
96 bool operator!= (
const STRING &
string)
const;
97 bool operator!= (
const char *
string)
const;
99 STRING & operator= (
const char *
string);
110 void assign(
const char *cstr,
int len);
116 void add_str_int(
const char* str,
int number);
118 void add_str_double(
const char* str,
double number);
121 inline void ensure(int32_t min_capacity) { ensure_cstr(min_capacity); }
124 typedef struct STRING_HEADER {
146 STRING_HEADER* data_;
149 inline STRING_HEADER* GetHeader() {
152 inline const STRING_HEADER* GetHeader()
const {
157 inline char* GetCStr() {
return ((
char*)data_) +
sizeof(STRING_HEADER); }
159 inline const char* GetCStr()
const {
160 return ((
const char *)data_) +
sizeof(STRING_HEADER);
162 inline bool InvariantOk()
const {
163 #if STRING_IS_PROTECTED 164 return (GetHeader()->used_ == 0) ?
165 (string() ==
nullptr) : (GetHeader()->used_ == (strlen(
string()) + 1));
174 char* ensure_cstr(int32_t min_capacity);
176 void FixHeader()
const;
178 char* AllocData(
int used,
int capacity);
ICOORD & operator+=(ICOORD &op1, const ICOORD &op2)
uint32_t unsigned_size() const
bool Serialize(FILE *fp, const char *data, size_t n)
ICOORD operator+(const ICOORD &op1, const ICOORD &op2)
void ensure(int32_t min_capacity)
bool DeSerialize(FILE *fp, char *data, size_t n)