C String. More...
#include <rcstring.h>
Public Member Functions | |
RCString (void) | |
RCString (const char *src) | |
RCString (const char *src, size_t len) | |
RCString (const std::string &src) | |
RCString (char car) | |
RCString (const RCString &src) | |
Internal methods | |
void | Copy (const char *text, size_t nb) |
size_t | GetLen (void) const |
size_t | GetMaxLen (void) const |
void | SetLen (size_t len) |
void | SetLen (size_t len, const RCString &str) |
bool | IsEmpty (void) const |
bool | ContainOnlySpaces (void) const |
Manipulation methods | |
void | Clear (void) |
RCString | ToUpper (void) const |
RCString | ToLower (void) const |
RCString | Trim (void) const |
RCString | Trim (const RCString &str) const |
int | Find (const char car, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const RCString &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const RCString &str, int pos=0, bool CaseSensitive=true) const |
void | Replace (const char search, const char rep, bool first=false, int pos=0) |
void | ReplaceStr (const RCString &search, const RCString &rep, bool first=false, int pos=0) |
bool | Begins (const RCString &begin, bool skip=false) const |
bool | Ends (const RCString &end, bool skip=false) const |
RCString | Mid (size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const RCString &sub, int pos) const |
void | Insert (const RCString &sub, int pos, size_t del=0) |
void | Split (iRContainer< RCString > &elements, const char car, const char del=0) const |
void | GuessWords (iRContainer< RCString > &elements, bool hyphen) const |
void | Concat (const iRContainer< RCString > &elements, const char car=0) |
Methods related to containers | |
int | Compare (const RCString &src) const |
int | Compare (const char *src) const |
size_t | HashCode (size_t max) const |
Operators | |
const char * | operator() (void) const |
operator const char * (void) const | |
operator std::string () const | |
const char & | operator[] (size_t idx) const |
char & | operator[] (size_t idx) |
bool | operator== (const RCString &src) const |
bool | operator== (const char *src) const |
bool | operator!= (const RCString &src) const |
bool | operator!= (const char *src) const |
RCString & | operator= (const RCString &src) |
RCString & | operator= (const char *src) |
RCString & | operator= (const std::string &src) |
RCString & | operator+= (const RCString &src) |
RCString & | operator+= (const char *src) |
RCString & | operator+= (const char src) |
Public Member Functions inherited from BasicString< char, RCString > | |
void | Copy (const char *text, size_t nb) |
RCString & | operator= (const RCString &src) |
RCString & | operator= (const char *src) |
size_t | GetLen (void) const |
size_t | GetMaxLen (void) const |
void | SetLen (size_t len) |
void | SetLen (size_t len, const RCString &str) |
bool | IsEmpty (void) const |
void | Clear (void) |
RCString | ToUpper (void) const |
RCString | ToLower (void) const |
RCString | Trim (void) const |
RCString | Trim (const RCString &str) const |
bool | ContainOnlySpaces (void) const |
RCString & | operator+= (const RCString &src) |
RCString & | operator+= (const char *src) |
int | Find (const charcar, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const RCString &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const RCString &str, int pos=0, bool CaseSensitive=true) const |
void | Replace (const charsearch, const charrep, bool first=false, int pos=0) |
void | ReplaceStr (const RCString &search, const RCString &rep, bool first=false, int pos=0) |
const char & | operator[] (size_t idx) const |
char & | operator[] (size_t idx) |
bool | Begins (const RCString &begin, bool skip=false) const |
bool | Ends (const RCString &end, bool skip=false) const |
RCString | Mid (size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const RCString &sub, int pos) const |
void | Insert (const RCString &sub, int pos, size_t del=0) |
void | Split (iRContainer< RCString > &elements, const charcar, const chardel) const |
void | GuessWords (iRContainer< RCString > &elements, bool hyphen) const |
void | Concat (const iRContainer< RCString > &elements, const charcar) |
size_t | HashIndex (size_t idx) const |
~BasicString (void) | |
Static Public Attributes | |
static const RCString | Null |
Additional Inherited Members | |
Protected Member Functions inherited from BasicString< char, RCString > | |
BasicString (void) | |
BasicString (const BasicString &str) | |
BasicString (const charcar) | |
BasicString (const char *src) | |
BasicString (const char *src, size_t len) | |
void | Copy (void) |
Static Protected Member Functions inherited from BasicString< char, RCString > | |
static CharBuffer * | GetDataNull (void) |
Protected Attributes inherited from BasicString< char, RCString > | |
CharBuffer * | Data |
Static Protected Attributes inherited from BasicString< char, RCString > | |
static CharBuffer * | DataNull |
Detailed Description
C String.
This class implements a C string (char*) as a class. The class uses a shared approach. For example in the following code:
The strings str1 and str2 use (as long as none of them is modified) the same copy of the characters string.
Constructor & Destructor Documentation
RCString | ( | void | ) |
Construct a empty string.
RCString | ( | const char * | src | ) |
Construct a string from a C-style string.
- Parameters
-
src C-style string used as reference.
RCString | ( | const char * | src, |
size_t | len | ||
) |
Construct a string by doing a deep copy of the first characters of a C-style string.
- Parameters
-
src C string used as reference. len Length.
RCString | ( | const std::string & | src | ) |
Construct a string from a C-style string.
- Parameters
-
src C-style string used as reference.
|
explicit |
Construct a string from a character.
- Parameters
-
car Character.
Construct a string from another string.
- Parameters
-
src String used as reference.
Member Function Documentation
void Copy | ( | const char * | text, |
size_t | nb | ||
) |
Copy a certain number of characters in the string.
- Parameters
-
text Text to copy. nb Number of characters to copy.
size_t GetLen | ( | void | ) | const |
size_t GetMaxLen | ( | void | ) | const |
void SetLen | ( | size_t | len | ) |
Set the length of the string. If the length is shorter that the current one, the string is truncated. If the length is greater than the current one, the internal buffer is updated. Any new space allocated contains arbitrary data.
- Parameters
-
len Length of the string.
void SetLen | ( | size_t | len, |
const RCString & | str | ||
) |
Set the length of the string. If the length is shorter that the current one, the string is truncated. If the length is greater than the current one, the second string is used to fill the first string (eventually it is copied several times).
- Parameters
-
len Length of the string. str String used to fill.
bool IsEmpty | ( | void | ) | const |
bool ContainOnlySpaces | ( | void | ) | const |
void Clear | ( | void | ) |
Clear the content of the string.
RCString ToUpper | ( | void | ) | const |
Get a uppercase version of the string.
- Returns
- String.
RCString ToLower | ( | void | ) | const |
Get a lowercase version of the string.
- Returns
- String.
RCString Trim | ( | void | ) | const |
This function return a string by stripping whitespace (or other characters) from the beginning and end of the string.
- Returns
- String.
This function return a string by stripping a given sub-string from the beginning and end of the string.
- Parameters
-
str Sub-string to strip.
- Returns
- String.
int Find | ( | const char | car, |
int | pos = 0 , |
||
bool | CaseSensitive = true |
||
) | const |
Find the position of a given character in the string.
- Parameters
-
car Character to find. pos Position to start the search. Negative values start the search from the end. CaseSensitive Is the search case sensitive.
- Returns
- The position of the first occurrence or -1 if the character was not found.
int FindStr | ( | const RCString & | str, |
int | pos = 0 , |
||
bool | CaseSensitive = true |
||
) | const |
Find the position of a given string in the string.
- Parameters
-
str String to find. pos Position to start the search. Negative values start the search from the end. CaseSensitive Is the search case sensitive.
- Returns
- The position of the first occurrence or -1 if the character was not found.
int FindAnyStr | ( | const RCString & | str, |
int | pos = 0 , |
||
bool | CaseSensitive = true |
||
) | const |
Find the position of a character of a given set in the string.
- Parameters
-
str String to find. pos Position to start the search. Negative values start the search from the end. CaseSensitive Is the search case sensitive.
- Returns
- The position of the first occurrence or -1 if the character was not found.
void Replace | ( | const char | search, |
const char | rep, | ||
bool | first = false , |
||
int | pos = 0 |
||
) |
Replace a given character in the string.
- Parameters
-
search Character to search. rep Character that will put in. first Must it stops after the first occurrence. pos Position to start. Negative values start the search from the end.
Replace a given sub-string in the string.
- Parameters
-
search String to search. rep String that will put in. first Must it stops after the first occurrence. pos Position to start. Negative values start the search from the end.
bool Begins | ( | const RCString & | begin, |
bool | skip = false |
||
) | const |
Look if a string begins with a given sub-string.
- Parameters
-
begin Sub-string to search for. skip If true, leading spaces are skipped for the comparison.
- Returns
- true if the string begins with the sub-string.
bool Ends | ( | const RCString & | end, |
bool | skip = false |
||
) | const |
Look if a string ends with a given sub-string.
- Parameters
-
end Sub-string to search for. skip If true, ending spaces are skipped for the comparison.
- Returns
- true if the string ends with the sub-string.
RCString Mid | ( | size_t | idx, |
size_t | len = (size_t)-1 |
||
) | const |
Get a sub-string of a given string.
- Parameters
-
idx Index of the first character. len Length of the sub-string. If the length is not specified, the end of the string is copied.
- Returns
- A string containing the substring.
bool IsAt | ( | const RCString & | sub, |
int | pos | ||
) | const |
Verify if a given sub-string is at a given position.
- Parameters
-
sub Sub-string. pos Position. If negative, the sub-string is searched at a given position of the end.
- Returns
- true if the string at a given position.
void Insert | ( | const RCString & | sub, |
int | pos, | ||
size_t | del = 0 |
||
) |
Insert a sub-string at a given position of the string.
- Parameters
-
sub Sub-string to insert. pos Position. If negative, the sub-string is searched at a given position of the end. del Number of characters that will be replaced by the sub-string. If del=(size_t)-1, all the characters after pos are deleted.
void Split | ( | iRContainer< RCString > & | elements, |
const char | car, | ||
const char | del = 0 |
||
) | const |
Split the string to find all the elements separated by a given character.
- Parameters
-
elements Container that will hold the results. It is not emptied by the method. car Character used as separator. del Delimiter of an element.
void GuessWords | ( | iRContainer< RCString > & | elements, |
bool | hyphen | ||
) | const |
Try to guess the different words in a given string. In practice, it supposes that certain characters separates words (spaces, ponctuations, uppercase, etc.).
- Parameters
-
elements Container that will hold the results. It is not emptied by the method. hyphen Should a hyphen be considered as a separator?
void Concat | ( | const iRContainer< RCString > & | elements, |
const char | car = 0 |
||
) |
Concatenate a series of elements and, eventually, separated them by a given character.
- Parameters
-
elements Container of elements to concatenate. car Character used as separator.
int Compare | ( | const RCString & | src | ) | const |
Lexically compares two strings and returns an integer less than, equal to, or greater than zero if this is less than, equal to, or greater than src.
- Parameters
-
src String to compare with.
- See also
- R::RContainer.
int Compare | ( | const char * | src | ) | const |
Lexically compares two strings and returns an integer less than, equal to, or greater than zero if this is less than, equal to, or greater than src.
- Parameters
-
src String to compare with.
- See also
- R::RContainer.
size_t HashCode | ( | size_t | max | ) | const |
Compute a hash code that in the range [0,max-1]. In practice, in computes a sum based on the Unicode values the characters.
This method is R::RHashContainer to manage string.
- Parameters
-
max Maximal value.
- Returns
- a number in the range [0,max-1].
const char* operator() | ( | void | ) | const |
Return the string. The resulting array should be copied (and not destroyed) since it is an internal structure.
operator const char * | ( | void | ) | const |
Return the string. The resulting array should be copied (and not destroyed) since it is an internal structure.
operator std::string | ( | ) | const |
Get a normal C++ string representing the current string.
- Returns
- std::string.
const char& operator[] | ( | size_t | idx | ) | const |
char& operator[] | ( | size_t | idx | ) |
bool operator== | ( | const RCString & | src | ) | const |
Equal operator.
- Parameters
-
src String to compare with.
bool operator== | ( | const char * | src | ) | const |
Equal operator.
- Parameters
-
src String to compare with.
bool operator!= | ( | const RCString & | src | ) | const |
Non-equal operator.
- Parameters
-
src String to compare with.
bool operator!= | ( | const char * | src | ) | const |
Non-equal operator.
- Parameters
-
src String to compare with.
Assignment operator using another string.
- Parameters
-
src Source string.
RCString& operator= | ( | const char * | src | ) |
Assignment operator using another string.
- Parameters
-
src Source string.
RCString& operator= | ( | const std::string & | src | ) |
Assignment operator using a string.
- Parameters
-
src Source string.
RCString& operator+= | ( | const char * | src | ) |
Add another string.
- Parameters
-
src Source string.
RCString& operator+= | ( | const char | src | ) |
Add a character to the string.
- Parameters
-
src Character.
Field Documentation
|
static |
Null string.