Temporary String. More...
#include <rtmpstring.h>
Public Member Functions | |
RTmpString (void) | |
RTmpString (const RTmpString &str) | |
RTmpString (const RChar car) | |
RTmpString (const char *src) | |
RTmpString (const RChar *src) | |
RTmpString (const RChar *src, size_t len) | |
void | Copy (const RChar *text, size_t nb) |
const char * | ToLatin1 (void) const |
const RChar * | ToUTF16 (void) const |
std::string | ToString (void) const |
RTmpString & | operator= (const RTmpString &src) |
RTmpString & | operator= (const char *src) |
RTmpString & | operator= (const RChar *src) |
size_t | GetLen (void) const |
size_t | GetMaxLen (void) const |
void | SetLen (size_t len) |
void | SetLen (size_t len, const RChar *str) |
bool | IsEmpty (void) const |
void | Clear (void) |
void | ToUpper (void) const |
void | ToLower (void) const |
void | Trim (void) const |
void | Trim (const RChar *str) const |
bool | ContainOnlySpaces (void) const |
RTmpString & | operator+= (const RTmpString &src) |
RTmpString & | operator+= (const char *src) |
RTmpString & | operator+= (const RChar *src) |
int | Find (const RChar car, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const RTmpString &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const RTmpString &str, int pos=0, bool CaseSensitive=true) const |
void | Replace (const RChar search, const RChar rep, bool first=false, int pos=0) |
void | ReplaceStr (const RTmpString &search, const RTmpString &rep, bool first=false, int pos=0) |
RChar * | operator() (void) |
const RChar * | operator() (void) const |
operator const char * (void) const | |
operator std::string () const | |
const RChar & | operator[] (size_t idx) const |
RChar & | operator[] (size_t idx) |
bool | Begins (const RTmpString &begin, bool skip=false, bool CaseSensitive=true) const |
bool | Ends (const RTmpString &end, bool skip=false, bool CaseSensitive=true) const |
void | Mid (RTmpString &to, size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const RTmpString &sub, int pos, bool CaseSensitive=true) const |
void | Insert (const RTmpString &sub, int pos, size_t del=0) |
void | Split (RContainer< RTmpString, true, false > &elements, const RChar car, const RChar del) const |
template<bool a, bool o> | |
void | Concat (const RContainer< RTmpString, a, o > &elements, const RChar car) |
size_t | HashIndex (size_t idx) const |
~RTmpString (void) | |
Private Member Functions | |
void | UnicodeToLatin1 (void) const |
Private Attributes | |
RChar | Text [MaxLen+1] |
size_t | Len |
char | Latin1 [MaxLen+1] |
Detailed Description
template<size_t MaxLen>
class R::RTmpString< MaxLen >
Temporary String.
This class implements a temporary string of Unicode characters (RChar). The template proposes to instantiate strings of a given size. Contrary to RString, RTmpString does not allocate the text on the heap but on the stack. It should therefore be optimized for temporary string (as the name suggests) where a maximum size is known.
- Warning
- Some compilers generate the codes for each instantiation. It is therefore a good practice to limit the number of instantiations. Moreover, since these strings occupy the stack, using too many of them with large sizes can lead to a problem (in particular for recursive functions).
- Template Parameters
-
MaxLen Maximum size of the string.
Constructor & Destructor Documentation
RTmpString | ( | void | ) |
Construct a null string.
RTmpString | ( | const RTmpString< MaxLen > & | str | ) |
Copy constructor.
- Parameters
-
str Original string.
RTmpString | ( | const RChar | car | ) |
Construct a string with one character.
- Parameters
-
car Character.
RTmpString | ( | const char * | src | ) |
Construct a string from an array.
- Parameters
-
src Array used as reference.
RTmpString | ( | const RChar * | src | ) |
Construct a string from an array.
- Parameters
-
src Array used as reference.
RTmpString | ( | const RChar * | src, |
size_t | len | ||
) |
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.
~RTmpString | ( | void | ) |
Destruct the string.
Member Function Documentation
void Copy | ( | const RChar * | text, |
size_t | nb | ||
) |
Copy a certain number of characters in the string.
- Parameters
-
text Text to copy. nb Number of characters to copy.
|
private |
Transform the RString into C string. The resulting C string should be destroyed by the caller of the function.
const char* ToLatin1 | ( | void | ) | const |
Transform the string into a "C String" in Latin1 encoding. The resulting array should be copied (and not destroyed) since it is an internal structure.
- Returns
- C String
const RChar* ToUTF16 | ( | void | ) | const |
Return the string in UTF16.
std::string ToString | ( | void | ) | const |
Get a normal C++ string representing the current string.
- Returns
- std::string.
RTmpString& operator= | ( | const RTmpString< MaxLen > & | src | ) |
Assignment operator using another string.
- Parameters
-
src Source string.
RTmpString& operator= | ( | const char * | src | ) |
Assignment operator using another string.
- Parameters
-
src Source string.
RTmpString& operator= | ( | const RChar * | 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 RChar * | 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.
void ToUpper | ( | void | ) | const |
Get a uppercase version of the string.
- Returns
- String.
void ToLower | ( | void | ) | const |
Get a lowercase version of the string.
- Returns
- String.
void Trim | ( | void | ) | const |
This function return a string by stripping whitespace (or other characters) from the beginning and end of the string.
- Returns
- String.
void Trim | ( | const RChar * | 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.
RTmpString& operator+= | ( | const RTmpString< MaxLen > & | src | ) |
Add another string.
- Parameters
-
src Source string.
RTmpString& operator+= | ( | const char * | src | ) |
Add a string to the string.
- Parameters
-
src Source string.
RTmpString& operator+= | ( | const RChar * | src | ) |
Add a string to the string.
- Parameters
-
src Source string.
int Find | ( | const RChar | 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 RTmpString< MaxLen > & | 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 RTmpString< MaxLen > & | 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.
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 RTmpString< MaxLen > & | search, |
const RTmpString< MaxLen > & | 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.
RChar* operator() | ( | void | ) |
Return the string. The resulting array should be copied (and not destroyed) since it is an internal structure.
const RChar* 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 RChar& 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.
RChar& 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 RTmpString< MaxLen > & | begin, |
bool | skip = false , |
||
bool | CaseSensitive = true |
||
) | 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. CaseSensitive Is the search case sensitive.
- Returns
- true if the string begins with the sub-string.
bool Ends | ( | const RTmpString< MaxLen > & | end, |
bool | skip = false , |
||
bool | CaseSensitive = true |
||
) | 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. CaseSensitive Is the search case sensitive.
- Returns
- true if the string ends with the sub-string.
void Mid | ( | RTmpString< MaxLen > & | to, |
size_t | idx, | ||
size_t | len = (size_t)-1 |
||
) | const |
Extract a sub-string of a given string.
- Parameters
-
to The sub-string that will be extracted. 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 RTmpString< MaxLen > & | sub, |
int | pos, | ||
bool | CaseSensitive = true |
||
) | 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. CaseSensitive Is the search case sensitive.
- Returns
- true if the string at a given position.
void Insert | ( | const RTmpString< MaxLen > & | 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 | ( | RContainer< RTmpString< MaxLen >, true, false > & | elements, |
const RChar | car, | ||
const RChar | 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 Concat | ( | const RContainer< RTmpString< MaxLen >, a, o > & | elements, |
const RChar | 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
|
private |
Text.
|
private |
Actual length.
|
private |
Latin1 version of the string.