ALBA
|
#include <albaString.h>
Public Member Functions | |
const albaID | Length () const |
void | Copy (const char *src) |
void | NCopy (const char *src, int n) |
void | Erase (int start, int end=-1) |
char * | Duplicate () const |
int | Compare (const char *str) const |
bool | Equals (const char *str) const |
bool | StartsWith (const char *str) const |
bool | EndsWith (const char *str) const |
albaString & | Append (const char *str) |
int | FindChr (const int c) const |
void | Replace (char from, char to) |
int | FindLastChr (const int c) const |
int | FindFirst (const char *str) const |
int | FindLast (const char *str) const |
const char * | BaseName () const |
void | ExtractPathName () |
void | SetPathName (const char *str) |
void | SetPathName (albaString *str) |
char * | ParsePathName () |
char * | ParsePathName (albaString *str) |
void | ForceDuplicate () |
const char * | GetCStr () const |
char * | GetNonConstCStr () |
int | GetSize () const |
int | SetMaxLength (albaID len) |
bool | IsEmpty () const |
albaString & | Set (const char *a, bool release=false) |
void | SetCStr (char *a, bool release=false) |
void | Printf (const char *format,...) |
void | NPrintf (unsigned long size, const char *format,...) |
operator const char * () const | |
char & | operator[] (const int i) |
const char | operator[] (const int i) const |
const bool | operator== (const char *src) const |
const bool | operator!= (const char *src) const |
const bool | operator< (const char *a) const |
const bool | operator> (const char *a) const |
const bool | operator<= (const char *a) const |
const bool | operator>= (const char *a) const |
albaString & | operator<< (const char *a) |
void | operator<< (std::ostream &os) |
void | operator>> (std::istream &os) |
albaString & | operator<< (int d) |
albaString & | operator<< (long d) |
albaString & | operator<< (float d) |
albaString & | operator<< (double d) |
albaString & | operator<< (albaMatrix d) |
albaString & | operator<< (albaString *s) |
albaString & | operator+= (const char *s) |
albaString (const albaString &src) | |
albaString (const char *src) | |
albaString (const double &num) | |
albaString & | operator= (const albaString &mat) |
albaString & | operator= (const char *src) |
albaString & | operator= (const double &num) |
albaString () | |
~albaString () | |
Static Public Member Functions | |
static albaID | Length (const char *str) |
static void | Copy (char *dest, const char *src) |
static char * | Duplicate (const char *str) |
static void | Duplicate (char *&store, const char *src, bool release=true) |
static int | Compare (const char *str1, const char *str2) |
static bool | Equals (const char *str1, const char *str2) |
static bool | StartsWith (const char *str1, const char *str2) |
static bool | EndsWith (const char *str1, const char *str2) |
static char * | Append (const char *str1, const char *str2) |
static const char * | BaseName (const char *filename) |
static char * | ParsePathName (char *str) |
static bool | IsEmpty (const char *str) |
static wxString | Format (const char *format,...) |
Protected Member Functions | |
int | SetSize (albaID size) |
void | Initialize () |
Protected Attributes | |
char * | m_CStr |
const char * | m_ConstCStr |
albaID | m_Size |
albaString - performs common string operations on c-strings.
albaString is an implementation of string which operates on a traditional c-string internally stored. At each moment this string can be retrieved with GetCStr(). The memory of this m_CStr is automatically garbaged. Originally based on vtkString. BEWARE, when albaString is assigned with Set() to a "const char *" this is simply referenced and not copied, this implies very high performance but can cause invalid memory access: e.g. in case the "const char *" is a function argument. When a albaString storing a reference to a const char * is modified the string is automatically copied into a new memory. This string can be passed as argument wherever a const char * is expected.
Definition at line 42 of file albaString.h.
albaString::albaString | ( | const albaString & | src | ) |
albaString::albaString | ( | const char * | src | ) |
albaString::albaString | ( | const double & | num | ) |
albaString::albaString | ( | ) |
albaString::~albaString | ( | ) |
|
static |
This static method returns the size of c-string.
If the string is empty, it returns 0. It can handle null pointers.
const albaID albaString::Length | ( | ) | const |
This method returns the size of this string.
|
static |
static method to copy c-string to the another c-string.
void albaString::Copy | ( | const char * | src | ) |
Copy a c-string to this string.
void albaString::NCopy | ( | const char * | src, |
int | n | ||
) |
Copy N characters of another string to this string.
void albaString::Erase | ( | int | start, |
int | end = -1 |
||
) |
Erase characters from start position to end position.
If end is not specified erase to the end of the string.
|
static |
This method makes a duplicate of a c-string similar to C function strdup but it uses new to create new string, so you can use delete to remove it.
It returns 0 if the input is empty. This function automatically release old pointed data (if not specified differently)
|
static |
This method makes a duplicate of the string similar to C function strdup but it uses new to create new string, so you can use delete to remove it.
It returns 0 if the input is empty. The new string pointer is copied in the destination pointer. If this was already != NULL, the corresponding memory is released. This is useful to automatically manage garbage collection but beware to not provide an uninitialized pointer variable. Beware memory releasing must be performed by consumer
char * albaString::Duplicate | ( | ) | const |
Duplicate the string stored inside this object.
Beware memory releasing must be performed by consumer
|
static |
This static method compare two strings.
It is similar to strcmp, but it can handle null pointers. return 0 if str1 == str2, -1 if str1<str2, 1 if str1>str2
int albaString::Compare | ( | const char * | str | ) | const |
This method compare the given c-string with the one stored inside this object.
It is similar to strcmp, but it can handle null pointers. Return 0 if str equal this, -1 if str > this, 1 if str < this
|
inlinestatic |
This static method compare two strings.
It is similar to strcmp, but it can handle null pointers. Also it only returns C style true or false versus compare which returns also which one is greater.
Definition at line 106 of file albaString.h.
bool albaString::Equals | ( | const char * | str | ) | const |
This method compare the given c-string with the one stored inside this object.
It is similar to strcmp, but it can handle null pointers. Also it only returns C style true or false versus compare which returns also which one is greater.
|
static |
Static method to check if the first string starts with the second one.
bool albaString::StartsWith | ( | const char * | str | ) | const |
Check if this string starts with the given one.
|
static |
Static method to check if the first string ends with the second one.
bool albaString::EndsWith | ( | const char * | str | ) | const |
Check if this string ends with the given one.
|
static |
Append two strings and produce a new one.
The consumer must delete the resulting string. The method returns 0 if inputs are empty or if there was an error.
albaString & albaString::Append | ( | const char * | str | ) |
Append a new string to this string.
int albaString::FindChr | ( | const int | c | ) | const |
Scan the string for the first occurrence of the character.
void albaString::Replace | ( | char | from, |
char | to | ||
) |
Replace each caracter from with to.
int albaString::FindLastChr | ( | const int | c | ) | const |
Scan the string for the first occurrence of the character.
int albaString::FindFirst | ( | const char * | str | ) | const |
Find first occurrence of a substring.
int albaString::FindLast | ( | const char * | str | ) | const |
Find last occurrence of a substring.
|
static |
Extract the base name of a filename string.
const char * albaString::BaseName | ( | ) | const |
void albaString::ExtractPathName | ( | ) |
Extract the pathname from a filename string.
Result is written inplace.
void albaString::SetPathName | ( | const char * | str | ) |
parse the given string to substitute each (back)slash character with the right pathname separator.
void albaString::SetPathName | ( | albaString * | str | ) |
char * albaString::ParsePathName | ( | ) |
parse the given string to substitute each (back)slash character with the right pathname separator.
|
static |
char * albaString::ParsePathName | ( | albaString * | str | ) |
void albaString::ForceDuplicate | ( | ) |
Force the string to create an internal duplication in place of reference to const char.
const char * albaString::GetCStr | ( | ) | const |
Return the pointer to the internal c-string.
char * albaString::GetNonConstCStr | ( | ) |
Return the pointer to the internal c-string, but first force string the internal copy.
|
inline |
return the real memory size allocated for the internal c-string
Definition at line 180 of file albaString.h.
int albaString::SetMaxLength | ( | albaID | len | ) |
Pre-Allocate space for the internal c-string.
The memory size is is given in terms of string length, that is one more character for the trailing '\0' is allocated. Previous data is retained. Memory is reallocated only if requested size is > of existing one. All the albaString methods resize this memory when necessary, but to improve performance it's possible to preallocate an enough large memory to store the data preventing reallocation of memory. Return 0 if OK, -1 in case of relocation problems
|
inlinestatic |
return true if empty
Definition at line 194 of file albaString.h.
|
inline |
return true if empty
Definition at line 196 of file albaString.h.
References IsEmpty().
Referenced by IsEmpty().
albaString & albaString::Set | ( | const char * | a, |
bool | release = false |
||
) |
Set the internal pointer to a give pointer.
Second parameter allow to force the release of the memory
Referenced by albaCString::albaCString().
void albaString::SetCStr | ( | char * | a, |
bool | release = false |
||
) |
this can be used only with non constant c-string
void albaString::Printf | ( | const char * | format, |
... | |||
) |
Format given arguments according to format string.
Format string format is that of vsprintf function
|
static |
void albaString::NPrintf | ( | unsigned long | size, |
const char * | format, | ||
... | |||
) |
like Printf but faster (you can specify output string size)
|
inline |
this allows to convert a albaString to const char *.
Definition at line 216 of file albaString.h.
char & albaString::operator[] | ( | const int | i | ) |
Direct access to single string elements for writing.
This operator forces memory copy in case of internal const char reference.
const char albaString::operator[] | ( | const int | i | ) | const |
direct access to string single elements for reading
const bool albaString::operator== | ( | const char * | src | ) | const |
const bool albaString::operator!= | ( | const char * | src | ) | const |
const bool albaString::operator< | ( | const char * | a | ) | const |
const bool albaString::operator> | ( | const char * | a | ) | const |
const bool albaString::operator<= | ( | const char * | a | ) | const |
const bool albaString::operator>= | ( | const char * | a | ) | const |
|
inline |
Definition at line 236 of file albaString.h.
void albaString::operator<< | ( | std::ostream & | os | ) |
void albaString::operator>> | ( | std::istream & | os | ) |
albaString & albaString::operator<< | ( | int | d | ) |
albaString & albaString::operator<< | ( | long | d | ) |
albaString & albaString::operator<< | ( | float | d | ) |
albaString & albaString::operator<< | ( | double | d | ) |
albaString & albaString::operator<< | ( | albaMatrix | d | ) |
Put inside string a albaMatrix in row order example: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 -> "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1".
albaString & albaString::operator<< | ( | albaString * | s | ) |
albaString & albaString::operator+= | ( | const char * | s | ) |
albaString & albaString::operator= | ( | const albaString & | mat | ) |
albaString & albaString::operator= | ( | const char * | src | ) |
albaString & albaString::operator= | ( | const double & | num | ) |
|
protected |
Allocate space for the internal c-string.
|
inlineprotected |
Definition at line 279 of file albaString.h.
|
protected |
Definition at line 281 of file albaString.h.
|
protected |
Definition at line 282 of file albaString.h.
|
protected |
Definition at line 283 of file albaString.h.