| Home | Index | universal Index | gsp Index | Examples | Tutorial |
#include "universal__String.h"
This class offers a set of low and high-level operations for safe and convenient handling of character strings, including commonly used operators (==,=. More...
Public Functions | ||
| String | ( ) | |
| String | ( const char * lpszSource , long iLen = -1 ) | |
| String | ( const String & rStr ) | |
| String | ( char c ) | |
| String | ( unsigned char c ) | |
| String | ( int iValue , const char * lpszFormat = 0 ) | |
| String | ( unsigned int uValue , const char * lpszFormat = 0 ) | |
| String | ( long iValue , const char * lpszFormat = 0 ) | |
| String | ( unsigned long uValue , const char * lpszFormat = 0 ) | |
| String | ( float fSource , const char * lpszFormat = 0 ) | |
| String | ( double dSource , const char * lpszFormat = 0 ) | |
| operator const char * | ( ) const | |
| ~String | ( ) | |
| append | ( const char * pzStr ) |
| append | ( const String & rStr ) |
| append | ( char c ) |
| append | ( unsigned char c ) |
| append | ( unsigned int uN ) |
| append | ( int iN ) |
| append | ( unsigned long uN ) |
| append | ( long iN ) |
| append | ( float fN ) |
| append | ( double dN ) |
| capacity | ( void ) const |
| charAt | ( unsigned long uIndex ) const |
| charAt | ( long iIndex ) const |
| charAt | ( unsigned long uIndex ) |
| charAt | ( long iIndex ) |
| consistsOfChars | ( const char * chararray ) const |
| empty | ( ) const |
| endsWith | ( const String & rStr ) const |
| equals | ( const char * pszStr ) const |
| equals | ( const String & rStr ) const |
| equalsIgnoreCase | ( const char * pszStr ) const |
| equalsIgnoreCase | ( const String & rStr ) const |
| erase | ( unsigned long start = 0 , int nb = -1 ) |
| eraseRange | ( unsigned long start , long end = -1 ) |
| escapeSequence | ( ) |
| fill | ( unsigned long uLen , char fillc = ' ' , unsigned long uFrom = 0xFFFFFFFF ) |
| formatColumn | ( unsigned long uColWidth ) |
| grep | ( const String & c_sSearch ) | |
| hashCode | ( ) const |
| indexOf | ( int cha , unsigned long uStartFrom = 0 ) const |
| indexOf | ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const |
| insert | ( unsigned long uOffset , const String & rStr ) |
| insert | ( unsigned long uOffset , char c ) |
| isCaseLess | ( ) const |
| isUINT | ( ) const |
| justify | ( unsigned long uColWidth ) |
| lastIndexOf | ( int cha , unsigned long uStartFrom = 0 ) const |
| lastIndexOf | ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const |
| left | ( unsigned int uLength ) const | |
| length | ( void ) const |
| matchesPattern | ( const String & c_sPattern ) const |
| matchesPattern | ( const StringList & c_slPatternList ) const |
| mid | ( unsigned int uPosition , unsigned int uLength ) const | |
| nl | ( const String & rStr ) |
| operator () | ( unsigned int uPosition , unsigned int uLength ) const | |
| operator [] | ( int iIndex ) |
| operator [] | ( long iIndex ) |
| operator [] | ( unsigned int uIndex ) |
| operator [] | ( unsigned long uIndex ) |
| operator [] | ( long iIndex ) const |
| operator [] | ( int iIndex ) const |
| operator [] | ( unsigned int uIndex ) const |
| operator [] | ( unsigned long uIndex ) const |
| operator = | ( char c ) |
| operator = | ( unsigned char c ) |
| operator = | ( const char * pszSource ) |
| operator = | ( const String & rstrSource ) |
| operator = | ( int iSource ) |
| operator = | ( unsigned int uSource ) |
| operator = | ( long lSource ) |
| operator = | ( unsigned long uSource ) |
| operator = | ( short sSource ) |
| operator = | ( unsigned short usSource ) |
| operator = | ( float fSource ) |
| operator = | ( double dSource ) |
| operator += | ( const char * pszSource ) |
| operator += | ( const String & rstrSource ) |
| operator += | ( char c ) |
| operator += | ( unsigned char c ) |
| operator += | ( int iAdd ) |
| operator += | ( unsigned int iAdd ) |
| operator += | ( long lAdd ) |
| operator += | ( unsigned long uAdd ) |
| operator += | ( float fAdd ) |
| operator += | ( double dAdd ) |
| operator + | ( const char * pszSource ) const | |
| operator + | ( const String & rstrSource ) const | |
| operator + | ( char c ) const | |
| operator + | ( unsigned char c ) const | |
| operator + | ( int iSource ) const | |
| operator + | ( unsigned int uSource ) const | |
| operator + | ( long lSource ) const | |
| operator + | ( unsigned long uSource ) const | |
| operator + | ( float fSource ) const | |
| operator + | ( double dSource ) const | |
| operator == | ( const char * pszStr ) const |
| operator == | ( const String & rStr ) const |
| operator == | ( unsigned char c ) const |
| operator == | ( char c ) const |
| operator == | ( int iSource ) const |
| operator == | ( unsigned int uSource ) const |
| operator == | ( long lSource ) const |
| operator == | ( unsigned long uSource ) const |
| operator == | ( float fSource ) const |
| operator == | ( double dSource ) const |
| operator != | ( const char * pszStr ) const |
| operator != | ( const String & rStr ) const |
| operator != | ( unsigned char c ) const |
| operator != | ( char c ) const |
| operator != | ( int iSource ) const |
| operator != | ( unsigned int uSource ) const |
| operator != | ( long lSource ) const |
| operator != | ( unsigned long uSource ) const |
| operator != | ( float fSource ) const |
| operator != | ( double dSource ) const |
| regionMatches | ( bool ignoreCase , unsigned long utoffset , const String rStr , unsigned long uooffset , unsigned long uLen ) const |
| replace | ( char cOld , char cNew , bool bAll = false ) |
| replace | ( char cOld , const char * pszNew , bool bAll = false ) |
| replace | ( const char * pszOld , char cNew , bool bAll = false ) |
| replace | ( const char * pszOld , const char * pszNew , bool bAll = false ) |
| reverse | ( ) |
| right | ( unsigned int uLength ) const | |
| rubout | ( const String & c_s , char cEraseChar = ' ' , unsigned long uFrom = 0 ) |
| set | ( const char * pszValue ) |
| setCaseLess | ( bool bCase = true ) |
| setEmpty | ( ) |
| shiftLeft | ( unsigned long uHowMuch = 1 ) |
| shiftRight | ( unsigned long uHowMuch = 1 , char rightc = ' ' ) |
| split | ( const String & c_sSep , bool bTrimItems = true ) const |
| startsWith | ( const String & rStr ) const |
| str | ( ) const |
| substring | ( unsigned int uPosition , unsigned int uPositionEnd ) const | |
| toLowerCase | ( void ) |
| toString | ( ) const | |
| toUpperCase | ( void ) |
| token | ( char cSep ) | |
| token | ( const String & rstrSep ) | |
| trim | ( char c = ' ' , bool bLessToo = false ) |
| trimLeft | ( char c = ' ' , bool bLessToo = false ) |
| trimRight | ( char c = ' ' , bool bLessToo = false ) |
| untabify | ( unsigned short usTabLen = 8 ) |
| untabifyWithCursor | ( unsigned long & uPos , unsigned short usTabLen = 8 ) |
Public Static Functions | ||
| formatOptionHelp | ( String sOpt , String sHelpText , unsigned long uOptColWidth = 30 , unsigned long uHelpColWidth = 40 , unsigned long uOptNbIndent = 2 ) | |
| toDouble | ( const String & rStr , double & rdTarget ) |
| toFloat | ( const String & rStr , float & rfTarget ) |
| toLong | ( const String & rStr , long & rlTarget ) |
| toString | ( long lSource , String & rRes ) |
| toString | ( unsigned long uSource , String & rRes ) |
| toString | ( double rdSource , String & rRes , int iPrecision = 10 ) |
| toUnsignedLong | ( const String & rStr , unsigned long & rulTarget ) |
Related Functions | ||
| operator + | ( const char * pszSource , const String & rStr ) | |
| operator < | ( const String & rStr1 , const String & rStr2 ) |
| operator > | ( const String & rStr1 , const String & rStr2 ) |
| operator << | ( std::ostream & os , const String & rStr ) |
Related Types | ||
| ||
This class offers a set of low and high-level operations for safe and convenient handling of character strings, including commonly used operators (==,=...) and conversion functions to numeric types.
The strings are managed like conventional C-style null-terminated ASCII strings (char *). Input or output const char* values are therefore always assumed to be null-terminated. If not so, the results are undefined.
The cast operator to const char* is useful for getting the raw C-style string.
Some of the functions are also compatible with the handling of binary buffers, even if these buffers may contain null or non-printable chars. This peculiarity is always documented for the matching functions.
This class is especially optimised for high performance and combines internally static and dynamic memory buffering. A string instance always holds a deep and private copy of its string. String instances never share memory buffers.
Memory Buffer management function.
Re-allocates the buffer if necessary to ensure that at least uMinCapacity are allocated
If the bufffer must be re-allocated, by default the new size is (old_size+1)*2. Otherwise it is uMinCapacity.
Selects the static or dynamic buffer according to the required size.
See also:
Default void constructor.
Constructs an empty string.
Example:
String s; // s == ""
See also:
Copy constructor.
Constructs a copy of the passed rStr string.
Example:
String s("Michel");
String s2(s); // s2 == "Michel"See also:
Constructs a string which copies the iLen first chars of pszSource.
If the size iLen is unspecified (< 0), the whole input string is copied till end of string is encountered (\0).
This function is compatible with the handling of binary buffers. If a length is specified, the string will store the iLen bytes of the passed buffer, inclusive all null and non-printable chars. The value of the buffer can then be got back using the str() operation.
In all cases, the string is ended with a null char.
iLen is optional, by default iLen = -1.
See also:
Example:
String s("Michel"); // s == "Michel"
String s2("Michel", 2); // s2 == "Mi"Constructs a string which just contains c.
See also:
Constructs a string which just contains c.
See also:
Constructs a string holding the string represention of int iValue.
lpszFormat is optional and contains the conversion format as given in in ::printf().
If lpszFormat is not specified (lpszFormat = NULL by default), operator=() is used for the conversion (safe). Otherwise, ::sprintf() with the specified formation is used (not safe).
Note:
This function is not recommended wherever safety is critical. When ::sprintf() is used, a limited buffer of size 100 is used. Moreover There is no consistency check made between the format and the passed value to convert.
See also:
Behaves like the above function but takes unsigned int uValue as argument.
Note:
Please read the notes of the first referenced function.
See also:
Behaves like the above function but takes long iValue as argument.
Note:
Please read the notes of the first referenced function.
See also:
Behaves like the above function but takes unsigned long uValue as argument.
Note:
Please read the notes of the first referenced function.
See also:
Behaves like the above function but takes float fValue as argument.
Note:
Please read the notes of the first referenced function.
See also:
Behaves like the above function but takes double dValue as argument.
Note:
Please read the notes of the first referenced function.
See also:
Destructor.
Delete any memory allocated on the heap and resets pointers to null.
See also:
Returns a hashcode for the string.
See also:
Tells whether the string is empty (zero char).
See also:
Returns the length of the string (0 or positive value).
See also:
Returns the actual buffer capacity of the string (at least as great than the string length).
See also:
Copies the chars between positions srcBegin and srcEnd to the target char array dst, starting at position dstBegin. The char of index "srcEnd" is not included !
See also:
Copies the chars from pszSource to this string, starting at position uDstBegin. Ensures the string has enougth capacity.
See also:
Returns the raw const char* pointer to the string buffer. The string can't be modified using the pointer. It is read-only.
See also:
Equivalent to operator=() but does not return a reference to itself.
Example:
String s;
s.set("Dog"); // s == "Dog"See also:
Empties string (zero char). length() returns zero after that. Is equivalent to set("").
See also:
Sets this string as case less or not depending on bCaseLess. bCaseLess is optional and true by default.
This will be taken into account within any search and comparison functions.
See also:
Tells whether the string is case less.
See also:
Assigns the string to pszSource. pszValue must end with '\0' (end of string). Previous string value is lost and overwritten by a copy of pszSource.
Returns a reference to itself.
Example:
String s; s = "Dog"; // s == "Dog"
See also:
Assigns the value of the passed string to this one. In all cases, the number of bytes copied is always that number returned by length() of the passed string.
This function is compatible with the handling of binary buffers. The passed string may contain a binary buffer for which length() returns the size.
Example:
String s("Dog");
String s2;
s2 = s; // s2 == "Dog"See also:
Equivalent to the function referenced below, except that it takes a char as argument. After this operator, the string will just hold the passed char.
Example:
String s; s = 'c'; // s == "c"
See also:
Equivalent to the function referenced below.
See also:
Assigns the string to the string representation of the passed int iSource. The conversion function mentioned below is used to realise the conversion.
Example:
String s; int i = 345; s = i; // s == "345" i = -1; s = i; // s == "-1"
See also:
Equivalent to the function mentioned above, except that it takes unsigned int uiSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes long lSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes unsigned long uSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes float fSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes double dSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes short sSource as argument and that the conversion function used is the one mentioned below.
See also:
Equivalent to the function mentioned above, except that it takes unsigned short usSource as argument and that the conversion function used is the one mentioned below.
See also:
Inverts the chars of the string.
Returns a reference to itself.
Example:
String s = "Reverse"; s.reverse(); // s == "esreveR"
See also:
Uppers case of string.
Returns a reference to itself.
Example:
String s = "Upper"; s.toUpperCase(); // s == "UPPER"
See also:
Lowers case of string.
Returns a reference to itself.
Example:
String s = "LoWer"; s.toLowerCase(); // s == "lower"
See also:
Removes all starting c. By default c = ' ' (space char).
bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.
Returns a reference to itself.
Example:
String s = " My sentence. "; s.trimLeft(); // s == "My sentence."
See also:
Removes all ending c chars. By default c = ' ' (space char).
bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.
Returns a reference to itself.
Example:
String s = " My sentence. "; s.trimRight(); // s == " My sentence."
See also:
Removes both all starting and ending c chars. By default c = ' ' (space char).
bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.
Returns a reference to itself.
Relies on trimLeft() and trimRight().
Example:
String s = " My sentence. "; s.trim(); // s == "My sentence."
See also:
Replaces any tabulation char by usTabLen space chars. usTabLen is optional. By default usTabLen = 8.
Additionally, this function computes the new position in the result string of the char that was initially at position uPos in the string. The new position is returned in uPos.
Returns a reference to itself.
Example:
String s = "Name:\tMehl"; unsigned long uPos = 6; s.untabifyWithCursor(uPos); // s == "Name: Mehl" uPos = 13.
See also:
Behaves like the function referred to below, except that it does not manage a char position conversion. s.trim(); // s == "My sentence."
Example:
String s = "Name:\tMehl"; s.untabifyWithCursor(4); // s == "Name: Mehl"
See also:
Replaces any character that can't be represented as is in a C string constant with the matching escape sequence.
The following table gives the correspondence between the chars and their escape sequence.
simple quote ' => \'
double quote " => \"
backslash \ => \\
horizontal tab => \t"
new line => \n
vertical tab => \v
backspace => \b
carriage return => \r
formfeed => \f
audible alert => \a
question mark => \?
octal number => \ooo
hexadecimal number => \xhh
See also:
Replaces string pszOld with pszNew.
All occurrences are replaced only if the optional parameter bAll is true, . By default bAll = false and only one occurrence is replaced.
This function is case sensitive.
Returns true is something was replaced, false otherwise.
Example:
String s = "This is a integer";
s.replace("is", "ee", true); // s == "Thee ee a integer"See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a char with another char.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a char by a string.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a string with a char.
See also:
Inserts string rStr at uOffset. The chars inclusive char at uOffset are shifted to the right.
Returns true if insertion was successful. False if uOffset is invalid.
Example:
String s = "This is a integer"; s.insert(9, "n unsigned"); // s == "This is an unsigned integer"
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it just permits to insert a char.
See also:
Shifts the string uHowMuch times to the left. The uHowMuch first chars are lost.
uHowMuch is optional. Its default value is 1.
Relies on the function referred to below.
Returns a reference to itself.
Example:
String s = "Complete String"; s.shift(9); // s == "String"
See also:
Shifts the string uHowMuch times to the right setting the inserted uHowMuch first chars to rightc.
uHowMuch is optional. Its default value is 1. rightc is optional. Its default value is ' '.
Relies on the two last functions referred to below.
Returns a reference to itself.
Example:
String s = "Complete String"; s.shift(7); // s == " Complete String"
See also:
Fills the string with uLen char(s) fillc.
fillc is optional. By default fillc = ' '.
uFrom is optional and set to 0xFFFFFFFF by default. In that case, the filling chars are appended to the current string.
If uFrom is specified, the filling chars overwrite the uLen first chars from position uFrom and overflowing chars are appended to the current string.
This function is compatible with the handling of binary buffers. The string can be filled with any byte value inclusive all null and non-printable chars. The value of the buffer can then be got back using the str() operation.
Returns a reference to itself.
Example:
String s = "Original String"; s.fill(9); // s == "Original String "
See also:
Removes chars between whose offset is between start and end. The char of offset end is not removed.
end is optional. By default end = -1 which means that all chars starting from start offset until the end of the string are removed.
Returns true if the removal was successful, false in those cases:
end is negative and is not -1, start or end is an invalid offset, start > end.
Note:
This function assumes that the string length is not greater than the maximum value of a long. Otherwise this function returns false.
Example:
String s = "Original String"; s.eraseRange(6,8); // s == "Origin String"
See also:
Removes nb chars from index start.
nb is optional. By default nb = -1 which means that all chars until the end of the string are removed.
Returns true if the removal was successful, false in those cases:
nb is negative and is not -1, start + nb is greater that the string length.
Equivalent to eraseRange(start, (long)(start+nb))
Note:
This function assumes that the string length is not greater than the maximum value of a long. Otherwise this function returns false.
Example:
String s = "Original String"; s.erase(6,2); // s == "Origin String"
See also:
Rubs off string c_s and replace the empty space with cEraseChar chars.
In constrast with the erase() function, this function does not modify the string size. It just replaces any occurrence of c_s with as many cEraseChar needed to rub off c_s from the string.
It is much less time-consuming than other functions like erase() or replace() as no memory allocation and freeing is needed at all. Therefore it may sometimes be a better choice with regard to the result or the performance sought.
cEraseChar is optional and is the space char by default.
uFrom is optional and set to 0 by default. It gives the char index relative to c_s from which the erasing should actually take place. If the uFrom is greater than the size of c_s, nothing is done!
As return value, tells whether the string was changed.
Example:
String s = "Original String";
s.rubout("Original"); // s == " String"
s.rubout("Str", ' ', 1); // s == " S ing"See also:
Appends string rStr terminated with a new line char. Convenient when generating lines of source code files for example.
Returns a reference to itself.
Example:
String s = "Begin"; String s2 = "End"; s.append(s2).escapeSequence(); // s == "BeginEnd\n"
See also:
Appends string rStr.
Returns a reference to itself.
Example:
String s = "Begin"; String s2 = "End"; s.append(s2); // s == "BeginEnd"
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it takes directly a C string (const char*) instead of a String object as parameter.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it just appends c.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it just appends unsigned c.
See also:
Appends the string representation of the passed unsigned int uN.
Returns a reference to itself.
Note:
Constructor String(unsigned int) is used for conversion.
Example:
String s = "rfc"; unsigned int i = 1913; s.append(i); // s == "rfc1913"
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed int iN.
Note:
Constructor String(int) is used for conversion.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed unsigned long uN.
Note:
Constructor String(unsigned long) is used for conversion.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed long iN.
Note:
Constructor String(long) is used for conversion.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed float fN.
Note:
Constructor String(float) is used for conversion.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed double dN.
Note:
Constructor String(double) is used for conversion.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Overloaded function provided for convenience. Behaves like the function referred to below.
See also:
Provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
Example:
String s = "I will go to swimmingpool"; String s2 = s + " tomorrow"; // s2 == "I will go to swimmingpool tomorrow" // s is unchanged.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.
See also:
Behaves like the function mentionned below.
See also:
Behaves like the function mentionned below.
See also:
Behaves like the function mentionned below.
See also:
Behaves like the function mentionned below.
See also:
Returns a reference to the char at index uIndex. Modifying the returned char also modifies the char of the string. This operator is called when the application wants to get the char value and change it.
Example:
String s = "Wood";
char& cFirst= s[0] ; // cFirst == 'W'
printf("First character of string is: '%c'. Now changing it.\n", cFirst);
cFirst = 'G'; // Now s == "Good"
printf("Also changing second character\n", cFirst);
s[1] = 'G'; // Now s == "GGod"See also:
Behaves like the above function but with an unsigned long index.
See also:
Behaves like the above function except that it takes an int index and that for negative indexes the last char is returned.
See also:
Behaves like the above function but with a long index.
See also:
Returns the char at index uIndex. This operator is called when the application just wants to get the char value and not modify it.
Example:
String s = "Welcome home"; char cFirst= s[0] ; // cFirst == 'W'
See also:
Behaves like the above function but with an unsigned long index.
See also:
Behaves like the above function except that it takes an int index and that for negative indexes the last char is returned.
See also:
Behaves like the above function but with a long index.
See also:
Equivalent to mid().
Example:
String s = "Welcome home"; String s2 = s(0,7) // s2 = "Welcome"
See also:
Returns the uLength leftmost chars.
If uLength is greater than the actual string length, an empty string is returned.
Otherwise it is equivalent to mid(0, uLength)
Example:
String s = "Welcome home"; String s2 = s.left(7) // s2 = "Welcome"
See also:
Returns the uLength rightmost chars.
If uLength is greater than the actual string length, an empty string is returned.
Otherwise it is equivalent to mid(length() - uLength, uLength)
Example:
String s = "Welcome home"; String s2 = s.right(4) // s2 = "home"
See also:
Returns the sub-string of ending at uPositionEnd and starting from uPosition. The char at index uPositionEnd is not part of the returned string.
If uPosition >= uPositionEnd, an empty string is returned.
Otherwise it is equivalent to mid(uPosition, uPositionEnd-uPosition);
Example:
String s = "Welcome home"; String s2 = s.substring(2, 4) // s2 = "lc"
See also:
Returns the sub-string of length uLength starting from uPosition.
If uPosition is beyond the end of the string, an empty string is returned.
If uPosition + uLength is greater than the string length, only the substring until end of string is returned.
Example:
String s = "Welcome home"; String s2 = s.mid(8, 10) // s2 = "home" String s3 = s.mid(0, 8) // s3 = "Welcome "
See also:
Performs the same operation as the famous grep unix command. Scans all the lines contained within the string and keep those containing the searched string.
Returns a string which results of the concatenation of all matching lines.
See also:
Extracts and returns the string part at the left of rstrSep.
The separator string rstrSep is not extracted and is removed from the original string.
If rstrSep is not found, the whole string is extracted and returned and the string is emptied.
Relies on strstr().
Example:
String s = "It#sep#is#sep#sunny";
String s2 = s.token("#sep#") // s == "is#sep#sunny" and s2 == "It"
String s3 = s.token("#sep#") // s == "sunny" and s2 == "It" and s3 == "is"See also:
Extracts and returns the string part at the left of cSep.
The separator char cSep is not extracted and is removed from the original string.
If no cSep is found, the whole string is extracted and returned and the string is emptied.
This specific function is available for performance purposes as it relies on ::strrchr().
Example:
String s = "It is sunny";
String s2 = s.token(' ') // s == "is sunny" and s2 == "It"
String s3 = s.token(' ') // s == "sunny" and s2 == "It" and s3 == "is"See also:
Splits the string into the list of substrings which are separated by c_sSep.
bTrimItems is optional and tells whether to trim the extracted substrings.
See also:
Returns the offset of the first occurrence of cha beyond offset uStartFrom. Returns -1 if not found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0
This specific function is available for performance purposes as it relies on ::strrchr().
Example:
String s = "NiceTown";
s.indexOf('e';) // == 3See also:
Returns the offset of the first occurrence of rStr beyond offset uStartFrom. Returns -1 if no such substring is found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0 bIgnoreCase is optional. By default bIgnoreCase = false
Uses ::strstr().
This function assumes that the length of the string is not greater than the upper boundary value of a long.
Example:
String s = "NiceTown";
s.indexOf("Town"); // == 4
s.indexOf("ow"); // == 5
s.indexOf("Ah"); // == -1See also:
Returns the offset of the last occurrence of cha beyond offset uStartFrom. Returns -1 if not found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0
This specific function is available for performance purposes as it relies on ::strrchr().
Example:
String s = "NiceTown";
s.lastIndexOf('e'); // == 3See also:
Returns the offset of the last occurrence of rStr beyond offset uStartFrom. Returns -1 if no such substring is found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0 bIgnoreCase is optional. By default bIgnoreCase = false
This function assumes that the length of the string is not greater than the upper boundary value of a long.
Example:
String s = "NiceTown";
s.lastIndexOf("Town"); // == 4
s.lastIndexOf("Tow"); // == 4
s.lastIndexOf("Ah"); // == -1See also:
Compares substring of length uLen starting at offset utoffset with the substring of rStr of the same length starting at offset uooffset. If bIgnoreCase is true, the char case is not taken into account. Returns false if utoffset + uLen is greater than the string or if uooffset + uLen is greater than the passed string length.
Example:
String s = "NiceTown"; String s2 = "cetoz"; if (s.regionMatches(true, 2, s2, 0, 4)) // Success ... if (s.regionMatches(true, 2, s2, 0, 5)) // Failure ...
Note:
It is not tested whether utoffset + uLen > upperboundary(unsigned long) It is not tested whether uooffset + uLen > upperboundary(unsigned long)
See also:
Tells whether the string is equal to pszStr regardless of char case.
Note:
Uses ::strcasecmp() if available.
Example:
String s = "Happy";
if (s.equalsIgnoreCase("HaPPy")) // Success
...
if (s.equals("happy")) // Success
...See also:
Overloaded function provided for convenience.
See also:
Tells whether the string is equal to pszStr. The comparison is case sensitive.
Note:
Uses ::strncmp().
Example:
String s = "Happy";
if (s.equals("Happy")) // Success
...
if (s.equals("Yes")) // Failure
...See also:
Overloaded function provided for convenience.
See also:
Overloaded function provided for convenience. Returns the result of the equivalent equal function.
See also:
Overloaded function provided for convenience. Returns the result of the equivalent equal function.
See also:
Overloaded function provided for convenience. Tells whether the string's size is 1 and its char is arg.
See also:
Overloaded function provided for convenience. Tells whether the string's size is 1 and its char is arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to an int is equal to int arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to an unsigned int is equal to unsigned int arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to a long is equal to long arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to an unsigned long is equal to unsigned long arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to a float is equal to float arg.
See also:
Overloaded function provided for convenience. Tells whether this string converted to a double is equal to double arg.
See also:
Tells whether pszStr differs from this string. Returns the reverse result of operator==.
See also:
Tells whether rStr differs from this string. Returns the reverse result of operator==.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Overloaded function provided for convenience. Is the opposite function to the one referred to below.
See also:
Tells whether the string starts with string rStr. A constant C string (char*) can also be passed to this method since the String class defines a constructor with such type.
Note:
Uses ::strncmp().
Example:
String s = "Happy";
if (s.startsWith("Happ")) // Success
...
if (s.startsWith("Yes")) // Failure
...See also:
Tells whether the string ends with string rStr. A constant C string (char*) can also be passed to this method since the String class defines a constructor with such type.
Note:
Uses ::strncmp().
Example:
String s = "Happy";
if (s.endsWith("py")) // Success
...
if (s.endsWith("Sad")) // Failure
...See also:
Tells whether the string matches the pattern c_sPattern given as a regular expression.
At the moment, the only pattern supported is a single '*' as regular expression.
Example:
String s = "pattern";
s.matchesPattern("p*"); // true
s.matchesPattern("pat*"); // true
s.matchesPattern("p*n"); // true
s.matchesPattern("p*sn"); // falseSee also:
Tells whether the string matches any of the patterns given in the list c_slPatternList.
This function iterates through all patterns of the list by calling the function referred to below.
See also:
Tells whether the string is a combination of all the chars part of chararray.
Example:
String s = "laval";
const char* pszAllowedChars="alv";
const char* pszAllowedChars2="alvw";
if (s.consistsOfChars(pszAllowedChars))
{
... // Success: "laval" consists of 'l', 'a' and 'v' chars.
}
if (s.consistsOfChars(pszAllowedChars2))
{
... // Failure: "laval" doesn't contain 'w'.
}See also:
Cast operator to "const char*". The pointer returned points to the internal char array used to store the string.
Example:
String s = "won"; s += "again"; const char* pszString = (const char*)s; // pszString == "wonagain"
See also:
Converts double dSource to a string. iPrecision is the desired number of decimal numbers. iPrecision is optional and by default iPrecision = 10. If iPrecision < 0, the default precision is the one of %f in ::sprintf().
On success, stores the result in rRes; True is always returned.
Example:
String s;
double dVal = -2343545;
if (String::toString(dVal, s))
{
// Success: s == "-2343545"
...
}Note:
::sprintf(..., "%.iPrecision", dSource) is used for the conversion.
See also:
Converts long lSource to a string. On success, stores the result in rRes; True is always returned.
Example:
String s;
long iVal = -2343545;
if (String::toString(iVal, s))
{
// Success: s == "-2343545"
...
}See also:
Converts unsigned long uSource to a string. On success, stores the result in rRes; True is always returned.
Example:
String s;
unsigned long uVal = 2343545;
if (String::toString(uVal, s)
{
// Success: s == "2343545"
...
}See also:
Attempts to convert string rStr to an long. On success, i.e. the string contains a valid representation of a long number, stores the result in rlTarget and returns true. On failure, returns false.
Note:
::strtol() is used for the conversion.
Example:
String s("-2343545");
long iValue = 0;
if (String::toLong(s, iValue))
{
// Success: iValue == -2343545
...
}See also:
Attempts to convert string rStr to an unsigned long. On success, i.e. the string contains a valid representation of a unsigned long number, stores the result in rulTarget and returns true. On failure, returns false.
Note:
::strtoul() is used for the conversion.
Example:
String s("2343545");
unsigned long uVal = 0;
if (String::toUnsignedLong(s, uValue))
{
// Success: uValue == 2343545
...
}See also:
Attempts to convert string rStr to a float. On success, i.e. the string contains a valid representation of a float number, stores the result in rfTarget and returns true. On failure, returns false.
Note:
::strtod() is used for conversion, not ::strtof(). ::strtod() is described by ANSI whereas strtof is described in ISOC99. This function is inaccessible under Linux even with -D_USE_ISOC99
Example:
String s("121.32");
float fValue = 0.0;
if (String::toFloat(s, fValue))
{
// Success: fValue == 121.32
...
}See also:
Formats a standard command line help text for a command option.
The option name given by sOpt is displayed in the first column whose width is given by uOptColWidth. Option names are indented with uOptNbIndent space chars.
uOptColWidth is optional and is equal to 30 by default.
uOptNbIndent is optional and is equal to 2 by default.
The actual help description is displayed in the second column whose width is given by uHelpColWidth.
uHelpColWidth is optional and is equal to 40 by default.
Below given three examples which are excerpt of the UNIX make command line help:
Example:
-b, -m Ignored for compatibility.
-B, --always-make Unconditionally make all targets.
-C DIRECTORY, --directory=DIRECTORY
Change to DIRECTORY before doing anything.See also:
Attempts to convert string rStr to a double. On success, i.e. the string contains a valid representation of a double number, stores the result in rdTarget and returns true. On failure, returns false.
Note:
::strtod() is used for conversion.
Example:
String s("121.32");
double dValue = 0.0;
if (String::toDouble(s, dValue))
{
// Success: dValue == 121.32
...
}See also:
Tells whether the string represents an unsigned integer number, regardless of any boundary value consideration. Any leading whitespaces is ignored.
Example:
String s("232435465657657409");
s.isUINT(); // Returns trueSee also:
Returns a string copy of this one.
See also:
Formats the strings so that the text fits into a column of the specified width uColWidth, keeping words unsplitted and adding new lines if necessary.
If a word is longer than the specified width, it is splitted and the '-' split char is shown at the split point.
if uColWidth is zero, the string is emptied.
if uColWidth is 1, there is a char per line and no '-' char showing the split point is shown.
Example:
String s = "This is a sample text that will be formatted for holding into
a column of 20 chars.";
s.formatColumn(20);
// s ="This is a sample\n
text that will be\n
formatted for\n
holding into a\n
column of 20 chars."Example:
String s ="awordnotholdinginalinewiththespecifiedwidth"
s.formatColumn(20);
// s ="awordnotholdinginal-\n
inewiththespecified-\n
width"See also:
Justifies the text so that it occupies the whole column width.
if uColWidth is zero, the string is emptied.
Example:
String s = "This is a sample text that will be formatted for holding into a column of 20 chars."; s.justify(20); // s = "This is a sample text that will be formatted for holding into a column of 20 chars."
See also:
Returns a string resulting from the concatenation of c_pszSource and rStr
See also:
"Lesser than" comparison operator between 2 strings.
See also:
"Greater than" comparison operator between 2 strings.
See also:
Output stream operator for a string. The content of s is put into the os output stream.
See also:
This file is part of the LLOOP LL Object-Oriented Parser Generator and Object Expander Generator. Copyright (c) 2005-2006 Michel MEHL, France. All rights reserved. LLOOP is distributed by the company ERSA SaRL.
| Copyright (c) 2005-2006 Michel MEHL, Haguenau, France |
| LLOOP version 1.1 |