Generic String. More...
#include <basicstring.h>
Data Structures | |
class | CharBuffer |
Shared String Buffer. | |
class | Ref |
Generic Sub-String Reference. | |
Public Member Functions | |
void | Copy (const C *text, size_t nb) |
S & | operator= (const S &src) |
S & | operator= (const C *src) |
size_t | GetLen (void) const |
size_t | GetMaxLen (void) const |
void | SetLen (size_t len) |
void | SetLen (size_t len, const S &str) |
bool | IsEmpty (void) const |
void | Clear (void) |
S | ToUpper (void) const |
S | ToLower (void) const |
S | Trim (void) const |
S | Trim (const S &str) const |
bool | ContainOnlySpaces (void) const |
S & | operator+= (const S &src) |
S & | operator+= (const C *src) |
int | Find (const C car, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const S &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const S &str, int pos=0, bool CaseSensitive=true) const |
void | Replace (const C search, const C rep, bool first=false, int pos=0) |
void | ReplaceStr (const S &search, const S &rep, bool first=false, int pos=0) |
const C & | operator[] (size_t idx) const |
C & | operator[] (size_t idx) |
bool | Begins (const S &begin, bool skip=false) const |
bool | Ends (const S &end, bool skip=false) const |
S | Mid (size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const S &sub, int pos) const |
void | Insert (const S &sub, int pos, size_t del=0) |
void | Split (iRContainer< S > &elements, const C car, const C del) const |
void | GuessWords (iRContainer< S > &elements, bool hyphen) const |
void | Concat (const iRContainer< S > &elements, const C car) |
size_t | HashIndex (size_t idx) const |
~BasicString (void) | |
Protected Member Functions | |
BasicString (void) | |
BasicString (const BasicString &str) | |
BasicString (const C car) | |
BasicString (const C *src) | |
BasicString (const C *src, size_t len) | |
void | Copy (void) |
Static Protected Member Functions | |
static CharBuffer * | GetDataNull (void) |
Protected Attributes | |
CharBuffer * | Data |
Static Protected Attributes | |
static CharBuffer * | DataNull |
Detailed Description
template<class C, class S>
class R::BasicString< C, S >
Generic String.
This class implements a generic string. It is used to instantiate RString and RCString. Its role is to centralize as much code as possible.
- Template Parameters
-
C Class representing a character. S Final class representing the string.
Constructor & Destructor Documentation
|
protected |
Construct a null string.
|
protected |
Copy constructor.
- Parameters
-
str Original string.
|
protected |
Construct a string with one character.
- Parameters
-
car Character.
|
protected |
Construct a string from an array.
- Parameters
-
src Array used as reference.
|
protected |
Construct a string by doing a deep copy of the first characters of a C-style string.
- Parameters
-
src C-style string used as reference. len Length.
~BasicString | ( | void | ) |
Destruct the string.
Member Function Documentation
|
staticprotected |
Return the pointer to the "null" buffer. If it is not created, create it.
- Returns
- Pointer to the "null" buffer.
|
protected |
Deep copy of the string if necessary, i.e. when the string points to an internal buffer referenced by other strings, make a copy of it.
void Copy | ( | const C * | text, |
size_t | nb | ||
) |
Copy a certain number of characters in the string.
- Parameters
-
text Text to copy. nb Number of characters to copy.
S& operator= | ( | const S & | src | ) |
Assignment operator using another string.
- Parameters
-
src Source string.
S& operator= | ( | const C * | src | ) |
Assignment operator using another string.
- Parameters
-
src Source string.
size_t GetLen | ( | void | ) | const |
Return the length of the string.
size_t GetMaxLen | ( | void | ) | const |
Return the maximal length of the string.
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 S & | 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 |
Look if the string is empty.
- Returns
- true if the length is null, false else.
void Clear | ( | void | ) |
Clear the content of the string.
S ToUpper | ( | void | ) | const |
Get a uppercase version of the string.
- Returns
- String.
S ToLower | ( | void | ) | const |
Get a lowercase version of the string.
- Returns
- String.
S Trim | ( | void | ) | const |
This function return a string by stripping whitespace (or other characters) from the beginning and end of the string.
- Returns
- String.
S Trim | ( | const S & | str | ) | const |
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.
bool ContainOnlySpaces | ( | void | ) | const |
Look if the string contains only spaces.
S& operator+= | ( | const S & | src | ) |
Add another string.
- Parameters
-
src Source string.
S& operator+= | ( | const C * | src | ) |
Add a string to the string.
- Parameters
-
src Source string.
int Find | ( | const C | 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 S & | 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 S & | 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 C | search, |
const C | 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.
void ReplaceStr | ( | const S & | search, |
const S & | rep, | ||
bool | first = false , |
||
int | pos = 0 |
||
) |
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.
const C& operator[] | ( | size_t | idx | ) | const |
This function returns the character at a given position in the string. (Read only).
- Parameters
-
idx Position of the character.
C& operator[] | ( | size_t | idx | ) |
This function returns the character at a given position in the string.
- Parameters
-
idx Position of the character.
bool Begins | ( | const S & | 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 S & | 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.
S 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 S & | 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 S & | 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< S > & | elements, |
const C | car, | ||
const C | del | ||
) | 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< S > & | 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< S > & | elements, |
const C | car | ||
) |
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.
size_t HashIndex | ( | size_t | idx | ) | const |
Return a number between 0 and 26 according to the character at position idx in the string.
- Remarks
- Supported values for idx are 1 and 2.
- Parameters
-
idx Index of hash asked.
- See also
- R::RHashContainer and R::RDblHashContainer.
Field Documentation
|
staticprotected |
Pointer to the buffer representing the null string.
|
protected |
Pointer to the buffer of the string.