Rogue Wave Views 5.6 |
Rogue Wave Views |
Rogue Wave Views Documentation Home |
Class that manages strings in single or multibytes. More...
#include <ilog/string.h>
Public Member Functions | |
IlString (const char *cstring=0) | |
This constructor builds an IlString object from the C string cstring. More... | |
IlString (const IlString &string) | |
This constructor is the copy constructor. More... | |
IL_EXPLICIT | IlString (int value, const char *format=DefaultIntegerFormat) |
This constructor is the conversion constructor from an integer. More... | |
IL_EXPLICIT | IlString (unsigned int value, const char *format=DefaultUnsignedIntegerFormat) |
This constructor is the conversion constructor from an unsigned integer. More... | |
IL_EXPLICIT | IlString (short value, const char *format=DefaultShortFormat) |
This constructor is the conversion constructor from a short integer. More... | |
IL_EXPLICIT | IlString (unsigned short value, const char *format=DefaultUnsignedShortFormat) |
This constructor is the conversion constructor from an unsigned short integer. More... | |
IL_EXPLICIT | IlString (long value, const char *format=DefaultLongFormat) |
This constructor is the conversion constructor from a long integer. More... | |
IL_EXPLICIT | IlString (unsigned long value, const char *format=DefaultUnsignedLongFormat) |
This constructor is the conversion constructor from an unsigned long integer. More... | |
IL_EXPLICIT | IlString (float value, const char *format=DefaultFloatFormat) |
This constructor is the conversion constructor from a float. More... | |
IL_EXPLICIT | IlString (double value, const char *format=DefaultDoubleFormat) |
This constructor is the conversion constructor from a double. More... | |
~IlString () | |
The destructor releases the resources used by the object. | |
int | caseCompare (const IlString &string, int start1=0, int end1=-1, int start2=0, int end2=-1) const |
This member function returns an int according to the lexicographical order (case insensitive) of this in relation to string. More... | |
IlString & | catenate (const IlString &string, int start=0, int end=-1) |
This member function catenates the given string to this . More... | |
int | compare (const IlString &string, int start1=0, int end1=-1, int start2=0, int end2=-1) const |
This member function returns an int according to the lexicographical order of this in relation to string. More... | |
char * | copyValue () const |
This member function returns a const pointer to a new allocated C-style string in single or multibyte according to the locale of the program. More... | |
IlBoolean | endsWith (const IlString &, int=0, int=-1) const |
This member function returns IlTrue when the strings ends with string, IlFalse otherwise. More... | |
IlBoolean | equals (const IlString &string, int start1=0, int end1=-1, int start2=0, int end2=-1) const |
This member function returns IlTrue when the strings this and string are equal. More... | |
int | getIndexOf (const IlString &subString, int start=0, int subStart=0, int subEnd=-1) const |
This member function returns the index of the first position of the substring subString in the current string. More... | |
int | getLastIndexOf (const IlString &subString, int end=-1, int subStart=0, int subEnd=-1) const |
This member function returns the index of the last position of the substring subString in the string. More... | |
size_t | getLength () const |
This member function returns the length of the string. More... | |
size_t | getSize () const |
This member function returns the size of the string. More... | |
IlString | getSubString (int start=0, int end=-1) const |
This member function returns a new IlString , substring of the current string. More... | |
const char * | getValue () const |
This member function returns a const pointer to a C-style string in single or multibyte according to the locale of the program. More... | |
IlString & | insert (const IlString &string, int position=0, int start=0, int end=-1) |
This member function inserts the given string to this at the given position. More... | |
IlBoolean | isBlank () const |
This member function returns IlTrue when the string is empty or contains only spaces, tabs, and so on; IlFalse otherwise. More... | |
IlBoolean | isEmpty () const |
This member function returns IlTrue when the string is empty, IlFalse otherwise. More... | |
operator const char * () const | |
Conversion operator to C-style string. More... | |
IlBoolean | operator! () const |
The not operator. More... | |
IlBoolean | operator!= (const IlString &string) const |
Inequality operator. More... | |
IlString & | operator+= (const IlString &string) |
Merge operator. More... | |
IlBoolean | operator< (const IlString &string) const |
Less operator. More... | |
IlBoolean | operator<= (const IlString &string) const |
Less-or-equal operator. More... | |
IlString & | operator= (const IlString &string) |
Assignment operator. More... | |
IlBoolean | operator== (const IlString &string) const |
Equality operator. More... | |
IlBoolean | operator> (const IlString &string) const |
Greater operator. More... | |
IlBoolean | operator>= (const IlString &string) const |
Greater-or-equal operator. More... | |
IlString & | prepend (const IlString &string, int start=0, int end=-1) |
This member function prepends the given string to this . More... | |
void | readQuoted (IL_STDPREF istream &istr) |
This member function reads from the stream istr and fills in this . More... | |
IlString & | remove (int start=0, int end=-1) |
This member function removes a part of the current string. More... | |
IlString & | remove (const IlString &subString, int start=0, int end=-1) |
This member function removes a substring of the current string. More... | |
IlString & | replace (const IlString &string, int start=0, int end=-1, int subStart=0, int subEnd=-1) |
This member function replaces a part of the current string by another string. More... | |
IlBoolean | startsWith (const IlString &string, int start=0, int end=-1) const |
This member function returns IlTrue when the current string starts with string, IlFalse otherwise. More... | |
IlString & | substitute (const IlString &string1, const IlString &string2, int start=0, int end=-1, int subStart1=0, int subEnd1=-1, int subStart2=0, int subEnd2=-1) |
This member function substitutes in the current string the occurrences of a substring by another one. More... | |
IlString & | toLower () |
This member function converts the current string to lower case. More... | |
IlString & | toUpper () |
This member function converts the current string to upper case. More... | |
void | writeQuoted (IL_STDPREF ostream &ostr) const |
This member function writes the string into the stream ostr surrounded by double quotes. More... | |
Class that manages strings in single or multibytes.
Library: ilog
According to the locale, the string is created internally with a single or multibyte representation. This class lets you use it without having to take care of this representation. However, this class is not intended to convert either from a single byte to a multibyte string, or from a multibyte to a single byte string. When an IlString
object is created, it is supposed to deal with the same locale for its entire life.
This class uses a mechanism of reference counter in order to share the C strings used internally. This means that the pointers returned by IlString::operator const char*() const
and IlString::getValue()
must be used with care. They may be invalid after any call to a member function that modifies the object that returned this pointer.
IlString::IlString | ( | const char * | cstring = 0 | ) |
This constructor builds an IlString
object from the C string cstring.
A copy of cstring is used internally. Giving a null
value is equivalent to giving "".
This constructor is also the default constructor.
cstring | A constant pointer to a C-style string. |
IlString::IlString | ( | const IlString & | string | ) |
This constructor is the copy constructor.
It builds a new IlString
object from the object string. The internal C string is shared by both objects until one of them is modified (use of a reference counter).
string | A constant reference to an IlString object. |
IL_EXPLICIT IlString::IlString | ( | int | value, |
const char * | format = DefaultIntegerFormat |
||
) |
This constructor is the conversion constructor from an integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%d"
.
explicit
for compilers that implement this keyword.value | An int. |
format | A pointer to a C-style string. The default value is "\%d" . |
IL_EXPLICIT IlString::IlString | ( | unsigned int | value, |
const char * | format = DefaultUnsignedIntegerFormat |
||
) |
This constructor is the conversion constructor from an unsigned integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format s "\%u"
.
explicit
for compilers that implement this keyword.value | An unsigned int. |
format | A pointer to a C-style string. The default value is "\%u" . |
IL_EXPLICIT IlString::IlString | ( | short | value, |
const char * | format = DefaultShortFormat |
||
) |
This constructor is the conversion constructor from a short integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%hd"
.
explicit
for compilers that implement this keyword.value | A short int. |
format | A pointer to a C-style string. The default value is "\%hd" . |
IL_EXPLICIT IlString::IlString | ( | unsigned short | value, |
const char * | format = DefaultUnsignedShortFormat |
||
) |
This constructor is the conversion constructor from an unsigned short integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%hu"
.
explicit
for compilers that implement this keyword.value | An unsigned short. |
format | A pointer to a C-style string. The default value is "\%hu" . |
IL_EXPLICIT IlString::IlString | ( | long | value, |
const char * | format = DefaultLongFormat |
||
) |
This constructor is the conversion constructor from a long integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%ld".
explicit
for compilers that implement this keyword.value | A long integer. |
format | A pointer to a C-style string. The default value is "\%ld" . |
IL_EXPLICIT IlString::IlString | ( | unsigned long | value, |
const char * | format = DefaultUnsignedLongFormat |
||
) |
This constructor is the conversion constructor from an unsigned long integer.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%lu"
.
explicit
for compilers that implement this keyword.value | An unsigned long. |
format | A pointer to a C-style string. The default value is "\%lu" . |
IL_EXPLICIT IlString::IlString | ( | float | value, |
const char * | format = DefaultFloatFormat |
||
) |
This constructor is the conversion constructor from a float.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%f"
.
explicit
for compilers that implement this keyword.value | A float. |
format | A pointer to a C-style string. The default value is "\%f" . |
IL_EXPLICIT IlString::IlString | ( | double | value, |
const char * | format = DefaultDoubleFormat |
||
) |
This constructor is the conversion constructor from a double.
The conversion is done according to the format. The syntax is compatible with the syntax of the printf
family functions. By default, the format is "\%g"
.
explicit
for compilers that implement this keyword.value | A double. |
format | A pointer to a C-style string. The default value is "\%g" . |
int IlString::caseCompare | ( | const IlString & | string, |
int | start1 = 0 , |
||
int | end1 = -1 , |
||
int | start2 = 0 , |
||
int | end2 = -1 |
||
) | const |
This member function returns an int according to the lexicographical order (case insensitive) of this
in relation to string.
The return value is negative when this
is before string.
It is null when the strings are equal.
It is positive when this
is after string.
The order depends on the locale. The comparison is done on the strings in lower case.
The string this
may be restricted by start1 and end1.
The string string may be restricted by start2 and end2.
string | A constant reference to an IlString object. |
start1 | An int . The default value is 0. |
end1 | An int . The default value is -1. |
start2 | An int . The default value is 0. |
end2 | An int . The default value is -1. |
IlBoolean
. This member function catenates the given string to this
.
The string string may be restricted by start and end. If end is equal to -1 this means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
It returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
int IlString::compare | ( | const IlString & | string, |
int | start1 = 0 , |
||
int | end1 = -1 , |
||
int | start2 = 0 , |
||
int | end2 = -1 |
||
) | const |
This member function returns an int according to the lexicographical order of this
in relation to string.
The return value is negative when this
is before string.
It is null when the strings are equal.
It is positive when this
is after string.
The order depends on the locale.
The string this
may be restricted by start1 and end1.
The string string may be restricted by start2 and end2.
If end1 or end2 are equal to -1, that means the relative string is taken until its end. Otherwise this parameter is the index of the first character that follows the relative substring.
string | A constant reference to an IlString object. |
start1 | An int . The default value is 0. |
end1 | An int . The default value is -1. |
start2 | An int . The default value is 0. |
end2 | An int . The default value is -1. |
IlBoolean
. char* IlString::copyValue | ( | ) | const |
This member function returns a const pointer to a new allocated C-style string in single or multibyte according to the locale of the program.
The pointed C string must be deleted with the operator delete[]
by the caller when it is no longer used.
new[]
operator. This member function returns IlTrue
when the strings ends with string, IlFalse
otherwise.
The string may be restricted by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
subString | A constant reference to an IlString object. |
subStart | An int . The default value is 0. |
subEnd | An int . The default value is -1. |
IlBoolean
. IlBoolean IlString::equals | ( | const IlString & | string, |
int | start1 = 0 , |
||
int | end1 = -1 , |
||
int | start2 = 0 , |
||
int | end2 = -1 |
||
) | const |
This member function returns IlTrue
when the strings this
and string are equal.
The strings are equal when strcmp
(or the equivalent for multibyte) returns 0.
The string this
may be restricted by start1 and end1.
The string string may be restricted by start2 and end2. If end1 or end2 are equal to -1, that means the relative string is taken until its end. Otherwise this parameter is the index of the first character that follows the relative substring.
string | A constant reference to an IlString object. |
start1 | An int . The default value is 0. |
end1 | An int . The default value is -1. |
start2 | An int . The default value is 0. |
end2 | An int . The default value is -1. |
IlBoolean
. int IlString::getIndexOf | ( | const IlString & | subString, |
int | start = 0 , |
||
int | subStart = 0 , |
||
int | subEnd = -1 |
||
) | const |
This member function returns the index of the first position of the substring subString in the current string.
The search starts at the position start. The substring may be restricted by the parameters subStart and subEnd. If subEnd is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
If the substring is not found, it returns -1.
subString | A constant reference to an IlString object. |
start | An int . The default value is 0. |
subStart | An int . The default value is 0. |
subEnd | An int . The default value is -1. |
int
. int IlString::getLastIndexOf | ( | const IlString & | subString, |
int | end = -1 , |
||
int | subStart = 0 , |
||
int | subEnd = -1 |
||
) | const |
This member function returns the index of the last position of the substring subString in the string.
The search starts at the position end, a value of -1 means the end of the string. The substring may be restricted by the parameters subStart and subEnd. If subEnd is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
If the substring is not found, it returns -1.
subString | A constant reference to an IlString object. |
end | An int . The default value is -1. |
subStart | An int . The default value is 0. |
subEnd | An int . The default value is -1. |
int
. size_t IlString::getLength | ( | ) | const |
This member function returns the length of the string.
It is the number of characters of the string.
size_t
. size_t IlString::getSize | ( | ) | const |
This member function returns the size of the string.
It is the size needed to represent the string (with the final 0). It is not necessarily the number of characters of this string.
size_t
. IlString IlString::getSubString | ( | int | start = 0 , |
int | end = -1 |
||
) | const |
This member function returns a new IlString
, substring of the current string.
The substring is defined by start and end.
The value of start is the index of the position where the substring starts.
The value of end is the (position+1) of the last character of the substring. This means that the character whose position is end, if it exists, is not included.
For end == -1
, this member function returns the tail of the string from start.
start | An int . The default value is 0. |
end | An int . The default value is -1. |
IlString
object. const char* IlString::getValue | ( | ) | const |
This member function returns a const pointer to a C-style string in single or multibyte according to the locale of the program.
The pointed C string is the internal one. It must never be modified nor deleted.
IlString& IlString::insert | ( | const IlString & | string, |
int | position = 0 , |
||
int | start = 0 , |
||
int | end = -1 |
||
) |
This member function inserts the given string to this
at the given position.
The string string may be restricted by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
It returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
position | An int . The default value is 0. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
IlBoolean IlString::isBlank | ( | ) | const |
This member function returns IlTrue
when the string is empty or contains only spaces, tabs, and so on; IlFalse
otherwise.
IlBoolean
. IlBoolean IlString::isEmpty | ( | ) | const |
This member function returns IlTrue
when the string is empty, IlFalse
otherwise.
IlBoolean
. IlString::operator const char * | ( | ) | const |
Conversion operator to C-style string.
This conversion operator returns a const pointer to a C-style string in single or multibyte according to the locale of the program.
The pointed C string is the internal one. It must never be modified nor deleted.
IlBoolean IlString::operator! | ( | ) | const |
The not operator.
This operator returns IlTrue
when the string is empty, IlFalse
otherwise.
IlBoolean
. IlBoolean IlString::operator!= | ( | const IlString & | string | ) | const |
Inequality operator.
This operator returns IlFalse
when the strings are equal, that is, when the function strcmp
(or the equivalent for multibyte) returns 0, and IlTrue
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. Merge operator.
This operator catenates the given string to this
. It returns *this
.
Warning: This operator may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
Less operator.
This operator returns IlTrue
when the string is strictly before string in the lexicographical order, IlFalse
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. Less-or-equal operator.
This operator returns IlTrue
when the string is before string in the lexicographical order or equal to string, IlFalse
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. Assignment operator.
This operator assigns the given string to this
. It returns *this
.
Warning: This operator may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
Equality operator.
This operator returns IlTrue
when the strings are equal, that is, when the function strcmp
(or equivalent for multibyte) returns 0, and IlFalse
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. Greater operator.
This operator returns IlTrue
when the string is strictly after string in the lexicographical order, IlFalse
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. Greater-or-equal operator.
This operator returns IlTrue
when the string is after string in the lexicographical order or equal to string, IlFalse
otherwise.
string | A constant reference to an IlString object. |
IlBoolean
. This member function prepends the given string to this
.
The string string may be restricted by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
It returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
void IlString::readQuoted | ( | IL_STDPREF istream & | istr | ) |
This member function reads from the stream istr and fills in this
.
The format is defined in the function IlString::writeQuoted(IL_STDPREF ostream&) const
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
istr | A reference to an istream. |
IlString& IlString::remove | ( | int | start = 0 , |
int | end = -1 |
||
) |
This member function removes a part of the current string.
The part to be removed is defined by its start position and its end position (not included). If end is equal to -1, the end of the string is removed.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
This member function removes a substring of the current string.
The part to be removed is defined by subString, possibly restricted by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring. If the substring subString is not part of the string, this latter is not modified.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
subString | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
IlString& IlString::replace | ( | const IlString & | string, |
int | start = 0 , |
||
int | end = -1 , |
||
int | subStart = 0 , |
||
int | subEnd = -1 |
||
) |
This member function replaces a part of the current string by another string.
The substring to be removed is defined by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
Ths substring string may be restricted by subStart and subEnd. If subEnd is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
subStart | An int . The default value is 0. |
subEnd | An int . The default value is -1. |
This member function returns IlTrue
when the current string starts with string, IlFalse
otherwise.
The string may be restricted by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
string | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
IlBoolean
. IlString& IlString::substitute | ( | const IlString & | string1, |
const IlString & | string2, | ||
int | start = 0 , |
||
int | end = -1 , |
||
int | subStart1 = 0 , |
||
int | subEnd1 = -1 , |
||
int | subStart2 = 0 , |
||
int | subEnd2 = -1 |
||
) |
This member function substitutes in the current string the occurrences of a substring by another one.
The substring to be replaced is defined by string1, possibly restricted by subStart1 and subEnd1. If subEnd1 is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring. The new substring is defined by string2, possibly restricted by subStart2 and subEnd2. If subEnd2 is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring. The substitution may be limited to the part of the string defined by start and end. If end is equal to -1 that means the end of the substring. Otherwise it is the index of the first char in the string after the substring.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
string1 | A constant reference to an IlString object. |
string2 | A constant reference to an IlString object. |
start | An int . The default value is 0. |
end | An int . The default value is -1. |
subStart1 | An int . The default value is 0. |
subEnd1 | An int . The default value is -1. |
subStart2 | An int . The default value is 0. |
subEnd2 | An int . The default value is -1. |
IlString& IlString::toLower | ( | ) |
This member function converts the current string to lower case.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
IlString& IlString::toUpper | ( | ) |
This member function converts the current string to upper case.
This member function returns *this
.
Warning: This function may modify the internal representation of the string. This means that any pointer that was returned by IlString::getValue
or IlString::operator const char*()
may be invalid.
void IlString::writeQuoted | ( | IL_STDPREF ostream & | ostr | ) | const |
This member function writes the string into the stream ostr surrounded by double quotes.
Every space and double quote is prefixed by a backslash.
ostr | A reference to an ostream. |
© Copyright 2012, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.