The QString class provides an abstraction of Unicode text and the classic C null-terminated char array (char*). More...
#include <qstring.h>
Classes | |
struct | Null |
Public Member Functions | |
QString () | |
QString (QChar) | |
QString (const QString &) | |
QString (const QByteArray &) | |
QString (const QCString &) | |
QString (const QChar *unicode, uint length) | |
QString (const char *str) | |
~QString () | |
QString & | operator= (const QString &) |
QString & | operator= (const char *) |
QString & | operator= (const QCString &) |
QString & | operator= (QChar c) |
QString & | operator= (char c) |
QString (const Null &) | |
QString & | operator= (const Null &) |
bool | isNull () const |
bool | isEmpty () const |
uint | length () const |
void | truncate (uint pos) |
void | fill (QChar c, int len=-1) |
QString | copy () const |
QString | arg (long a, int fieldwidth=0, int base=10) const |
QString | arg (ulong a, int fieldwidth=0, int base=10) const |
QString | arg (int a, int fieldwidth=0, int base=10) const |
QString | arg (uint a, int fieldwidth=0, int base=10) const |
QString | arg (short a, int fieldwidth=0, int base=10) const |
QString | arg (ushort a, int fieldwidth=0, int base=10) const |
QString | arg (char a, int fieldwidth=0) const |
QString | arg (QChar a, int fieldwidth=0) const |
QString | arg (const QString &a, int fieldwidth=0) const |
QString | arg (double a, int fieldwidth=0, char fmt='g', int prec=-1) const |
QString & | sprintf (const char *format,...) |
int | find (QChar c, int index=0, bool cs=TRUE) const |
int | find (char c, int index=0, bool cs=TRUE) const |
int | find (const QString &str, int index=0, bool cs=TRUE) const |
int | find (const QRegExp &, int index=0) const |
int | find (const char *str, int index=0) const |
int | findRev (QChar c, int index=-1, bool cs=TRUE) const |
int | findRev (char c, int index=-1, bool cs=TRUE) const |
int | findRev (const QString &str, int index=-1, bool cs=TRUE) const |
int | findRev (const QRegExp &, int index=-1) const |
int | findRev (const char *str, int index=-1) const |
int | contains (QChar c, bool cs=TRUE) const |
int | contains (char c, bool cs=TRUE) const |
int | contains (const char *str, bool cs=TRUE) const |
int | contains (const QString &str, bool cs=TRUE) const |
int | contains (const QRegExp &) const |
QString | left (uint len) const |
QString | right (uint len) const |
QString | mid (uint index, uint len=0xffffffff) const |
QString | leftJustify (uint width, QChar fill=' ', bool trunc=FALSE) const |
QString | rightJustify (uint width, QChar fill=' ', bool trunc=FALSE) const |
QString | lower () const |
QString | upper () const |
QString | stripWhiteSpace () const |
QString | simplifyWhiteSpace () const |
QString & | insert (uint index, const QString &) |
QString & | insert (uint index, const QChar *, uint len) |
QString & | insert (uint index, QChar) |
QString & | insert (uint index, char c) |
QString & | append (char) |
QString & | append (QChar) |
QString & | append (const QString &) |
QString & | prepend (char) |
QString & | prepend (QChar) |
QString & | prepend (const QString &) |
QString & | remove (uint index, uint len) |
QString & | replace (uint index, uint len, const QString &) |
QString & | replace (uint index, uint len, const QChar *, uint clen) |
QString & | replace (const QRegExp &, const QString &) |
short | toShort (bool *ok=0, int base=10) const |
ushort | toUShort (bool *ok=0, int base=10) const |
int | toInt (bool *ok=0, int base=10) const |
uint | toUInt (bool *ok=0, int base=10) const |
long | toLong (bool *ok=0, int base=10) const |
ulong | toULong (bool *ok=0, int base=10) const |
uint64 | toUInt64 (bool *ok=0, int base=10) const |
float | toFloat (bool *ok=0) const |
double | toDouble (bool *ok=0) const |
QString & | setNum (short, int base=10) |
QString & | setNum (ushort, int base=10) |
QString & | setNum (int, int base=10) |
QString & | setNum (uint, int base=10) |
QString & | setNum (long, int base=10) |
QString & | setNum (ulong, int base=10) |
QString & | setNum (float, char f='g', int prec=6) |
QString & | setNum (double, char f='g', int prec=6) |
void | setExpand (uint index, QChar c) |
QString & | operator+= (const QString &str) |
QString & | operator+= (QChar c) |
QString & | operator+= (char c) |
QChar | at (uint i) const |
QChar | operator[] (int i) const |
QCharRef | at (uint i) |
QCharRef | operator[] (int i) |
QChar | constref (uint i) const |
QChar & | ref (uint i) |
const QChar * | unicode () const |
const char * | ascii () const |
const char * | latin1 () const |
const unsigned short * | ucs2 () const |
QCString | utf8 () const |
QCString | local8Bit () const |
bool | operator! () const |
QString & | setUnicode (const QChar *unicode, uint len) |
QString & | setUnicodeCodes (const ushort *unicode_as_ushorts, uint len) |
QString & | setLatin1 (const char *, int len=-1) |
int | compare (const QString &s) const |
void | compose () |
QChar::Direction | basicDirection () |
QString | visual (int index=0, int len=-1) |
const char * | data () const |
bool | startsWith (const QString &) const |
Static Public Member Functions | |
static QString | number (long, int base=10) |
static QString | number (ulong, int base=10) |
static QString | number (int, int base=10) |
static QString | number (uint, int base=10) |
static QString | number (double, char f='g', int prec=6) |
static QString | fromLatin1 (const char *, int len=-1) |
static QString | fromUcs2 (const unsigned short *ucs2) |
static QString | fromUtf8 (const char *, int len=-1) |
static QString | fromLocal8Bit (const char *, int len=-1) |
static int | compare (const QString &s1, const QString &s2) |
Static Public Attributes | |
static const Null | null = { } |
Private Member Functions | |
QString (int size, bool dummy) | |
void | deref () |
void | real_detach () |
void | setLength (uint pos) |
void | subat (uint) |
bool | findArg (int &pos, int &len) const |
QString (QStringData *dd, bool) | |
Static Private Member Functions | |
static QChar * | asciiToUnicode (const char *, uint *len, uint maxlen=(uint)-1) |
static QChar * | asciiToUnicode (const QByteArray &, uint *len) |
static char * | unicodeToAscii (const QChar *, uint len) |
static QStringData * | makeSharedNull () |
Private Attributes | |
QStringData * | d |
Static Private Attributes | |
static QStringData * | shared_null = 0 |
Friends | |
class | QConstString |
Q_EXPORT QDataStream & | operator>> (QDataStream &, QString &) |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const QString &s1, const QString &s2) |
bool | operator== (const QString &s1, const char *s2) |
bool | operator== (const char *s1, const QString &s2) |
bool | operator!= (const QString &s1, const QString &s2) |
bool | operator!= (const QString &s1, const char *s2) |
bool | operator!= (const char *s1, const QString &s2) |
bool | operator< (const QString &s1, const char *s2) |
bool | operator< (const char *s1, const QString &s2) |
bool | operator<= (const QString &s1, const char *s2) |
bool | operator<= (const char *s1, const QString &s2) |
bool | operator> (const QString &s1, const char *s2) |
bool | operator> (const char *s1, const QString &s2) |
bool | operator>= (const QString &s1, const char *s2) |
bool | operator>= (const char *s1, const QString &s2) |
QString | operator+ (const QString &s1, const QString &s2) |
QString | operator+ (const QString &s1, const char *s2) |
QString | operator+ (const char *s1, const QString &s2) |
QString | operator+ (const QString &s, char c) |
QString | operator+ (char c, const QString &s) |
QDataStream & | operator<< (QDataStream &s, const QString &str) |
The QString class provides an abstraction of Unicode text and the classic C null-terminated char array (char*).
QString uses implicit sharing, and so it is very efficient and easy to use.
In all QString methods that take const char* parameters, the const char* is interpreted as a classic C-style 0-terminated ASCII string. It is legal for the const char* parameter to be 0. The results are undefined if the const char* string is not 0-terminated. Functions that copy classic C strings into a QString will not copy the terminating 0-character. The QChar array of the QString (as returned by unicode()) is not terminated by a null.
A QString that has not been assigned to anything is null, i.e. both the length and data pointer is 0. A QString that references the empty string ("", a single '\0' char) is empty. Both null and empty QStrings are legal parameters to the methods. Assigning const char 0 to QString gives a null QString.
Note that if you find that you are mixing usage of QCString, QString, and QByteArray, this causes lots of unnecessary copying and might indicate that the true nature of the data you are dealing with is uncertain. If the data is NUL-terminated 8-bit data, use QCString; if it is unterminated (ie. contains NULs) 8-bit data, use QByteArray; if it is text, use QString.
|
inline |
QString::QString | ( | QChar | ch | ) |
Constructs a string containing the one character ch.
Definition at line 12234 of file qstring.cpp.
QString::QString | ( | const QString & | s | ) |
QString::QString | ( | const QByteArray & | ba | ) |
Constructs a string that is a deep copy of ba interpreted as a classic C string.
Definition at line 12280 of file qstring.cpp.
QString::QString | ( | const QCString & | ba | ) |
Definition at line 12288 of file qstring.cpp.
Constructs a string that is a deep copy of the first length QChar in the array unicode.
If unicode and length are 0, a null string is created.
If only unicode is 0, the string is empty, but has length characters of space preallocated - QString expands automatically anyway, but this may speed some cases up a little.
Definition at line 12313 of file qstring.cpp.
QString::QString | ( | const char * | str | ) |
Constructs a string that is a deep copy of str, interpreted as a classic C string.
If str is 0 a null string is created.
This is a cast constructor, but it is perfectly safe: converting a Latin1 const char* to QString preserves all the information. You can disable this constructor by defining QT_NO_CAST_ASCII when you compile your applications. You can also make QString objects by using setLatin1()/fromLatin1(), or fromLocal8Bit(), fromUtf8(), or whatever encoding is appropriate for the 8-bit data you have.
Definition at line 12343 of file qstring.cpp.
|
inline |
|
private |
Private function.
Constructs a string with preallocated space for size characters.
The string is empty.
Definition at line 12260 of file qstring.cpp.
|
inlineprivate |
|
inline |
Appends ch to the string and returns a reference to the result. Equivalent to operator+=().
Definition at line 703 of file qstring.h.
Appends ch to the string and returns a reference to the result. Equivalent to operator+=().
Definition at line 700 of file qstring.h.
Appends str to the string and returns a reference to the result. Equivalent to operator+=().
Definition at line 697 of file qstring.h.
QString QString::arg | ( | long | a, |
int | fieldwidth = 0 , |
||
int | base = 10 |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 12593 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 12603 of file qstring.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 721 of file qstring.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 724 of file qstring.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 727 of file qstring.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is expressed in to base notation, which is decimal by default and must be in the range 2-36 inclusive.
Definition at line 730 of file qstring.h.
QString QString::arg | ( | char | a, |
int | fieldwidth = 0 |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
a is assumed to be in the Latin1 character set.
Definition at line 12642 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 12651 of file qstring.cpp.
Returns a string equal to this one, but with the lowest-numbered occurrence of i
(for a positive integer i) replaced by a.
fieldwidth is the minimum amount of space a is padded to. A positive value produces right-aligned text, while a negative value produces left aligned text.
If there is no i
pattern, a warning message (qWarning()) is printed and the text as appended at the end of the string. This is error recovery and should not occur in correct code.
Definition at line 12553 of file qstring.cpp.
QString QString::arg | ( | double | a, |
int | fieldwidth = 0 , |
||
char | fmt = 'g' , |
||
int | prec = -1 |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
is formatted according to the fmt format specified, which is 'g' by default and can be any of 'f', 'F', 'e', 'E', 'g' or 'G', all of which have the same meaning as for sprintf(). prec determines the precision, just as for number() and sprintf().
Definition at line 12665 of file qstring.cpp.
const char * QString::ascii | ( | ) | const |
This functions simply calls latin1() and returns the result.
Definition at line 14494 of file qstring.cpp.
|
staticprivate |
This utility function converts the NUL-terminated 8-bit string str to Unicode, returning the result and setting len to the length of the Unicode string.
The caller is responsible for deleting the return value with delete[].
Definition at line 12005 of file qstring.cpp.
|
staticprivate |
This utility function converts the 8-bit string ba to Unicode, returning the result.
The caller is responsible for deleting the return value with delete[].
Definition at line 11957 of file qstring.cpp.
Returns a reference to the character at i, expanding the string with QChar::null if necessary. The resulting reference can then be assigned to, or otherwise used immediately, but becomes invalid once further modifications are made to the string.
Definition at line 623 of file qstring.h.
QChar::Direction QString::basicDirection | ( | ) |
This function returns the basic directionality of the string (QChar::DirR for right to left and QChar::DirL for left to right). Useful to find the right alignment.
Definition at line 11621 of file qstring.cpp.
int QString::compare | ( | const QString & | s | ) | const |
Compares this string to s, returning an integer less than, equal to, or greater than zero if it is, respectively, lexically less than, equal to, or greater than s.
Definition at line 14838 of file qstring.cpp.
void QString::compose | ( | ) |
Note that this function is not supported in Qt 2.0, and is merely for experimental and illustrative purposes. It is mainly of interest to those experimenting with Arabic and other composition-rich texts.
Applies possible ligatures to a QString, useful when composition-rich text requires rendering with glyph-poor fonts, but also makes compositions such as QChar(0x0041) ('A') and QChar(0x0308) (Unicode accent diaresis) giving QChar(0x00c4) (German A Umlaut).
Definition at line 11543 of file qstring.cpp.
Returns the number of times the character c occurs in the string.
The match is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Definition at line 13104 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 13129 of file qstring.cpp.
Returns the number of times str occurs in the string.
The match is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
This function counts overlapping substrings, for example, "banana" contains two occurrences of "ana".
Definition at line 13160 of file qstring.cpp.
int QString::contains | ( | const QRegExp & | rx | ) | const |
Counts the number of overlapping occurrences of rx in the string.
Definition at line 13759 of file qstring.cpp.
|
inline |
|
inline |
Returns a pointer to a 0-terminated classic C string.
In Qt 1.x, this returned a char* allowing direct manipulation of the string as a sequence of bytes. In Qt 2.x where QString is a Unicode string, char* conversion constructs a temporary string, and hence direct character operations are meaningless.
Definition at line 542 of file qstring.h.
|
private |
Definition at line 12373 of file qstring.cpp.
void QString::fill | ( | QChar | c, |
int | len = -1 |
||
) |
Fills the string with len characters of value c.
If len is negative, the current string length is used.
Definition at line 12865 of file qstring.cpp.
Finds the first occurrence of the character c, starting at position index. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
Definition at line 12902 of file qstring.cpp.
Finds the first occurrence of the string str, starting at position index. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
Definition at line 12935 of file qstring.cpp.
int QString::find | ( | const QRegExp & | rx, |
int | index = 0 |
||
) | const |
Finds the first occurrence of the regular expression rx, starting at position index. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.
Returns the position of the next match, or -1 if rx was not found.
Definition at line 13713 of file qstring.cpp.
|
inline |
|
private |
Finds the first occurrence of the character c, starting at position index and searching backwards. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
Definition at line 13021 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 736 of file qstring.h.
Finds the first occurrence of the string str, starting at position index and searching backwards. If index is -1, the search starts at the last character; -2, at the next to last character; etc.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
Definition at line 13039 of file qstring.cpp.
int QString::findRev | ( | const QRegExp & | rx, |
int | index = -1 |
||
) | const |
Finds the first occurrence of the regular expression rx, starting at position index and searching backwards. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.
Returns the position of the next match (backwards), or -1 if rx was not found.
Definition at line 13732 of file qstring.cpp.
|
inline |
Equivalent to findRev(QString(str), index).
Definition at line 744 of file qstring.h.
|
static |
Creates a QString from Latin1 text. This is the same as the QString(const char*) constructor, but you can make that constructor invisible if you compile with the define QT_NO_CAST_ASCII, in which case you can explicitly create a QString from Latin-1 text using this function.
Definition at line 14539 of file qstring.cpp.
|
static |
Returns the unicode string decoded from the first len bytes of local8Bit. If len is -1 (the default), the length of local8Bit is used. If trailing partial characters are in local8Bit, they are ignored.
local8Bit is assumed to be encoded in a locale-specific format.
See QTextCodec for more diverse coding/decoding of Unicode strings.
Definition at line 14605 of file qstring.cpp.
|
static |
Constructs a string that is a deep copy of str, interpreted as a UCS2 encoded, zero terminated, Unicode string.
If str is 0, then a null string is created.
Definition at line 12119 of file qstring.cpp.
|
static |
Returns the unicode string decoded from the first len bytes of utf8. If len is -1 (the default), the length of utf8 is used. If trailing partial characters are in utf8, they are ignored.
See QTextCodec for more diverse coding/decoding of Unicode strings.
Definition at line 14523 of file qstring.cpp.
Insert s into the string before position index.
If index is beyond the end of the string, the string is extended with spaces (ASCII 32) to length index and s is then appended.
Definition at line 13523 of file qstring.cpp.
Insert len units of QChar data from s into the string before position index.
Definition at line 13534 of file qstring.cpp.
Insert c into the string at (before) position index and returns a reference to the string.
If index is beyond the end of the string, the string is extended with spaces (ASCII 32) to length index and c is then appended.
Definition at line 13584 of file qstring.cpp.
|
inline |
|
inline |
const char * QString::latin1 | ( | ) | const |
Returns a Latin-1 representation of the string. Note that the returned value is undefined if the string contains non-Latin-1 characters. If you want to convert strings into formats other than Unicode, see the QTextCodec classes.
This function is mainly useful for boot-strapping legacy code to use Unicode.
The result remains valid so long as one unmodified copy of the source string exists.
Definition at line 14457 of file qstring.cpp.
Returns a substring that contains the len leftmost characters of the string.
The whole string is returned if len exceeds the length of the string.
Definition at line 13199 of file qstring.cpp.
Returns a string of length width that contains this string and padded by the fill character.
If the length of the string exceeds width and truncate is FALSE, then the returned string is a copy of the string. If the length of the string exceeds width and truncate is TRUE, then the returned string is a left(width).
Definition at line 13303 of file qstring.cpp.
|
inline |
QCString QString::local8Bit | ( | ) | const |
Returns the string encoded in a locale-specific format. On X11, this is the QTextCodec::codecForLocale(). On Windows, it is a system-defined encoding.
See QTextCodec for more diverse coding/decoding of Unicode strings.
Definition at line 14569 of file qstring.cpp.
QString QString::lower | ( | ) | const |
Returns a new string that is the string converted to lower case.
Definition at line 13375 of file qstring.cpp.
|
staticprivate |
Definition at line 12190 of file qstring.cpp.
Returns a substring that contains the len characters of this string, starting at position index.
Returns a null string if the string is empty or index is out of range. Returns the whole string from index if index+len exceeds the length of the string.
Definition at line 13265 of file qstring.cpp.
|
static |
A convenience factory function that returns a string representation of the number n.
Definition at line 14249 of file qstring.cpp.
A convenience factory function that returns a string representation of the number n.
Definition at line 14262 of file qstring.cpp.
|
static |
A convenience factory function that returns a string representation of the number n.
Definition at line 14275 of file qstring.cpp.
A convenience factory function that returns a string representation of the number n.
Definition at line 14288 of file qstring.cpp.
|
static |
This static function returns the printed value of n, formatted in the f format with prec precision.
f can be 'f', 'F', 'e', 'E', 'g' or 'G', all of which have the same meaning as for sprintf().
Definition at line 14304 of file qstring.cpp.
|
inline |
Returns TRUE if it is a null string, otherwise FALSE. Thus you can write:
Note that if you say:
Then this will call operator const char*()
, which will do what you want, but rather inefficiently - you may wish to define the macro QT_NO_ASCII_CAST when writing code which you wish to strictly remain Unicode-clean.
When you want the above semantics, use !isNull()
or even !!
:
Definition at line 676 of file qstring.h.
Appends str to the string and returns a reference to the string.
Definition at line 14399 of file qstring.cpp.
Appends c to the string and returns a reference to the string.
Definition at line 14416 of file qstring.cpp.
QString & QString::operator+= | ( | char | c | ) |
Appends c to the string and returns a reference to the string.
Definition at line 14427 of file qstring.cpp.
Assigns a shallow copy of s to this string and returns a reference to this string.
Definition at line 12402 of file qstring.cpp.
QString & QString::operator= | ( | const char * | str | ) |
Assigns a deep copy of str, interpreted as a classic C string, to this string and returns a reference to this string.
If str is 0 a null string is created.
Definition at line 12429 of file qstring.cpp.
Assigns a deep copy of cs, interpreted as a classic C string, to this string and returns a reference to this string.
Definition at line 12415 of file qstring.cpp.
|
inline |
|
inline |
Returns the character at i, or QChar::null if i is beyond the length of the string.
Note: If this QString is not const or const&, the non-const operator[] will be used instead, which will expand the string if i is beyond the length of the string.
Definition at line 494 of file qstring.h.
|
inline |
Returns an object that references the character at i. This reference can then be assigned to, or otherwise used immediately, but becomes invalid once further modifications are made to the string. The QCharRef internal class can be used much like a constant QChar, but if you assign to it, you change the original string (which enlarges and detaches itself). You will get compilation errors if you try to use the result as anything but a QChar.
Definition at line 624 of file qstring.h.
|
inline |
|
private |
Deallocates any space reserved solely by this QString.
Definition at line 12368 of file qstring.cpp.
Removes len characters starting at position index from the string and returns a reference to the string.
If index is too big, nothing happens. If index is valid, but len is too large, the rest of the string is removed.
Definition at line 13633 of file qstring.cpp.
Replaces len characters starting at position index from the string with s, and returns a reference to the string.
If index is too big, nothing is deleted and s is inserted at the end of the string. If index is valid, but len is too large, str replaces the rest of the string.
Definition at line 13665 of file qstring.cpp.
Replaces len characters starting at position index by slen units ot QChar data from s, and returns a reference to the string.
Definition at line 13678 of file qstring.cpp.
Replaces every occurrence of rx in the string with str. Returns a reference to the string.
Examples:
Definition at line 13795 of file qstring.cpp.
Returns a substring that contains the len rightmost characters of the string.
The whole string is returned if len exceeds the length of the string.
Definition at line 13231 of file qstring.cpp.
Returns a string of length width that contains pad characters followed by the string.
If the length of the string exceeds width and truncate is FALSE, then the returned string is a copy of the string. If the length of the string exceeds width and truncate is TRUE, then the returned string is a left(width).
Definition at line 13342 of file qstring.cpp.
Sets the character at position index to c and expands the string if necessary, filling with spaces.
This method is redundant in Qt 2.x, because operator[] will expand the string as necessary.
Definition at line 14321 of file qstring.cpp.
QString & QString::setLatin1 | ( | const char * | str, |
int | len = -1 |
||
) |
Sets this string to str, interpreted as a classic Latin 1 C string. If the len argument is negative (default), it is set to strlen(str).
If str is 0 a null string is created. If str is "" an empty string is created.
Definition at line 14804 of file qstring.cpp.
|
private |
Definition at line 12508 of file qstring.cpp.
|
inline |
Sets the string to the printed value of n and returns a reference to the string.
Definition at line 706 of file qstring.h.
Sets the string to the printed unsigned value of n and returns a reference to the string.
Definition at line 709 of file qstring.h.
|
inline |
Sets the string to the printed value of n and returns a reference to the string.
Definition at line 712 of file qstring.h.
Sets the string to the printed unsigned value of n and returns a reference to the string.
Definition at line 715 of file qstring.h.
QString & QString::setNum | ( | long | n, |
int | base = 10 |
||
) |
Sets the string to the printed value of n and returns a reference to the string.
The value is converted to base notation (default is decimal). The base must be a value from 2 to 36.
Definition at line 14109 of file qstring.cpp.
Sets the string to the printed unsigned value of n and returns a reference to the string.
The value is converted to base notation (default is decimal). The base must be a value from 2 to 36.
Definition at line 14156 of file qstring.cpp.
|
inline |
QString & QString::setNum | ( | double | n, |
char | f = 'g' , |
||
int | prec = 6 |
||
) |
Sets the string to the printed value of n, formatted in the f format with prec precision, and returns a reference to the string.
f can be 'f', 'F', 'e', 'E', 'g' or 'G', all of which have the same meaning as for sprintf().
Definition at line 14208 of file qstring.cpp.
Resizes the string to len unicode characters and copies unicode into the string. If unicode is null, nothing is copied, but the string is resized to len anyway. If len is zero, the string becomes a null string.
Definition at line 14736 of file qstring.cpp.
Resizes the string to len unicode characters and copies unicode_as_ushorts into the string (on some X11 client platforms this will involve a byte-swapping pass).
If unicode is null, nothing is copied, but the string is resized to len anyway. If len is zero, the string becomes a null string.
Definition at line 14776 of file qstring.cpp.
QString QString::simplifyWhiteSpace | ( | ) | const |
Returns a new string that has white space removed from the start and the end, plus any sequence of internal white space replaced with a single space (ASCII 32).
White space means any character for which QChar::isSpace() returns TRUE. This includes ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space).
Definition at line 13482 of file qstring.cpp.
QString & QString::sprintf | ( | const char * | cformat, |
... | |||
) |
Safely builds a formatted string from a format string and an arbitrary list of arguments. The format string supports all the escape sequences of printf() in the standard C library.
The s escape sequence expects a utf8() encoded string. The format string cformat is expected to be in latin1. If you need a unicode format string, use QString::arg() instead. For typesafe string building, with full Unicode support, you can use QTextOStream like this:
For translations, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator, and has Unicode support.
Definition at line 12719 of file qstring.cpp.
QString QString::stripWhiteSpace | ( | ) | const |
Returns a new string that has white space removed from the start and the end.
White space means any character for which QChar::isSpace() returns TRUE. This includes ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space).
Definition at line 13438 of file qstring.cpp.
|
private |
Internal chunk of code to handle the uncommon cases of at() above.
Definition at line 14713 of file qstring.cpp.
double QString::toDouble | ( | bool * | ok = 0 | ) | const |
Returns the string converted to a double
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14071 of file qstring.cpp.
float QString::toFloat | ( | bool * | ok = 0 | ) | const |
Returns the string converted to a float
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14095 of file qstring.cpp.
int QString::toInt | ( | bool * | ok = 0 , |
int | base = 10 |
||
) | const |
Returns the string converted to a int
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14045 of file qstring.cpp.
long QString::toLong | ( | bool * | ok = 0 , |
int | base = 10 |
||
) | const |
Returns the string converted to a long
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 13834 of file qstring.cpp.
short QString::toShort | ( | bool * | ok = 0 , |
int | base = 10 |
||
) | const |
Returns the string converted to a short
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14001 of file qstring.cpp.
Returns the string converted to an unsigned int
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14058 of file qstring.cpp.
Returns the string converted to an unsigned long
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 13948 of file qstring.cpp.
Returns the string converted to an unsigned long
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 13895 of file qstring.cpp.
Returns the string converted to an unsigned short
value.
If ok is non-null, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Definition at line 14019 of file qstring.cpp.
void QString::truncate | ( | uint | newLen | ) |
Truncates the string at position newLen if newLen is less than the current length . Otherwise, nothing happens.
In Qt 1.x, it was possible to "truncate" a string to a longer length. This is no longer possible.
Definition at line 12490 of file qstring.cpp.
const unsigned short * QString::ucs2 | ( | ) | const |
Returns the QString as a zero terminated array of unsigned shorts if the string is not null; otherwise returns zero.
The result remains valid so long as one unmodified copy of the source string exists.
Definition at line 12092 of file qstring.cpp.
|
inline |
This utility function converts l 16-bit characters from uc to ASCII, returning a NUL-terminated string.
The caller is responsible for deleting the string with delete[].
Definition at line 12058 of file qstring.cpp.
QString QString::upper | ( | ) | const |
Returns a new string that is the string converted to upper case.
Definition at line 13404 of file qstring.cpp.
QCString QString::utf8 | ( | ) | const |
Returns the string encoded in UTF8 format.
See QTextCodec for more diverse coding/decoding of Unicode strings.
Definition at line 14507 of file qstring.cpp.
QString QString::visual | ( | int | index = 0 , |
int | len = -1 |
||
) |
This function returns the QString ordered visually. Useful for painting the string or when transforming to a visually ordered encoding.
Definition at line 11705 of file qstring.cpp.
Returns TRUE if the two strings are different, or FALSE if they are equal.
Equivalent to qstrcmp(s1,s2) != 0
.
Definition at line 14850 of file qstring.cpp.
Returns TRUE if the two strings are different, or FALSE if they are equal.
Equivalent to qstrcmp(s1,s2) != 0
.
Definition at line 14872 of file qstring.cpp.
Returns TRUE if the two strings are different, or FALSE if they are equal.
Equivalent to qstrcmp(s1,s2) != 0
.
Definition at line 14875 of file qstring.cpp.
Returns the concatenated string of s1 and s2.
Definition at line 774 of file qstring.h.
Returns the concatenated string of s1 and s2.
Definition at line 782 of file qstring.h.
Returns the concatenated string of s1 and s2.
Definition at line 789 of file qstring.h.
Returns the concatenated string of s and c.
Definition at line 804 of file qstring.h.
Returns the concatenated string of c and s.
Definition at line 819 of file qstring.h.
Returns TRUE if s1 is alphabetically less than s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) < 0
.
Definition at line 14878 of file qstring.cpp.
Returns TRUE if s1 is alphabetically less than s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) < 0
.
Definition at line 14881 of file qstring.cpp.
|
related |
Writes a string to the stream.
Definition at line 15066 of file qstring.cpp.
Returns TRUE if s1 is alphabetically less than or equal to s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) <= 0
.
Definition at line 14884 of file qstring.cpp.
Returns TRUE if s1 is alphabetically less than or equal to s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) <= 0
.
Definition at line 14887 of file qstring.cpp.
Returns TRUE if the two strings are equal, or FALSE if they are different. A null string is different from an empty, non-null string.
Equivalent to qstrcmp(s1,s2) == 0
.
Definition at line 14843 of file qstring.cpp.
Returns TRUE if the two strings are equal, or FALSE if they are different.
Equivalent to qstrcmp(s1,s2) == 0
.
Definition at line 14866 of file qstring.cpp.
Returns TRUE if the two strings are equal, or FALSE if they are different.
Equivalent to qstrcmp(s1,s2) == 0
.
Definition at line 14869 of file qstring.cpp.
Returns TRUE if s1 is alphabetically greater than s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) > 0
.
Definition at line 14890 of file qstring.cpp.
Returns TRUE if s1 is alphabetically greater than s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) > 0
.
Definition at line 14893 of file qstring.cpp.
Returns TRUE if s1 is alphabetically greater than or equal to s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) >= 0
.
Definition at line 14896 of file qstring.cpp.
Returns TRUE if s1 is alphabetically greater than or equal to s2, otherwise FALSE.
Equivalent to qstrcmp(s1,s2) >= 0
.
Definition at line 14899 of file qstring.cpp.
|
friend |
Reads a string from the stream.
Definition at line 15113 of file qstring.cpp.
|
friend |
|
private |
|
static |
|
staticprivate |