#include <strngs.h>
Definition at line 45 of file strngs.h.
◆ STRING() [1/4]
◆ STRING() [2/4]
STRING::STRING |
( |
const STRING & |
string | ) |
|
Definition at line 108 of file strngs.cpp.
110 const STRING_HEADER* str_header = str.GetHeader();
111 const int str_used = str_header->used_;
112 char *this_cstr = AllocData(str_used, str_used);
113 memcpy(this_cstr, str.GetCStr(), str_used);
114 assert(InvariantOk());
◆ STRING() [3/4]
STRING::STRING |
( |
const char * |
string | ) |
|
Definition at line 117 of file strngs.cpp.
118 if (cstr ==
nullptr) {
122 const int len = strlen(cstr) + 1;
123 char* this_cstr = AllocData(len, len);
124 memcpy(this_cstr, cstr, len);
126 assert(InvariantOk());
◆ STRING() [4/4]
STRING::STRING |
( |
const char * |
data, |
|
|
int |
length |
|
) |
| |
Definition at line 129 of file strngs.cpp.
130 if (data ==
nullptr) {
135 memcpy(this_cstr, data,
length);
◆ ~STRING()
◆ add_str_double()
void STRING::add_str_double |
( |
const char * |
str, |
|
|
double |
number |
|
) |
| |
Definition at line 387 of file strngs.cpp.
390 std::stringstream stream;
392 stream.imbue(std::locale::classic());
396 *
this += stream.str().c_str();
◆ 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 420 of file strngs.cpp.
421 STRING_HEADER* this_header = GetHeader();
422 this_header->used_ = 0;
423 char* this_cstr = ensure_cstr(len + 1);
425 this_header = GetHeader();
426 memcpy(this_cstr, cstr, len);
427 this_cstr[len] =
'\0';
428 this_header->used_ = len + 1;
430 assert(InvariantOk());
◆ c_str()
const char * STRING::c_str |
( |
| ) |
const |
Definition at line 205 of file strngs.cpp.
const char * string() const
◆ contains()
bool STRING::contains |
( |
char |
c | ) |
const |
Definition at line 185 of file strngs.cpp.
186 return (c !=
'\0') && (strchr (GetCStr(), c) !=
nullptr);
◆ DeSerialize() [1/2]
bool STRING::DeSerialize |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
Definition at line 159 of file strngs.cpp.
165 if (len > UINT16_MAX)
return false;
void ReverseN(void *ptr, int num_bytes)
bool DeSerialize(FILE *fp, char *data, size_t n)
void truncate_at(int32_t index)
◆ DeSerialize() [2/2]
Definition at line 171 of file strngs.cpp.
bool DeSerialize(char *data, size_t count=1)
◆ ensure()
void STRING::ensure |
( |
int32_t |
min_capacity | ) |
|
|
inline |
Definition at line 122 of file strngs.h.
123 ensure_cstr(min_capacity);
◆ length()
int32_t STRING::length |
( |
| ) |
const |
Definition at line 189 of file strngs.cpp.
191 return GetHeader()->used_ - 1;
◆ operator!=() [1/2]
Definition at line 325 of file strngs.cpp.
327 const STRING_HEADER* this_header = GetHeader();
330 return this_header->used_ > 1;
332 const int32_t
length = strlen(cstr) + 1;
333 return (this_header->used_ !=
length)
334 || (memcmp(GetCStr(), cstr,
length) != 0);
◆ operator!=() [2/2]
Definition at line 313 of file strngs.cpp.
316 const STRING_HEADER* str_header = str.GetHeader();
317 const STRING_HEADER* this_header = GetHeader();
318 const int this_used = this_header->used_;
319 const int str_used = str_header->used_;
321 return (this_used != str_used)
322 || (memcmp(GetCStr(), str.GetCStr(), this_used) != 0);
◆ operator+() [1/2]
STRING STRING::operator+ |
( |
char |
ch | ) |
const |
Definition at line 442 of file strngs.cpp.
445 const STRING_HEADER* this_header = GetHeader();
446 const int this_used = this_header->used_;
447 char* result_cstr = result.ensure_cstr(this_used + 1);
448 STRING_HEADER* result_header = result.GetHeader();
449 const int result_used = result_header->used_;
452 memcpy(result_cstr, GetCStr(), this_used);
453 result_cstr[result_used] = ch;
454 result_cstr[result_used + 1] =
'\0';
455 ++result_header->used_;
457 assert(InvariantOk());
◆ operator+() [2/2]
Definition at line 433 of file strngs.cpp.
437 assert(InvariantOk());
◆ operator+=() [1/3]
STRING & STRING::operator+= |
( |
char |
ch | ) |
|
Definition at line 487 of file strngs.cpp.
492 int this_used = GetHeader()->used_;
493 char* this_cstr = ensure_cstr(this_used + 1);
494 STRING_HEADER* this_header = GetHeader();
499 this_cstr[this_used++] = ch;
500 this_cstr[this_used++] =
'\0';
501 this_header->used_ = this_used;
503 assert(InvariantOk());
◆ operator+=() [2/3]
STRING & STRING::operator+= |
( |
const char * |
string | ) |
|
Definition at line 462 of file strngs.cpp.
467 const int len = strlen(str) + 1;
468 const int this_used = GetHeader()->used_;
469 char* this_cstr = ensure_cstr(this_used + len);
470 STRING_HEADER* this_header = GetHeader();
475 memcpy(this_cstr + this_used - 1, str, len);
476 this_header->used_ += len - 1;
478 memcpy(this_cstr, str, len);
479 this_header->used_ = len;
482 assert(InvariantOk());
◆ operator+=() [3/3]
Definition at line 354 of file strngs.cpp.
357 const STRING_HEADER* str_header = str.GetHeader();
358 const char* str_cstr = str.GetCStr();
359 const int str_used = str_header->used_;
360 const int this_used = GetHeader()->used_;
361 char* this_cstr = ensure_cstr(this_used + str_used);
363 STRING_HEADER* this_header = GetHeader();
366 memcpy(this_cstr + this_used - 1, str_cstr, str_used);
367 this_header->used_ += str_used - 1;
369 memcpy(this_cstr, str_cstr, str_used);
370 this_header->used_ = str_used;
373 assert(InvariantOk());
◆ operator=() [1/2]
STRING & STRING::operator= |
( |
const char * |
string | ) |
|
Definition at line 399 of file strngs.cpp.
400 STRING_HEADER* this_header = GetHeader();
402 const int len = strlen(cstr) + 1;
404 this_header->used_ = 0;
405 char* this_cstr = ensure_cstr(len);
406 this_header = GetHeader();
407 memcpy(this_cstr, cstr, len);
408 this_header->used_ = len;
416 assert(InvariantOk());
◆ operator=() [2/2]
Definition at line 338 of file strngs.cpp.
340 const STRING_HEADER* str_header = str.GetHeader();
341 const int str_used = str_header->used_;
343 GetHeader()->used_ = 0;
344 char* this_cstr = ensure_cstr(str_used);
345 STRING_HEADER* this_header = GetHeader();
347 memcpy(this_cstr, str.GetCStr(), str_used);
348 this_header->used_ = str_used;
350 assert(InvariantOk());
◆ operator==()
bool STRING::operator== |
( |
const STRING & |
string | ) |
const |
Definition at line 301 of file strngs.cpp.
304 const STRING_HEADER* str_header = str.GetHeader();
305 const STRING_HEADER* this_header = GetHeader();
306 const int this_used = this_header->used_;
307 const int str_used = str_header->used_;
309 return (this_used == str_used)
310 && (memcmp(GetCStr(), str.GetCStr(), this_used) == 0);
◆ operator[]()
char & STRING::operator[] |
( |
int32_t |
index | ) |
const |
Definition at line 274 of file strngs.cpp.
277 GetHeader()->used_ = -1;
278 return (
const_cast<char *
>(GetCStr()))[index];
◆ Serialize() [1/2]
bool STRING::Serialize |
( |
FILE * |
fp | ) |
const |
Definition at line 146 of file strngs.cpp.
bool Serialize(FILE *fp, const char *data, size_t n)
◆ Serialize() [2/2]
Definition at line 152 of file strngs.cpp.
bool Serialize(const char *data, size_t count=1)
◆ size()
int32_t STRING::size |
( |
| ) |
const |
|
inline |
◆ SkipDeSerialize()
◆ split()
Definition at line 282 of file strngs.cpp.
285 for (
int i = 0; i < len; i++) {
286 if ((*
this)[i] == c) {
287 if (i != start_index) {
296 if (len != start_index) {
297 splited->
push_back(
STRING(GetCStr() + start_index, len - start_index));
◆ strdup()
char* STRING::strdup |
( |
| ) |
const |
|
inline |
Definition at line 80 of file strngs.h.
81 int32_t len =
length() + 1;
82 return strncpy(
new char[len], GetCStr(), len);
◆ string()
const char * STRING::string |
( |
| ) |
const |
Definition at line 194 of file strngs.cpp.
195 const STRING_HEADER* header = GetHeader();
196 if (!header || header->used_ == 0)
◆ truncate_at()
void STRING::truncate_at |
( |
int32_t |
index | ) |
|
Definition at line 265 of file strngs.cpp.
268 char* this_cstr = ensure_cstr(index + 1);
269 this_cstr[index] =
'\0';
270 GetHeader()->used_ = index + 1;
271 assert(InvariantOk());
◆ unsigned_size()
uint32_t STRING::unsigned_size |
( |
| ) |
const |
|
inline |
Definition at line 72 of file strngs.h.
73 const int32_t len =
length();
75 return static_cast<uint32_t
>(len);
The documentation for this class was generated from the following files: