edelib
2.1.0
|
A (relatively simple) string implementation. More...
#include <edelib/String.h>
Public Member Functions | |
String () | |
String (const char *str) | |
String (const String &str) | |
~String () | |
String & | assign (const char *str, size_type len) |
String & | assign (const char *str) |
String & | assign (const String &str) |
String & | append (const char *str, size_type len) |
String & | append (const char *str) |
String & | append (const String &str) |
String & | append (size_type num, const char &ch) |
void | reserve (size_type len) |
void | swap (String &from) |
String | substr (size_type index, size_type num=npos) const |
size_type | find (const char *str, size_type offset) const |
size_type | find (char ch, size_type offset) const |
size_type | find (const char *str) const |
void | clear (void) |
void | printf (const char *fmt,...) |
void | trim_left (void) |
void | trim_right (void) |
void | trim (void) |
const char * | c_str (void) |
const char * | c_str (void) const |
const char * | data (void) const |
size_type | length (void) const |
size_type | capacity (void) const |
bool | empty (void) const |
String & | replace (char c1, char c2) |
char & | operator[] (size_type index) |
char | operator[] (size_type index) const |
String & | operator= (const char *str) |
String & | operator= (const String &str) |
String & | operator+= (const char *str) |
String & | operator+= (const String &str) |
String & | operator+= (const char &ch) |
Static Public Attributes | |
static const size_type | npos |
Related Functions | |
(Note that these are not member functions.) | |
String | operator+ (const String &s1, const String &s2) |
String | operator+ (const char *s1, const String &s2) |
String | operator+ (const String &s1, const char *s2) |
bool | operator== (const String &str1, const char *str2) |
bool | operator!= (const String &str1, const char *str2) |
bool | operator> (const String &str1, const char *str2) |
bool | operator>= (const String &str1, const char *str2) |
bool | operator< (const String &str1, const char *str2) |
bool | operator<= (const String &str1, const char *str2) |
bool | operator== (const char *str1, const String &str2) |
bool | operator!= (const char *str1, const String &str2) |
bool | operator> (const char *str1, const String &str2) |
bool | operator>= (const char *str1, const String &str2) |
bool | operator< (const char *str1, const String &str2) |
bool | operator<= (const char *str1, const String &str2) |
bool | operator== (const String &str1, const String &str2) |
bool | operator!= (const String &str1, const String &str2) |
bool | operator> (const String &str1, const String &str2) |
bool | operator>= (const String &str1, const String &str2) |
bool | operator< (const String &str1, const String &str2) |
bool | operator<= (const String &str1, const String &str2) |
A (relatively simple) string implementation.
This implementation tries to be compatible with std::string implementation, althought it does not implement all gory details from std::string. There are few reasons why this class exists:
This class does not provide find_xxx(), insert() and erase methods and iterators.
Some methods, like printf() does not exist in std::string. Also, the behaviour of capacity() differs from std::string like:
If you are not familiar with std::string, following things with this class can be done:
String | ( | ) |
Create empty string object
String | ( | const char * | str | ) |
Create a new string with copy of pointer to characters
str | a pointer to c-like string (it should not be NULL) |
Create a new string with copy of another string
str | is object of type String |
~String | ( | ) |
Clears all internal data. All possible external pointers to internal buffer will be invalidated
String& append | ( | const char * | str, |
size_type | len | ||
) |
Appends content of c-like string, with given length to the end of current string
str | a pointer to c-like string (it should not be NULL) |
len | a number of character that will be appended |
String& append | ( | const char * | str | ) |
Appends content of c-like string with it's full length to the end of current string
str | a pointer to c-like string (it should not be NULL) |
String& append | ( | size_type | num, |
const char & | ch | ||
) |
Appends given character num times at the end of character string
num | is number of given character |
ch | is character to append |
String& assign | ( | const char * | str, |
size_type | len | ||
) |
Assign content of c-like string, with given size. This method will destroy the previous content of the string
str | a pointer to c-like string (it should not be NULL) |
len | a number of character that will be assigned |
String& assign | ( | const char * | str | ) |
Assign content of c-like string with it's full length.
str | a pointer to c-like string (it should not be NULL) |
|
inline |
Return data formated as c-like string
Can be used as input for C functions, like:
Referenced by TiXmlPrinter::CStr(), TiXmlPrinter::Indent(), TiXmlPrinter::LineBreak(), String::operator!=(), String::operator<(), String::operator<=(), String::operator==(), String::operator>(), and String::operator>=().
|
inline |
Return data formated as c-like string
|
inline |
Retrun size of internal buffer
void clear | ( | void | ) |
Clear all elements of current string
|
inline |
Retrun pointer to internal buffer
Do not use this function as input for C functions.
|
inline |
Checks if string is empty
size_type find | ( | const char * | str, |
size_type | offset | ||
) | const |
Returns starting position of str starting at offset. If str is not found, String::npos will be returned
str | is string we are looking for |
offset | position to start looking from |
size_type find | ( | char | ch, |
size_type | offset | ||
) | const |
Returns starting position of given character starting at the given offset. If character is not found, String::npos will be returned
ch | character we are looking for |
offset | position to start looking from |
size_type find | ( | const char * | str | ) | const |
Returns start of given string. Behaves same as find(str, 0)
|
inline |
Retrun size of character data
Referenced by String::operator==(), TiXmlPrinter::Size(), and edelib::stringtok().
String& operator+= | ( | const char * | str | ) |
Same as append(str)
String& operator+= | ( | const char & | ch | ) |
Same as append(1, ch)
String& operator= | ( | const char * | str | ) |
Same as assign(str)
char& operator[] | ( | size_type | index | ) |
Returns character at given index
char operator[] | ( | size_type | index | ) | const |
Returns character at given index
void printf | ( | const char * | fmt, |
... | |||
) |
Assign data in printf form. All previous content will be deleted.
String& replace | ( | char | c1, |
char | c2 | ||
) |
Replace every occurence of c1 with the c2
c1 | is character that will be replaced |
c2 | is character used for replacement |
void reserve | ( | size_type | len | ) |
Set size of internal buffer
len | is size we want |
Returns a substring of the current string starting at the index with num characters long. If num is not specified, returned will be remain data starting from index
index | starting position for substring |
num | ending position for substring |
Referenced by edelib::stringtok().
void swap | ( | String & | from | ) |
Exchange the elements of current string with given
from | is replacement target |
void trim | ( | void | ) |
Remove starting and ending spaces
void trim_left | ( | void | ) |
Remove starting spaces
void trim_right | ( | void | ) |
Remove ending spaces
|
related |
Check if String and cstring are not equal
References String::c_str().
|
related |
Check if cstring and String are not equal
References String::c_str().
Check if two String's are not equal
References String::c_str().
|
related |
Check if String is less than cstring
References String::c_str().
|
related |
Check if cstring is less than String
References String::c_str().
Check if first String is less than the second
References String::c_str().
|
related |
Check if String is less or equal to cstring
References String::c_str().
|
related |
Check if cstring is less or equal to the String
References String::c_str().
Check if first String is less or equal than the second
References String::c_str().
|
related |
Check if String and cstring are equal
References String::c_str().
|
related |
Check if cstring and String are equal
References String::c_str().
Check if two String's are equal
References String::c_str(), and String::length().
|
related |
Check if String is larger than cstring
References String::c_str().
|
related |
Check if cstring is larger than String
References String::c_str().
Check if first String is larger than the second
References String::c_str().
|
related |
Check if String is larger or equal to the cstring
References String::c_str().
|
related |
Check if cstring is larger or equal to String
References String::c_str().
Check if first String is larger or equal than the second
References String::c_str().
|
static |
This will be returned when find() method fails. If is meant to be used in form: