#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 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 422 of file strngs.cpp.
423 STRING_HEADER* this_header = GetHeader();
424 this_header->used_ = 0;
425 char* this_cstr = ensure_cstr(len + 1);
427 this_header = GetHeader();
428 memcpy(this_cstr, cstr, len);
429 this_cstr[len] =
'\0';
430 this_header->used_ = len + 1;
432 assert(InvariantOk());
◆ c_str()
const char * STRING::c_str |
( |
| ) |
const |
Definition at line 209 of file strngs.cpp.
const char * string() const
◆ contains()
BOOL8 STRING::contains |
( |
const char |
c | ) |
const |
Definition at line 189 of file strngs.cpp.
190 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->
FReadEndian(&len,
sizeof(len), 1) != 1)
return false;
178 if (fp->
FRead(GetCStr(), 1, len) != len)
return false;
void truncate_at(inT32 index)
int FReadEndian(void *buffer, int size, int count)
int FRead(void *buffer, int size, int count)
◆ ensure()
void STRING::ensure |
( |
inT32 |
min_capacity | ) |
|
|
inline |
Definition at line 121 of file strngs.h.
121 { ensure_cstr(min_capacity); }
◆ length()
inT32 STRING::length |
( |
| ) |
const |
Definition at line 193 of file strngs.cpp.
195 return GetHeader()->used_ - 1;
◆ operator!=() [1/2]
Definition at line 317 of file strngs.cpp.
320 const STRING_HEADER* str_header = str.GetHeader();
321 const STRING_HEADER* this_header = GetHeader();
322 int this_used = this_header->used_;
323 int str_used = str_header->used_;
325 return (this_used != str_used)
326 || (memcmp(GetCStr(), str.GetCStr(), this_used) != 0);
◆ operator!=() [2/2]
Definition at line 329 of file strngs.cpp.
331 const STRING_HEADER* this_header = GetHeader();
334 return this_header->used_ > 1;
337 return (this_header->used_ != length)
338 || (memcmp(GetCStr(), cstr, length) != 0);
◆ operator+() [1/2]
Definition at line 435 of file strngs.cpp.
439 assert(InvariantOk());
◆ operator+() [2/2]
STRING STRING::operator+ |
( |
const char |
ch | ) |
const |
Definition at line 444 of file strngs.cpp.
447 const STRING_HEADER* this_header = GetHeader();
448 int this_used = this_header->used_;
449 char* result_cstr = result.ensure_cstr(this_used + 1);
450 STRING_HEADER* result_header = result.GetHeader();
451 int result_used = result_header->used_;
454 memcpy(result_cstr, GetCStr(), this_used);
455 result_cstr[result_used] = ch;
456 result_cstr[result_used + 1] =
'\0';
457 ++result_header->used_;
459 assert(InvariantOk());
◆ operator+=() [1/3]
STRING & STRING::operator+= |
( |
const char * |
string | ) |
|
Definition at line 464 of file strngs.cpp.
469 int len = strlen(str) + 1;
470 int this_used = GetHeader()->used_;
471 char* this_cstr = ensure_cstr(this_used + len);
472 STRING_HEADER* this_header = GetHeader();
477 memcpy(this_cstr + this_used - 1, str, len);
478 this_header->used_ += len - 1;
480 memcpy(this_cstr, str, len);
481 this_header->used_ = len;
484 assert(InvariantOk());
◆ operator+=() [2/3]
Definition at line 358 of file strngs.cpp.
361 const STRING_HEADER* str_header = str.GetHeader();
362 const char* str_cstr = str.GetCStr();
363 int str_used = str_header->used_;
364 int this_used = GetHeader()->used_;
365 char* this_cstr = ensure_cstr(this_used + str_used);
367 STRING_HEADER* this_header = GetHeader();
370 memcpy(this_cstr + this_used - 1, str_cstr, str_used);
371 this_header->used_ += str_used - 1;
373 memcpy(this_cstr, str_cstr, str_used);
374 this_header->used_ = str_used;
377 assert(InvariantOk());
◆ operator+=() [3/3]
STRING & STRING::operator+= |
( |
const char |
ch | ) |
|
Definition at line 489 of file strngs.cpp.
494 int this_used = GetHeader()->used_;
495 char* this_cstr = ensure_cstr(this_used + 1);
496 STRING_HEADER* this_header = GetHeader();
501 this_cstr[this_used++] = ch;
502 this_cstr[this_used++] =
'\0';
503 this_header->used_ = this_used;
505 assert(InvariantOk());
◆ operator=() [1/2]
STRING & STRING::operator= |
( |
const char * |
string | ) |
|
Definition at line 401 of file strngs.cpp.
402 STRING_HEADER* this_header = GetHeader();
404 int len = strlen(cstr) + 1;
406 this_header->used_ = 0;
407 char* this_cstr = ensure_cstr(len);
408 this_header = GetHeader();
409 memcpy(this_cstr, cstr, len);
410 this_header->used_ = len;
418 assert(InvariantOk());
◆ operator=() [2/2]
Definition at line 342 of file strngs.cpp.
344 const STRING_HEADER* str_header = str.GetHeader();
345 int str_used = str_header->used_;
347 GetHeader()->used_ = 0;
348 char* this_cstr = ensure_cstr(str_used);
349 STRING_HEADER* this_header = GetHeader();
351 memcpy(this_cstr, str.GetCStr(), str_used);
352 this_header->used_ = str_used;
354 assert(InvariantOk());
◆ operator==()
BOOL8 STRING::operator== |
( |
const STRING & |
string | ) |
const |
Definition at line 305 of file strngs.cpp.
308 const STRING_HEADER* str_header = str.GetHeader();
309 const STRING_HEADER* this_header = GetHeader();
310 int this_used = this_header->used_;
311 int str_used = str_header->used_;
313 return (this_used == str_used)
314 && (memcmp(GetCStr(), str.GetCStr(), this_used) == 0);
◆ operator[]()
char & STRING::operator[] |
( |
inT32 |
index | ) |
const |
Definition at line 278 of file strngs.cpp.
281 GetHeader()->used_ = -1;
282 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 183 of file strngs.cpp.
185 if (fp->
FReadEndian(&len,
sizeof(len), 1) != 1)
return false;
186 return fp->
FRead(NULL, 1, len) == len;
int FReadEndian(void *buffer, int size, int count)
int FRead(void *buffer, int size, int count)
◆ split()
Definition at line 286 of file strngs.cpp.
289 for (
int i = 0; i < len; i++) {
290 if ((*
this)[i] == c) {
291 if (i != start_index) {
300 if (len != start_index) {
301 splited->
push_back(
STRING(GetCStr() + start_index, len - start_index));
◆ strdup()
char* STRING::strdup |
( |
| ) |
const |
|
inline |
Definition at line 79 of file strngs.h.
81 return strncpy(
new char[len], GetCStr(), len);
◆ string()
const char * STRING::string |
( |
| ) |
const |
Definition at line 198 of file strngs.cpp.
199 const STRING_HEADER* header = GetHeader();
200 if (header->used_ == 0)
◆ truncate_at()
void STRING::truncate_at |
( |
inT32 |
index | ) |
|
Definition at line 269 of file strngs.cpp.
272 char* this_cstr = ensure_cstr(index + 1);
273 this_cstr[index] =
'\0';
274 GetHeader()->used_ = index + 1;
275 assert(InvariantOk());
◆ unsigned_size()
uinT32 STRING::unsigned_size |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files:
- /home/stefan/src/github/tesseract-ocr/tesseract/ccutil/strngs.h
- /home/stefan/src/github/tesseract-ocr/tesseract/ccutil/strngs.cpp