#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 110 of file strngs.cpp.
112 const STRING_HEADER* str_header = str.GetHeader();
113 const 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.
120 if (cstr ==
nullptr) {
124 const 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 |
|
) |
| |
Definition at line 131 of file strngs.cpp.
132 if (data ==
nullptr) {
137 memcpy(this_cstr, data,
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 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 207 of file strngs.cpp.
const char * string() const
◆ contains()
bool STRING::contains |
( |
const char |
c | ) |
const |
Definition at line 187 of file strngs.cpp.
188 return (c !=
'\0') && (strchr (GetCStr(), c) !=
nullptr);
◆ DeSerialize() [1/2]
bool STRING::DeSerialize |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
Definition at line 161 of file strngs.cpp.
167 if (len > UINT16_MAX)
return false;
void ReverseN(void *ptr, int num_bytes)
void truncate_at(int32_t index)
bool DeSerialize(FILE *fp, char *data, size_t n)
◆ DeSerialize() [2/2]
Definition at line 173 of file strngs.cpp.
bool DeSerialize(char *data, size_t count=1)
void truncate_at(int32_t index)
◆ ensure()
void STRING::ensure |
( |
int32_t |
min_capacity | ) |
|
|
inline |
Definition at line 121 of file strngs.h.
121 { ensure_cstr(min_capacity); }
◆ length()
int32_t STRING::length |
( |
| ) |
const |
Definition at line 191 of file strngs.cpp.
193 return GetHeader()->used_ - 1;
◆ operator!=() [1/2]
Definition at line 315 of file strngs.cpp.
318 const STRING_HEADER* str_header = str.GetHeader();
319 const STRING_HEADER* this_header = GetHeader();
320 const int this_used = this_header->used_;
321 const int str_used = str_header->used_;
323 return (this_used != str_used)
324 || (memcmp(GetCStr(), str.GetCStr(), this_used) != 0);
◆ operator!=() [2/2]
Definition at line 327 of file strngs.cpp.
329 const STRING_HEADER* this_header = GetHeader();
332 return this_header->used_ > 1;
334 const int32_t
length = strlen(cstr) + 1;
335 return (this_header->used_ !=
length)
336 || (memcmp(GetCStr(), cstr,
length) != 0);
◆ operator+() [1/2]
Definition at line 433 of file strngs.cpp.
437 assert(InvariantOk());
◆ operator+() [2/2]
STRING STRING::operator+ |
( |
const 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+=() [1/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+=() [2/3]
Definition at line 356 of file strngs.cpp.
359 const STRING_HEADER* str_header = str.GetHeader();
360 const char* str_cstr = str.GetCStr();
361 const int str_used = str_header->used_;
362 const int this_used = GetHeader()->used_;
363 char* this_cstr = ensure_cstr(this_used + str_used);
365 STRING_HEADER* this_header = GetHeader();
368 memcpy(this_cstr + this_used - 1, str_cstr, str_used);
369 this_header->used_ += str_used - 1;
371 memcpy(this_cstr, str_cstr, str_used);
372 this_header->used_ = str_used;
375 assert(InvariantOk());
◆ operator+=() [3/3]
STRING & STRING::operator+= |
( |
const 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=() [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 340 of file strngs.cpp.
342 const STRING_HEADER* str_header = str.GetHeader();
343 const int str_used = str_header->used_;
345 GetHeader()->used_ = 0;
346 char* this_cstr = ensure_cstr(str_used);
347 STRING_HEADER* this_header = GetHeader();
349 memcpy(this_cstr, str.GetCStr(), str_used);
350 this_header->used_ = str_used;
352 assert(InvariantOk());
◆ operator==()
bool STRING::operator== |
( |
const STRING & |
string | ) |
const |
Definition at line 303 of file strngs.cpp.
306 const STRING_HEADER* str_header = str.GetHeader();
307 const STRING_HEADER* this_header = GetHeader();
308 const int this_used = this_header->used_;
309 const int str_used = str_header->used_;
311 return (this_used == str_used)
312 && (memcmp(GetCStr(), str.GetCStr(), this_used) == 0);
◆ operator[]()
char & STRING::operator[] |
( |
int32_t |
index | ) |
const |
Definition at line 276 of file strngs.cpp.
279 GetHeader()->used_ = -1;
280 return ((
char *)GetCStr())[index];
◆ Serialize() [1/2]
bool STRING::Serialize |
( |
FILE * |
fp | ) |
const |
Definition at line 148 of file strngs.cpp.
bool Serialize(FILE *fp, const char *data, size_t n)
◆ Serialize() [2/2]
Definition at line 154 of file strngs.cpp.
bool Serialize(const char *data, size_t count=1)
◆ size()
int32_t STRING::size |
( |
| ) |
const |
|
inline |
◆ SkipDeSerialize()
Definition at line 181 of file strngs.cpp.
184 return fp->
Skip(len);
bool DeSerialize(char *data, size_t count=1)
◆ split()
Definition at line 284 of file strngs.cpp.
287 for (
int i = 0; i < len; i++) {
288 if ((*
this)[i] == c) {
289 if (i != start_index) {
298 if (len != start_index) {
299 splited->
push_back(
STRING(GetCStr() + start_index, len - start_index));
◆ strdup()
char* STRING::strdup |
( |
| ) |
const |
|
inline |
Definition at line 79 of file strngs.h.
80 int32_t len =
length() + 1;
81 return strncpy(
new char[len], GetCStr(), len);
◆ string()
const char * STRING::string |
( |
| ) |
const |
Definition at line 196 of file strngs.cpp.
197 const STRING_HEADER* header = GetHeader();
198 if (header->used_ == 0)
◆ truncate_at()
void STRING::truncate_at |
( |
int32_t |
index | ) |
|
Definition at line 267 of file strngs.cpp.
270 char* this_cstr = ensure_cstr(index + 1);
271 this_cstr[index] =
'\0';
272 GetHeader()->used_ = index + 1;
273 assert(InvariantOk());
◆ unsigned_size()
uint32_t STRING::unsigned_size |
( |
| ) |
const |
|
inline |
Definition at line 71 of file strngs.h.
72 const int32_t len =
length();
74 return static_cast<uint32_t
>(len);
The documentation for this class was generated from the following files:
- /usr/src/tesseract-ocr.master/src/ccutil/strngs.h
- /usr/src/tesseract-ocr.master/src/ccutil/strngs.cpp