#include <strngs.h>
Definition at line 44 of file strngs.h.
◆ STRING() [1/4]
◆ STRING() [2/4]
STRING::STRING |
( |
const STRING & |
string | ) |
|
Definition at line 110 of file strngs.cpp.
112 const STRING_HEADER* str_header = str.GetHeader();
113 int str_used = str_header->used_;
114 char *this_cstr = AllocData(str_used, str_used);
115 memcpy(this_cstr, str.GetCStr(), str_used);
116 assert(InvariantOk());
◆ STRING() [3/4]
STRING::STRING |
( |
const char * |
string | ) |
|
Definition at line 119 of file strngs.cpp.
124 int len = strlen(cstr) + 1;
125 char* this_cstr = AllocData(len, len);
126 memcpy(this_cstr, cstr, len);
128 assert(InvariantOk());
◆ STRING() [4/4]
STRING::STRING |
( |
const char * |
data, |
|
|
int |
length |
|
) |
| |
◆ ~STRING()
◆ add_str_double()
void STRING::add_str_double |
( |
const char * |
str, |
|
|
double |
number |
|
) |
| |
◆ add_str_int()
void STRING::add_str_int |
( |
const char * |
str, |
|
|
int |
number |
|
) |
| |
◆ assign()
void STRING::assign |
( |
const char * |
cstr, |
|
|
int |
len |
|
) |
| |
Definition at line 425 of file strngs.cpp.
426 STRING_HEADER* this_header = GetHeader();
427 this_header->used_ = 0;
428 char* this_cstr = ensure_cstr(len + 1);
430 this_header = GetHeader();
431 memcpy(this_cstr, cstr, len);
432 this_cstr[len] =
'\0';
433 this_header->used_ = len + 1;
435 assert(InvariantOk());
◆ c_str()
const char * STRING::c_str |
( |
| ) |
const |
Definition at line 212 of file strngs.cpp.
const char * string() const
◆ contains()
BOOL8 STRING::contains |
( |
const char |
c | ) |
const |
Definition at line 192 of file strngs.cpp.
193 return (c !=
'\0') && (strchr (GetCStr(), c) != NULL);
◆ DeSerialize() [1/2]
bool STRING::DeSerialize |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
Definition at line 163 of file strngs.cpp.
165 if (fread(&len,
sizeof(len), 1, fp) != 1)
return false;
169 if (static_cast<int>(fread(GetCStr(), 1, len, fp)) != len)
return false;
void truncate_at(inT32 index)
void ReverseN(void *ptr, int num_bytes)
◆ DeSerialize() [2/2]
Definition at line 174 of file strngs.cpp.
176 if (fp->
FRead(&len,
sizeof(len), 1) != 1)
return false;
180 if (fp->
FRead(GetCStr(), 1, len) != len)
return false;
void truncate_at(inT32 index)
int FRead(void *buffer, int size, int count)
void ReverseN(void *ptr, int num_bytes)
◆ ensure()
void STRING::ensure |
( |
inT32 |
min_capacity | ) |
|
|
inline |
Definition at line 114 of file strngs.h.
114 { ensure_cstr(min_capacity); }
◆ length()
inT32 STRING::length |
( |
| ) |
const |
Definition at line 196 of file strngs.cpp.
198 return GetHeader()->used_ - 1;
◆ operator!=() [1/2]
Definition at line 320 of file strngs.cpp.
323 const STRING_HEADER* str_header = str.GetHeader();
324 const STRING_HEADER* this_header = GetHeader();
325 int this_used = this_header->used_;
326 int str_used = str_header->used_;
328 return (this_used != str_used)
329 || (memcmp(GetCStr(), str.GetCStr(), this_used) != 0);
◆ operator!=() [2/2]
Definition at line 332 of file strngs.cpp.
334 const STRING_HEADER* this_header = GetHeader();
337 return this_header->used_ > 1;
340 return (this_header->used_ !=
length)
341 || (memcmp(GetCStr(), cstr,
length) != 0);
◆ operator+() [1/2]
Definition at line 438 of file strngs.cpp.
442 assert(InvariantOk());
◆ operator+() [2/2]
STRING STRING::operator+ |
( |
const char |
ch | ) |
const |
Definition at line 447 of file strngs.cpp.
450 const STRING_HEADER* this_header = GetHeader();
451 int this_used = this_header->used_;
452 char* result_cstr = result.ensure_cstr(this_used + 1);
453 STRING_HEADER* result_header = result.GetHeader();
454 int result_used = result_header->used_;
457 memcpy(result_cstr, GetCStr(), this_used);
458 result_cstr[result_used] = ch;
459 result_cstr[result_used + 1] =
'\0';
460 ++result_header->used_;
462 assert(InvariantOk());
◆ operator+=() [1/3]
STRING & STRING::operator+= |
( |
const char * |
string | ) |
|
Definition at line 467 of file strngs.cpp.
472 int len = strlen(str) + 1;
473 int this_used = GetHeader()->used_;
474 char* this_cstr = ensure_cstr(this_used + len);
475 STRING_HEADER* this_header = GetHeader();
480 memcpy(this_cstr + this_used - 1, str, len);
481 this_header->used_ += len - 1;
483 memcpy(this_cstr, str, len);
484 this_header->used_ = len;
487 assert(InvariantOk());
◆ operator+=() [2/3]
Definition at line 361 of file strngs.cpp.
364 const STRING_HEADER* str_header = str.GetHeader();
365 const char* str_cstr = str.GetCStr();
366 int str_used = str_header->used_;
367 int this_used = GetHeader()->used_;
368 char* this_cstr = ensure_cstr(this_used + str_used);
370 STRING_HEADER* this_header = GetHeader();
373 memcpy(this_cstr + this_used - 1, str_cstr, str_used);
374 this_header->used_ += str_used - 1;
376 memcpy(this_cstr, str_cstr, str_used);
377 this_header->used_ = str_used;
380 assert(InvariantOk());
◆ operator+=() [3/3]
STRING & STRING::operator+= |
( |
const char |
ch | ) |
|
Definition at line 492 of file strngs.cpp.
497 int this_used = GetHeader()->used_;
498 char* this_cstr = ensure_cstr(this_used + 1);
499 STRING_HEADER* this_header = GetHeader();
504 this_cstr[this_used++] = ch;
505 this_cstr[this_used++] =
'\0';
506 this_header->used_ = this_used;
508 assert(InvariantOk());
◆ operator=() [1/2]
STRING & STRING::operator= |
( |
const char * |
string | ) |
|
Definition at line 404 of file strngs.cpp.
405 STRING_HEADER* this_header = GetHeader();
407 int len = strlen(cstr) + 1;
409 this_header->used_ = 0;
410 char* this_cstr = ensure_cstr(len);
411 this_header = GetHeader();
412 memcpy(this_cstr, cstr, len);
413 this_header->used_ = len;
421 assert(InvariantOk());
◆ operator=() [2/2]
Definition at line 345 of file strngs.cpp.
347 const STRING_HEADER* str_header = str.GetHeader();
348 int str_used = str_header->used_;
350 GetHeader()->used_ = 0;
351 char* this_cstr = ensure_cstr(str_used);
352 STRING_HEADER* this_header = GetHeader();
354 memcpy(this_cstr, str.GetCStr(), str_used);
355 this_header->used_ = str_used;
357 assert(InvariantOk());
◆ operator==()
BOOL8 STRING::operator== |
( |
const STRING & |
string | ) |
const |
Definition at line 308 of file strngs.cpp.
311 const STRING_HEADER* str_header = str.GetHeader();
312 const STRING_HEADER* this_header = GetHeader();
313 int this_used = this_header->used_;
314 int str_used = str_header->used_;
316 return (this_used == str_used)
317 && (memcmp(GetCStr(), str.GetCStr(), this_used) == 0);
◆ operator[]()
char & STRING::operator[] |
( |
inT32 |
index | ) |
const |
Definition at line 281 of file strngs.cpp.
284 GetHeader()->used_ = -1;
285 return ((
char *)GetCStr())[index];
◆ Serialize() [1/2]
bool STRING::Serialize |
( |
FILE * |
fp | ) |
const |
Definition at line 148 of file strngs.cpp.
150 if (fwrite(&len,
sizeof(len), 1, fp) != 1)
return false;
151 if (static_cast<int>(fwrite(GetCStr(), 1, len, fp)) != len)
return false;
◆ Serialize() [2/2]
Definition at line 155 of file strngs.cpp.
157 if (fp->
FWrite(&len,
sizeof(len), 1) != 1)
return false;
158 if (fp->
FWrite(GetCStr(), 1, len) != len)
return false;
int FWrite(const void *buffer, int size, int count)
◆ size()
inT32 STRING::size |
( |
| ) |
const |
|
inline |
◆ SkipDeSerialize()
Definition at line 185 of file strngs.cpp.
187 if (fp->
FRead(&len,
sizeof(len), 1) != 1)
return false;
188 if (swap)
ReverseN(&len,
sizeof(len));
189 return fp->
FRead(NULL, 1, len) == len;
int FRead(void *buffer, int size, int count)
void ReverseN(void *ptr, int num_bytes)
◆ split()
Definition at line 289 of file strngs.cpp.
292 for (
int i = 0; i < len; i++) {
293 if ((*
this)[i] == c) {
294 if (i != start_index) {
303 if (len != start_index) {
304 splited->
push_back(
STRING(GetCStr() + start_index, len - start_index));
◆ strdup()
char* STRING::strdup |
( |
| ) |
const |
|
inline |
Definition at line 72 of file strngs.h.
74 return strncpy(
new char[len], GetCStr(), len);
◆ string()
const char * STRING::string |
( |
| ) |
const |
Definition at line 201 of file strngs.cpp.
202 const STRING_HEADER* header = GetHeader();
203 if (header->used_ == 0)
◆ truncate_at()
void STRING::truncate_at |
( |
inT32 |
index | ) |
|
Definition at line 272 of file strngs.cpp.
275 char* this_cstr = ensure_cstr(index + 1);
276 this_cstr[index] =
'\0';
277 GetHeader()->used_ = index + 1;
278 assert(InvariantOk());
The documentation for this class was generated from the following files: