Unicode String. More...
#include <rstring.h>
Public Member Functions | |
RString (void) | |
RString (const char *src) | |
RString (const RChar *src) | |
RString (const RChar *src, size_t len) | |
RString (const std::string &src) | |
RString (char car) | |
RString (RChar car) | |
RString (const RString &src) | |
Manipulation methods | |
void | Clear (void) |
RString | ToUpper (void) const |
RString | ToLower (void) const |
RString | Trim (void) const |
RString | Trim (const RString &str) const |
int | Find (const RChar car, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const RString &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const RString &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 RString &search, const RString &rep, bool first=false, int pos=0) |
bool | Begins (const RString &begin, bool skip=false) const |
bool | Ends (const RString &end, bool skip=false) const |
RString | Mid (size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const RString &sub, int pos) const |
void | Insert (const RString &sub, int pos, size_t del=0) |
void | Split (iRContainer< RString > &elements, const RChar car, const RChar del=RChar(0)) const |
void | GuessWords (iRContainer< RString > &elements, bool hyphen=false) const |
void | Concat (const iRContainer< RString > &elements, const RChar car=RChar(0)) |
Operators | |
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 | operator== (const RString &src) const |
bool | operator== (const char *src) const |
bool | operator== (const RChar *src) const |
bool | operator!= (const RString &src) const |
bool | operator!= (const char *src) const |
bool | operator!= (const RChar *src) const |
RString & | operator= (const RString &src) |
RString & | operator= (const RChar *src) |
RString & | operator= (const char *src) |
RString & | operator= (const std::string &src) |
RString & | operator+= (const RString &src) |
RString & | operator+= (const RChar *src) |
RString & | operator+= (const char *src) |
RString & | operator+= (const char src) |
RString & | operator+= (const RChar src) |
String to number methods | |
char | ToChar (bool &valid) const |
char | ToChar (void) const |
int | ToInt (bool &valid) const |
int | ToInt (void) const |
unsigned int | ToUInt (bool &valid) const |
unsigned int | ToUInt (void) const |
long | ToLong (bool &valid) const |
long | ToLong (void) const |
unsigned long | ToULong (bool &valid) const |
unsigned long | ToULong (void) const |
size_t | ToSizeT (bool &valid) const |
size_t | ToSizeT (void) const |
off_t | ToOffT (bool &valid) const |
off_t | ToOffT (void) const |
float | ToFloat (bool &valid) const |
float | ToFloat (void) const |
double | ToDouble (bool &valid) const |
double | ToDouble (void) const |
bool | ToBool (bool &valid, bool strict) const |
bool | ToBool (bool strict) const |
Public Member Functions inherited from BasicString< RChar, RString > | |
void | Copy (const RChar *text, size_t nb) |
RString & | operator= (const RString &src) |
RString & | 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 RString &str) |
bool | IsEmpty (void) const |
void | Clear (void) |
RString | ToUpper (void) const |
RString | ToLower (void) const |
RString | Trim (void) const |
RString | Trim (const RString &str) const |
bool | ContainOnlySpaces (void) const |
RString & | operator+= (const RString &src) |
RString & | operator+= (const RChar *src) |
int | Find (const RCharcar, int pos=0, bool CaseSensitive=true) const |
int | FindStr (const RString &str, int pos=0, bool CaseSensitive=true) const |
int | FindAnyStr (const RString &str, int pos=0, bool CaseSensitive=true) const |
void | Replace (const RCharsearch, const RCharrep, bool first=false, int pos=0) |
void | ReplaceStr (const RString &search, const RString &rep, bool first=false, int pos=0) |
const RChar & | operator[] (size_t idx) const |
RChar & | operator[] (size_t idx) |
bool | Begins (const RString &begin, bool skip=false) const |
bool | Ends (const RString &end, bool skip=false) const |
RString | Mid (size_t idx, size_t len=(size_t)-1) const |
bool | IsAt (const RString &sub, int pos) const |
void | Insert (const RString &sub, int pos, size_t del=0) |
void | Split (iRContainer< RString > &elements, const RCharcar, const RChardel) const |
void | GuessWords (iRContainer< RString > &elements, bool hyphen) const |
void | Concat (const iRContainer< RString > &elements, const RCharcar) |
size_t | HashIndex (size_t idx) const |
~BasicString (void) | |
Static Public Member Functions | |
Number to string methods | |
static RString | Number (const int nb) |
static RString | Number (const unsigned int nb) |
static RString | Number (const long nb) |
static RString | Number (const unsigned long nb) |
static RString | Number (const long long nb) |
static RString | Number (const unsigned long long nb) |
static RString | Number (const float nb, const char *format="%E") |
static RString | Number (const double nb, const char *format="%E") |
static RString | Number (const long double nb, const char *format="%LE") |
Static Public Attributes | |
static const RString | Null |
Internal methods | |
void | Copy (const RChar *text, size_t nb) |
void | Copy (const char *text, size_t nb) |
const char * | ToLatin1 (void) const |
const RChar * | ToUTF16 (void) const |
std::string | ToString (void) const |
size_t | GetLen (void) const |
size_t | GetMaxLen (void) const |
void | SetLen (size_t len) |
void | SetLen (size_t len, const RString &str) |
bool | IsEmpty (void) const |
bool | ContainOnlySpaces (void) const |
static RChar * | Latin1ToUnicode (const char *src, size_t &len, size_t &maxlen) |
char * | UnicodeToLatin1 (bool escape=false) const |
void | GenerateException (const RString &msg) const |
Methods related to containers | |
int | Compare (const RString &src) const |
int | Compare (const char *src) const |
int | Compare (const RChar *src) const |
size_t | HashCode (size_t max) const |
static int | SortOrder (const void *a, const void *b) |
static int | SortDesOrder (const void *a, const void *b) |
Additional Inherited Members | |
Protected Member Functions inherited from BasicString< RChar, RString > | |
BasicString (void) | |
BasicString (const BasicString &str) | |
BasicString (const RCharcar) | |
BasicString (const RChar *src) | |
BasicString (const RChar *src, size_t len) | |
void | Copy (void) |
Static Protected Member Functions inherited from BasicString< RChar, RString > | |
static CharBuffer * | GetDataNull (void) |
Protected Attributes inherited from BasicString< RChar, RString > | |
CharBuffer * | Data |
Static Protected Attributes inherited from BasicString< RChar, RString > | |
static CharBuffer * | DataNull |
Detailed Description
Unicode String.
This class implements a unicode string (RChar*) 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.
The RStringBuilder class is an efficient implementation to build string by adding characters.
Constructor & Destructor Documentation
RString | ( | void | ) |
Construct a empty string.
RString | ( | const char * | src | ) |
Construct a string from a C-style string.
- Parameters
-
src C-style string used as reference.
Construct a string from a Unicode array.
- Parameters
-
src Array used as reference.
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.
RString | ( | const std::string & | src | ) |
Construct a string from a string.
- Parameters
-
src String used as reference.
|
explicit |
Construct a string from a character.
- Parameters
-
car Character.
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.
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.
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.
|
staticprivate |
Transform a C string into an array of RChar. The resulting array should be destroyed by the caller of the function.
- Parameters
-
src C-style string. len Length of the string (computed by the function). maxlen Maximum length (may be updated by the function).
|
private |
Transform the RString into C string. The resulting C string should be destroyed by the caller of the function.
- Parameters
-
escape Escape invalid sequences of bytes?
|
private |
Generate an exception related to this string. Its contains:
"'string': msg".
- Parameters
-
msg Message to add.
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 RString & | 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. The string is deallocated and set to RSting::Null. If the memory must not be deallocated (for example if the string holds multiple temporary values), it is better to use RString::SetLen.
RString ToUpper | ( | void | ) | const |
Get a uppercase version of the string.
- Returns
- String.
RString ToLower | ( | void | ) | const |
Get a lowercase version of the string.
- Returns
- String.
RString 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 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 RString & | 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 RString & | 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.
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 RString & | 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 RString & | 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.
RString 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 RString & | 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 RString & | 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< RString > & | elements, |
const RChar | car, | ||
const RChar | del = RChar(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< RString > & | elements, |
bool | hyphen = false |
||
) | 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< RString > & | elements, |
const RChar | car = RChar(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 RString & | 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.
int Compare | ( | const RChar * | 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].
|
static |
Static function used to order a container of strings in ascending order.
- Parameters
-
a First string. b Second string.
- See also
- R::RContainer.
|
static |
Static function used to order a container of strings in descending order.
- Parameters
-
a First string. b Second string.
- See also
- R::RContainer.
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 operator== | ( | const RString & | 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 RChar * | src | ) | const |
Equal operator.
- Parameters
-
src String to compare with.
bool operator!= | ( | const RString & | 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.
bool operator!= | ( | const RChar * | src | ) | const |
Non-equal operator.
- Parameters
-
src String to compare with.
Assignment operator using another string.
- Parameters
-
src Source string.
Assignment operator using another string.
- Parameters
-
src Source string.
RString& operator= | ( | const char * | src | ) |
Assignment operator using a "C string".
- Parameters
-
src Source string.
RString& operator= | ( | const std::string & | src | ) |
Assignment operator using a string.
- Parameters
-
src Source string.
RString& operator+= | ( | const char * | src | ) |
Add a "C string" to the string.
- Parameters
-
src Source string.
RString& operator+= | ( | const char | src | ) |
Add a character to the string. If mutliple characters must be added, it is more efficient to use RStringBuilder.
- Parameters
-
src Character.
Add a character to the string. If mutliple characters must be added, it is more efficient to use RStringBuilder.
- Parameters
-
src Character.
|
static |
Transform an int to a string.
- Parameters
-
nb Number.
|
static |
Transform an size_t to a string.
- Parameters
-
nb Number.
|
static |
Transform a long to a string.
- Parameters
-
nb Number.
|
static |
Transform an unsigned long to a string.
- Parameters
-
nb Number.
|
static |
Transform an unsigned long long to a string.
- Parameters
-
nb Number.
|
static |
Transform an unsigned long long to a string.
- Parameters
-
nb Number.
|
static |
Transform a float to a string.
- Parameters
-
nb Number. format String representing the format.
|
static |
Transform a double to a string.
- Parameters
-
nb Number. format String representing the format.
|
static |
Transform a long double to a string.
- Parameters
-
nb Number. format String representing the format.
char ToChar | ( | bool & | valid | ) | const |
Try to transform a string into a char (as a number).
- Parameters
-
valid Variable becomes true if the conversion was done.
char ToChar | ( | void | ) | const |
Try to transform a string into a char (as a number). This version generates an exception if the string does not contain a valid number.
int ToInt | ( | bool & | valid | ) | const |
Try to transform a string into an integer.
- Parameters
-
valid Variable becomes true if the conversion was done.
int ToInt | ( | void | ) | const |
Try to transform a string into an integer. This version generates an exception if the string does not contain a valid number.
unsigned int ToUInt | ( | bool & | valid | ) | const |
Try to transform a string into an unsigned integer.
- Parameters
-
valid Variable becomes true if the conversion was done.
unsigned int ToUInt | ( | void | ) | const |
Try to transform a string into an unsigned integer. This version generates an exception if the string does not contain a valid number.
long ToLong | ( | bool & | valid | ) | const |
Try to transform a string into a long.
- Parameters
-
valid Variable becomes true if the conversion was done.
long ToLong | ( | void | ) | const |
Try to transform a string into a long. This version generates an exception if the string does not contain a valid number.
unsigned long ToULong | ( | bool & | valid | ) | const |
Try to transform a string into an unsigned long.
- Parameters
-
valid Variable becomes true if the conversion was done.
unsigned long ToULong | ( | void | ) | const |
Try to transform a string into an unsigned long. This version generates an exception if the string does not contain a valid number.
size_t ToSizeT | ( | bool & | valid | ) | const |
Try to transform a string into a size_t.
- Parameters
-
valid Variable becomes true if the conversion was done.
size_t ToSizeT | ( | void | ) | const |
Try to transform a string into a size_t. This version generates an exception if the string does not contain a valid number.
off_t ToOffT | ( | bool & | valid | ) | const |
Try to transform a string into a off_t.
- Parameters
-
valid Variable becomes true if the conversion was done.
off_t ToOffT | ( | void | ) | const |
Try to transform a string into a off_t. This version generates an exception if the string does not contain a valid number.
float ToFloat | ( | bool & | valid | ) | const |
- Try to transform a string into a float.
- Parameters
-
valid Variable becomes true if the conversion was done.
float ToFloat | ( | void | ) | const |
- Try to transform a string into a float. This version generates an exception if the string does not contain a valid number.
double ToDouble | ( | bool & | valid | ) | const |
- Try to transform a string into a double.
- Parameters
-
valid Variable becomes true if the conversion was done.
double ToDouble | ( | void | ) | const |
- Try to transform a string into a double. This version generates an exception if the string does not contain a valid number.
bool ToBool | ( | bool & | valid, |
bool | strict | ||
) | const |
Try to transform a string into a boolean value. It recognizes the strings "0", "1", "true" and "false".
- Parameters
-
valid Variable becomes true if the conversion was done. strict Define if the string recognition is strict ("true" and "false") or if upper case letters are allowed.
bool ToBool | ( | bool | strict | ) | const |
Try to transform a string into a boolean value. It recognizes the strings "0", "1", "true" and "false".
- Parameters
-
strict Define if the string recognition is strict ("true" and "false") or if upper case letters are allowed.
This version generates an exception if the string does not contain a valid boolean value.
Field Documentation
|
static |
Null string.