Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | Related Functions | List of all members
QString Class Reference

The QString class provides an abstraction of Unicode text and the classic C null-terminated char array (char*). More...

#include <qstring.h>

Inheritance diagram for QString:
QConstString StringImpl

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 ()
 
QStringoperator= (const QString &)
 
QStringoperator= (const char *)
 
QStringoperator= (const QCString &)
 
QStringoperator= (QChar c)
 
QStringoperator= (char c)
 
 QString (const Null &)
 
QStringoperator= (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
 
QStringsprintf (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
 
QStringinsert (uint index, const QString &)
 
QStringinsert (uint index, const QChar *, uint len)
 
QStringinsert (uint index, QChar)
 
QStringinsert (uint index, char c)
 
QStringappend (char)
 
QStringappend (QChar)
 
QStringappend (const QString &)
 
QStringprepend (char)
 
QStringprepend (QChar)
 
QStringprepend (const QString &)
 
QStringremove (uint index, uint len)
 
QStringreplace (uint index, uint len, const QString &)
 
QStringreplace (uint index, uint len, const QChar *, uint clen)
 
QStringreplace (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
 
QStringsetNum (short, int base=10)
 
QStringsetNum (ushort, int base=10)
 
QStringsetNum (int, int base=10)
 
QStringsetNum (uint, int base=10)
 
QStringsetNum (long, int base=10)
 
QStringsetNum (ulong, int base=10)
 
QStringsetNum (float, char f='g', int prec=6)
 
QStringsetNum (double, char f='g', int prec=6)
 
void setExpand (uint index, QChar c)
 
QStringoperator+= (const QString &str)
 
QStringoperator+= (QChar c)
 
QStringoperator+= (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
 
QCharref (uint i)
 
const QCharunicode () const
 
const char * ascii () const
 
const char * latin1 () const
 
const unsigned short * ucs2 () const
 
QCString utf8 () const
 
QCString local8Bit () const
 
bool operator! () const
 
QStringsetUnicode (const QChar *unicode, uint len)
 
QStringsetUnicodeCodes (const ushort *unicode_as_ushorts, uint len)
 
QStringsetLatin1 (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 QCharasciiToUnicode (const char *, uint *len, uint maxlen=(uint)-1)
 
static QCharasciiToUnicode (const QByteArray &, uint *len)
 
static char * unicodeToAscii (const QChar *, uint len)
 
static QStringDatamakeSharedNull ()
 

Private Attributes

QStringDatad
 

Static Private Attributes

static QStringDatashared_null = 0
 

Friends

class QConstString
 
Q_EXPORT QDataStreamoperator>> (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)
 
QDataStreamoperator<< (QDataStream &s, const QString &str)
 

Detailed Description

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.

See also
QChar Shared classes

Definition at line 350 of file qstring.h.

Constructor & Destructor Documentation

QString::QString ( )
inline

Constructs a null string.

See also
isNull()

Definition at line 652 of file qstring.h.

652  :
654 {
655  d->ref();
656 }
void ref()
Definition: qshared.h:49
QStringData * d
Definition: qstring.h:560
static QStringData * makeSharedNull()
Definition: qstring.cpp:12190
static QStringData * shared_null
Definition: qstring.h:561
QString::QString ( QChar  ch)

Constructs a string containing the one character ch.

Definition at line 12234 of file qstring.cpp.

12235 {
12236  d = new QStringData( QT_ALLOC_QCHAR_VEC( 1 ), 1, 1 );
12237  d->unicode[0] = ch;
12238 }
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
QString::QString ( const QString s)

Constructs an implicitly-shared copy of s.

Definition at line 12243 of file qstring.cpp.

12243  :
12244  d(s.d)
12245 {
12246  Q2HELPER(stat_fast_copy++)
12247  d->ref();
12248 }
#define Q2HELPER(x)
Definition: qstring.cpp:12221
QStringData * d
Definition: qstring.h:560
QChar & ref(uint i)
Definition: qstring.h:500
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.

12281 {
12282  Q2HELPER(stat_construct_ba++)
12283  uint l;
12284  QChar *uc = internalAsciiToUnicode(ba,&l);
12285  d = new QStringData(uc,l,l);
12286 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
#define Q2HELPER(x)
Definition: qstring.cpp:12221
QStringData * d
Definition: qstring.h:560
static QChar * internalAsciiToUnicode(const QByteArray &ba, uint *len)
Definition: qstring.cpp:11977
unsigned uint
Definition: qglobal.h:351
QString::QString ( const QCString ba)

Definition at line 12288 of file qstring.cpp.

12289 {
12290  //Q2HELPER(stat_construct_ba++)
12291  //uint l;
12292  //QChar *uc = internalAsciiToUnicode(ba,&l);
12293  //d = new QStringData(uc,l,l);
12294  Q2HELPER(stat_fast_copy++)
12295  QString s = QString::fromUtf8(ba.data(),ba.length());
12296  d = s.d;
12297  d->ref();
12298 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
const char * data() const
Definition: qstring.h:542
#define Q2HELPER(x)
Definition: qstring.cpp:12221
uint length() const
Definition: qstring.h:679
static QString fromUtf8(const char *, int len=-1)
Definition: qstring.cpp:14523
QStringData * d
Definition: qstring.h:560
QChar & ref(uint i)
Definition: qstring.h:500
static QCString * s
Definition: config.cpp:1042
QString::QString ( const QChar unicode,
uint  length 
)

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.

See also
isNull()

Definition at line 12313 of file qstring.cpp.

12314 {
12315  if ( !unicode && !length ) {
12317  d->ref();
12318  } else {
12319  QChar* uc = QT_ALLOC_QCHAR_VEC( length );
12320  if ( unicode )
12321  memcpy(uc, unicode, length*sizeof(QChar));
12322  d = new QStringData(uc,unicode ? length : 0,length);
12323  }
12324 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
void ref()
Definition: qshared.h:49
QStringData * d
Definition: qstring.h:560
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
static QStringData * makeSharedNull()
Definition: qstring.cpp:12190
static QStringData * shared_null
Definition: qstring.h:561
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.

See also
isNull()

Definition at line 12343 of file qstring.cpp.

12344 {
12345  //Q2HELPER(stat_construct_charstar++)
12346  //uint l;
12347  //QChar *uc = internalAsciiToUnicode(str,&l);
12348  //Q2HELPER(stat_construct_charstar_size+=l)
12349  //d = new QStringData(uc,l,l);
12350  Q2HELPER(stat_fast_copy++)
12352  d = s.d;
12353  d->ref();
12354 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
#define Q2HELPER(x)
Definition: qstring.cpp:12221
static QString fromUtf8(const char *, int len=-1)
Definition: qstring.cpp:14523
QStringData * d
Definition: qstring.h:560
QChar & ref(uint i)
Definition: qstring.h:500
static QCString * s
Definition: config.cpp:1042
static QCString str
QString::~QString ( )
inline

Destroys the string and frees the "real" string, if this was the last copy of that string.

Definition at line 658 of file qstring.h.

659 {
660  if ( d->deref() ) {
661  if ( d == shared_null )
662  shared_null = 0;
663  d->deleteSelf();
664  }
665 }
bool deref()
Definition: qshared.h:50
void deleteSelf()
Definition: qstring.cpp:12383
QStringData * d
Definition: qstring.h:560
static QStringData * shared_null
Definition: qstring.h:561
QString::QString ( const Null )
inline

Definition at line 377 of file qstring.h.

377 : d(shared_null) { d->ref(); }
void ref()
Definition: qshared.h:49
QStringData * d
Definition: qstring.h:560
static QStringData * shared_null
Definition: qstring.h:561
QString::QString ( int  size,
bool  dummy 
)
private

Private function.

Constructs a string with preallocated space for size characters.

The string is empty.

See also
isNull()

Definition at line 12260 of file qstring.cpp.

12261 {
12262  if ( size ) {
12263  Q2HELPER(stat_construct_int++)
12264  int l = size;
12265  Q2HELPER(stat_construct_int_size+=l)
12266  QChar* uc = QT_ALLOC_QCHAR_VEC( l );
12267  d = new QStringData( uc, 0, l );
12268  } else {
12269  Q2HELPER(stat_construct_null++)
12271  d->ref();
12272  }
12273 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
#define Q2HELPER(x)
Definition: qstring.cpp:12221
QStringData * d
Definition: qstring.h:560
QChar & ref(uint i)
Definition: qstring.h:500
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
static QStringData * shared_null
Definition: qstring.h:561
QString::QString ( QStringData dd,
bool   
)
inlineprivate

Definition at line 565 of file qstring.h.

565 : d(dd) { }
QStringData * d
Definition: qstring.h:560

Member Function Documentation

QString & QString::append ( char  ch)
inline

Appends ch to the string and returns a reference to the result. Equivalent to operator+=().

Definition at line 703 of file qstring.h.

704 { return operator+=(c); }
QString & operator+=(const QString &str)
Definition: qstring.cpp:14399
QString & QString::append ( QChar  ch)
inline

Appends ch to the string and returns a reference to the result. Equivalent to operator+=().

Definition at line 700 of file qstring.h.

701 { return operator+=(c); }
QString & operator+=(const QString &str)
Definition: qstring.cpp:14399
QString & QString::append ( const QString str)
inline

Appends str to the string and returns a reference to the result. Equivalent to operator+=().

Definition at line 697 of file qstring.h.

698 { return operator+=(s); }
QString & operator+=(const QString &str)
Definition: qstring.cpp:14399
static QCString * s
Definition: config.cpp:1042
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.

12594 {
12595  return arg( QString::number( a, base ), fieldwidth );
12596 }
static QString number(long, int base=10)
Definition: qstring.cpp:14249
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( ulong  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 12603 of file qstring.cpp.

12604 {
12605  return arg( QString::number( a, base ), fieldwidth );
12606 }
static QString number(long, int base=10)
Definition: qstring.cpp:14249
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( int  a,
int  fieldwidth = 0,
int  base = 10 
) const
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.

722 { return arg((long)a, fieldwidth, base); }
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( uint  a,
int  fieldwidth = 0,
int  base = 10 
) const
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 724 of file qstring.h.

725 { return arg((ulong)a, fieldwidth, base); }
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
unsigned long ulong
Definition: qglobal.h:352
QString QString::arg ( short  a,
int  fieldwidth = 0,
int  base = 10 
) const
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.

728 { return arg((long)a, fieldwidth, base); }
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( ushort  a,
int  fieldwidth = 0,
int  base = 10 
) const
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 730 of file qstring.h.

731 { return arg((ulong)a, fieldwidth, base); }
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
unsigned long ulong
Definition: qglobal.h:352
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.

12643 {
12644  QString c;
12645  c += a;
12646  return arg( c, fieldwidth );
12647 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( QChar  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.

Definition at line 12651 of file qstring.cpp.

12652 {
12653  QString c;
12654  c += a;
12655  return arg( c, fieldwidth );
12656 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
QString QString::arg ( const QString a,
int  fieldwidth = 0 
) const

Returns a string equal to this one, but with the lowest-numbered occurrence of i (for a positive integer i) replaced by a.

label.setText( tr("Rename %1 to %2?").arg(oldName).arg(newName) );

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.

Warning
Using arg() for constructing "real" sentences programmatically is likely to lead to translation problems. Inserting objects like numbers or file names is fairly safe.
Relying on spaces to create alignment is prone to lead to translation problems.

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.

See also
QObject::tr()

Definition at line 12553 of file qstring.cpp.

12554 {
12555  int pos, len;
12556  QString r = *this;
12557 
12558  if ( !findArg( pos, len ) ) {
12559  qWarning( "QString::arg(): Argument missing: %s, %s",
12560  (const char *)ascii(), (const char *)ascii() );
12561  // Make sure the text at least appears SOMEWHERE
12562  r += ' ';
12563  pos = r.length();
12564  len = 0;
12565  }
12566 
12567  r.replace( pos, len, a );
12568  if ( fieldwidth < 0 ) {
12569  QString s;
12570  while ( (uint)-fieldwidth > a.length() ) {
12571  s += ' ';
12572  fieldwidth++;
12573  }
12574  r.insert( pos + a.length(), s );
12575  } else if ( fieldwidth ) {
12576  QString s;
12577  while ( (uint)fieldwidth > a.length() ) {
12578  s += ' ';
12579  fieldwidth--;
12580  }
12581  r.insert( pos, s );
12582  }
12583 
12584  return r;
12585 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
const char * ascii() const
Definition: qstring.cpp:14494
uint length() const
Definition: qstring.h:679
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
bool findArg(int &pos, int &len) const
Definition: qstring.cpp:12674
unsigned uint
Definition: qglobal.h:351
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
static QCString * s
Definition: config.cpp:1042
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.

12666 {
12667  return arg( QString::number( a, fmt, prec ), fieldwidth );
12668 }
static QString number(long, int base=10)
Definition: qstring.cpp:14249
QString arg(long a, int fieldwidth=0, int base=10) const
Definition: qstring.cpp:12593
const double a
const char * QString::ascii ( ) const

This functions simply calls latin1() and returns the result.

Definition at line 14494 of file qstring.cpp.

14495 {
14496  return latin1();
14497 }
const char * latin1() const
Definition: qstring.cpp:14457
QChar * QString::asciiToUnicode ( const char *  str,
uint len,
uint  maxlen = (uint)-1 
)
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.

12006 {
12007  QChar* result = 0;
12008  uint l = 0;
12009  if ( str ) {
12010  if ( maxlen != (uint)-1 ) {
12011  while ( l < maxlen && str[l] )
12012  l++;
12013  } else {
12014  // Faster?
12015  l = qstrlen(str);
12016  }
12017  QChar *uc = new QChar[ l ]; // Can't use macro since function is public
12018  result = uc;
12019  uint i = l;
12020  while ( i-- )
12021  *uc++ = *str++;
12022  }
12023  if ( len )
12024  *len = l;
12025  return result;
12026 }
static QCString result
static const int maxlen
Definition: qregexp.cpp:904
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
unsigned uint
Definition: qglobal.h:351
static QCString str
QChar * QString::asciiToUnicode ( const QByteArray ba,
uint len 
)
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.

11958 {
11959  if ( ba.isNull() ) {
11960  if ( len )
11961  *len = 0;
11962  return 0;
11963  }
11964  int l = 0;
11965  while ( l < (int)ba.size() && ba[l] )
11966  l++;
11967  const char* str = ba.data();
11968  QChar *uc = new QChar[ l ]; // Can't use macro, since function is public
11969  QChar *result = uc;
11970  if ( len )
11971  *len = l;
11972  while (l--)
11973  *uc++ = *str++;
11974  return result;
11975 }
bool isNull() const
Definition: qarray.h:68
static QCString result
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
type * data() const
Definition: qarray.h:63
uint size() const
Definition: qarray.h:65
static QCString str
QChar QString::at ( uint  i) const
inline

Returns the character at i, or 0 if i is beyond the length of the string.

Note: If this QString is not const or const&, the non-const at() will be used instead, which will expand the string if i is beyond the length of the string.

Definition at line 492 of file qstring.h.

493  { return i<d->len ? d->unicode[i] : QChar::null; }
uint len
Definition: qstring.h:344
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
QT_STATIC_CONST QChar null
Definition: qstring.h:68
QCharRef QString::at ( uint  i)
inline

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.

623 { return QCharRef(this,i); }
The QCharRef class is a helper class for QString.
Definition: qstring.h:568
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.

11622 {
11623 #ifndef QT_NO_UNICODETABLES
11624  // find base direction
11625  unsigned int pos = 0;
11626  while ((pos < length()) &&
11627  (at(pos) != RLE) &&
11628  (at(pos) != LRE) &&
11629  (at(pos) != RLO) &&
11630  (at(pos) != LRO) &&
11631  (at(pos).direction() > 1) &&
11632  (at(pos).direction() != QChar::DirAL)) // not R and not L
11633  pos++;
11634 
11635  if ((at(pos).direction() == QChar::DirR) ||
11636  (at(pos).direction() == QChar::DirAL) ||
11637  (at(pos) == RLE) ||
11638  (at(pos) == RLO))
11639  return QChar::DirR;
11640 #endif
11641 
11642  return QChar::DirL;
11643 }
static QChar LRO((ushort) 0x202d)
QChar at(uint i) const
Definition: qstring.h:492
uint length() const
Definition: qstring.h:679
static QChar LRE((ushort) 0x202a)
static QChar RLE((ushort) 0x202b)
static QChar RLO((ushort) 0x202e)
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.

14839 {
14840  return ucstrcmp(*this,s);
14841 }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
int QString::compare ( const QString s1,
const QString s2 
)
inlinestatic

Compare s1 to s2 returning an integer less than, equal to, or greater than zero if s1 is, respectively, lexically less than, equal to, or greater than s2.

Definition at line 530 of file qstring.h.

531  { return s1.compare(s2); }
int compare(const QString &s) const
Definition: qstring.cpp:14838
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.

11544 {
11545 #ifndef QT_NO_UNICODETABLES
11546  unsigned int index=0, len;
11547  unsigned int cindex = 0;
11548 
11549  QChar code, head;
11550 
11551  QArray<QChar> dia;
11552 
11553  QString composed = *this;
11554 
11555  while (index < length()) {
11556  code = at(index);
11557  //printf("\n\nligature for 0x%x:\n", code.unicode());
11558  QLigature ligature(code);
11559  ligature.first();
11560  while(ligature.current()) {
11561  if ((len = ligature.match(*this, index)) != 0) {
11562  head = ligature.head();
11563  unsigned short code = head.unicode();
11564  // we exclude Arabic presentation forms A and a few
11565  // other ligatures, which are undefined in most fonts
11566  if(!(code > 0xfb50 && code < 0xfe80) &&
11567  !(code > 0xfb00 && code < 0xfb2a)) {
11568  // joining info is only needed for arabic
11569  if (format(ligature.tag(), *this, index, len)) {
11570  //printf("using ligature 0x%x, len=%d\n",code,len);
11571  // replace letter
11572  composed.replace(cindex, len, QChar(head));
11573  index += len-1;
11574  // we continue searching in case we have a final
11575  // form because medial ones are preferred.
11576  if ( len != 1 || ligature.tag() !=QChar::Final )
11577  break;
11578  }
11579  }
11580  }
11581  ligature.next();
11582  }
11583  cindex++;
11584  index++;
11585  }
11586  *this = composed;
11587 #endif
11588 }
ushort unicode() const
Definition: qstring.h:151
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
Definition: qarray.h:46
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
QChar at(uint i) const
Definition: qstring.h:492
uint length() const
Definition: qstring.h:679
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
CodeOutputInterface * code
QChar QString::constref ( uint  i) const
inline

Equivalent to at(i), this returns the QChar at i by value.

See also
ref()

Definition at line 498 of file qstring.h.

499  { return at(i); }
QChar at(uint i) const
Definition: qstring.h:492
int QString::contains ( QChar  c,
bool  cs = TRUE 
) const

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.

13105 {
13106  int count = 0;
13107  const QChar *uc = unicode();
13108  if ( !uc )
13109  return 0;
13110  int n = length();
13111  if ( cs ) { // case sensitive
13112  while ( n-- )
13113  if ( *uc++ == c )
13114  count++;
13115  } else { // case insensitive
13116  c = c.lower();
13117  while ( n-- ) {
13118  if ( uc->lower() == c )
13119  count++;
13120  uc++;
13121  }
13122  }
13123  return count;
13124 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
std::void_t< T > n
QChar lower() const
Definition: qstring.cpp:11229
const char * cs
int QString::contains ( char  c,
bool  cs = TRUE 
) const
inline

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 424 of file qstring.h.

425  { return contains(QChar(c), cs); }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
int contains(QChar c, bool cs=TRUE) const
Definition: qstring.cpp:13104
const char * cs
int QString::contains ( const char *  str,
bool  cs = TRUE 
) const

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.

13130 {
13131  return contains(QString(str),cs);
13132 }
int contains(QChar c, bool cs=TRUE) const
Definition: qstring.cpp:13104
const char * cs
static QCString str
QString()
Definition: qstring.h:652
int QString::contains ( const QString str,
bool  cs = TRUE 
) const

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".

See also
findRev()

Definition at line 13160 of file qstring.cpp.

13161 {
13162  int count = 0;
13163  const QChar *uc = unicode();
13164  if ( !uc )
13165  return 0;
13166  int len = str.length();
13167  int n = length();
13168  while ( n-- ) { // counts overlapping strings
13169  // ### Doesn't account for length of this - searches over "end"
13170  if ( cs ) {
13171  if ( ucstrncmp( uc, str.unicode(), len ) == 0 )
13172  count++;
13173  } else {
13174  if ( ucstrnicmp(uc, str.unicode(), len) == 0 )
13175  count++;
13176  }
13177  uc++;
13178  }
13179  return count;
13180 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10711
uint length() const
Definition: qstring.h:679
std::void_t< T > n
static int ucstrnicmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10720
const char * cs
int QString::contains ( const QRegExp rx) const

Counts the number of overlapping occurrences of rx in the string.

Example:

QString s = "banana and panama";
QRegExp r = QRegExp("a[nm]a", TRUE, FALSE);
s.contains( r ); // 4 matches
See also
find() findRev()

Definition at line 13759 of file qstring.cpp.

13760 {
13761  if ( isEmpty() )
13762  return rx.match( data() ) < 0 ? 0 : 1;
13763  int count = 0;
13764  int index = -1;
13765  int len = length();
13766  while ( index < len-1 ) { // count overlapping matches
13767  index = rx.match( data(), index+1 );
13768  if ( index < 0 )
13769  break;
13770  count++;
13771  }
13772  return count;
13773 }
bool isEmpty() const
Definition: qstring.h:682
const char * data() const
Definition: qstring.h:542
uint length() const
Definition: qstring.h:679
int match(const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
Definition: qregexp.cpp:649
QString QString::copy ( ) const
inline

Returns a deep copy of this string.

Doing this is redundant in Qt 2.x, since QString is implicitly shared, and so will automatically be deeply copied as necessary.

Definition at line 685 of file qstring.h.

686 { return QString( *this ); }
QString()
Definition: qstring.h:652
const char * QString::data ( ) const
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.

542 { return latin1(); }
const char * latin1() const
Definition: qstring.cpp:14457
void QString::deref ( )
private

Definition at line 12373 of file qstring.cpp.

12374 {
12375  if ( d->deref() ) {
12376  if ( d == shared_null )
12377  shared_null = 0;
12378  delete d;
12379  d = 0; // helps debugging
12380  }
12381 }
bool deref()
Definition: qshared.h:50
QStringData * d
Definition: qstring.h:560
static QStringData * shared_null
Definition: qstring.h:561
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.

12866 {
12867  if ( len < 0 )
12868  len = length();
12869  if ( len == 0 ) {
12870  *this = "";
12871  } else {
12872  deref();
12873  QChar * nd = QT_ALLOC_QCHAR_VEC( len );
12874  d = new QStringData(nd,len,len);
12875  while (len--) *nd++ = c;
12876  }
12877 }
void deref()
Definition: qstring.cpp:12373
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
int QString::find ( QChar  c,
int  index = 0,
bool  cs = TRUE 
) const

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.

12903 {
12904  if ( index < 0 )
12905  index += length();
12906  if ( (uint)index >= length() ) // index outside string
12907  return -1;
12908  register const QChar *uc;
12909  uc = unicode()+index;
12910  int n = length()-index;
12911  if ( cs ) {
12912  while ( n-- && *uc != c )
12913  uc++;
12914  } else {
12915  c = c.lower();
12916  while ( n-- && uc->lower() != c )
12917  uc++;
12918  }
12919  if ( uint(uc - unicode()) >= length() )
12920  return -1;
12921  return (int)(uc - unicode());
12922 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
std::void_t< T > n
QChar lower() const
Definition: qstring.cpp:11229
const char * cs
unsigned uint
Definition: qglobal.h:351
int QString::find ( char  c,
int  index = 0,
bool  cs = TRUE 
) const
inline

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 733 of file qstring.h.

734 { return find(QChar(c), index, cs); }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
const char * cs
int QString::find ( const QString str,
int  index = 0,
bool  cs = TRUE 
) const

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.

12936 {
12937  /*
12938  We use some weird hashing for efficiency's sake. Instead of
12939  comparing strings, we compare the hash value of str with that of
12940  a part of this QString. Only if that matches, we call ucstrncmp
12941  or ucstrnicmp.
12942 
12943  The hash value of a string is the sum of the cells of its
12944  QChars.
12945  */
12946  if ( index < 0 )
12947  index += length();
12948  int lstr = str.length();
12949  int lthis = length() - index;
12950  if ( (uint)lthis > length() )
12951  return -1;
12952  int delta = lthis - lstr;
12953  if ( delta < 0 )
12954  return -1;
12955 
12956  const QChar *uthis = unicode() + index;
12957  const QChar *ustr = str.unicode();
12958  uint hthis = 0;
12959  uint hstr = 0;
12960  int i;
12961  if ( cs ) {
12962  for ( i = 0; i < lstr; i++ ) {
12963  hthis += uthis[i].cell();
12964  hstr += ustr[i].cell();
12965  }
12966  i = 0;
12967  while ( TRUE ) {
12968  if ( hthis == hstr && ucstrncmp(uthis + i, ustr, lstr) == 0 )
12969  return index + i;
12970  if ( i == delta )
12971  return -1;
12972  hthis += uthis[i + lstr].cell();
12973  hthis -= uthis[i].cell();
12974  i++;
12975  }
12976  } else {
12977  for ( i = 0; i < lstr; i++ ) {
12978  hthis += uthis[i].lower().cell();
12979  hstr += ustr[i].lower().cell();
12980  }
12981  i = 0;
12982  while ( TRUE ) {
12983  if ( hthis == hstr && ucstrnicmp(uthis + i, ustr, lstr) == 0 )
12984  return index + i;
12985  if ( i == delta )
12986  return -1;
12987  hthis += uthis[i + lstr].lower().cell();
12988  hthis -= uthis[i].lower().cell();
12989  i++;
12990  }
12991  }
12992 #if defined(Q_SPURIOUS_NON_VOID_WARNING)
12993  return -1;
12994 #endif
12995 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uchar & cell()
Definition: qstring.h:167
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10711
uint length() const
Definition: qstring.h:679
static int ucstrnicmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10720
QChar lower() const
Definition: qstring.cpp:11229
const char * cs
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
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.

See also
findRev() replace() contains()

Definition at line 13713 of file qstring.cpp.

13714 {
13715  if ( index < 0 )
13716  index += length();
13717  return rx.match( data(), index );
13718 }
const char * data() const
Definition: qstring.h:542
uint length() const
Definition: qstring.h:679
int match(const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
Definition: qregexp.cpp:649
int QString::find ( const char *  str,
int  index = 0 
) const
inline

Equivalent to find(QString(str), index).

Definition at line 741 of file qstring.h.

742 { return find(QString::fromLatin1(str), index); }
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
static QCString str
bool QString::findArg ( int &  pos,
int &  len 
) const
private

Just 1-digit arguments.

Definition at line 12674 of file qstring.cpp.

12675 {
12676  char lowest=0;
12677  for (uint i=0; i<length(); i++) {
12678  if ( at(i) == '%' && i+1<length() ) {
12679  char dig = at(i+1);
12680  if ( dig >= '0' && dig <= '9' ) {
12681  if ( !lowest || dig < lowest ) {
12682  lowest = dig;
12683  pos = i;
12684  len = 2;
12685  }
12686  }
12687  }
12688  }
12689  return lowest != 0;
12690 }
QChar at(uint i) const
Definition: qstring.h:492
uint length() const
Definition: qstring.h:679
unsigned uint
Definition: qglobal.h:351
int QString::findRev ( QChar  c,
int  index = -1,
bool  cs = TRUE 
) const

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.

13022 {
13023  QString t( c );
13024  return findRev( t, index, cs );
13025 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
const char * cs
int QString::findRev ( char  c,
int  index = -1,
bool  cs = TRUE 
) const
inline

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.

737 { return findRev( QChar(c), index, cs ); }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
const char * cs
int QString::findRev ( const QString str,
int  index = -1,
bool  cs = TRUE 
) const

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.

13040 {
13041  /*
13042  See QString::find() for explanations.
13043  */
13044  int lthis = length();
13045  if ( index < 0 )
13046  index += lthis;
13047 
13048  int lstr = str.length();
13049  int delta = lthis - lstr;
13050  if ( index < 0 || index > lthis || delta < 0 )
13051  return -1;
13052  if ( index > delta )
13053  index = delta;
13054 
13055  const QChar *uthis = unicode();
13056  const QChar *ustr = str.unicode();
13057  uint hthis = 0;
13058  uint hstr = 0;
13059  int i;
13060  if ( cs ) {
13061  for ( i = 0; i < lstr; i++ ) {
13062  hthis += uthis[index + i].cell();
13063  hstr += ustr[i].cell();
13064  }
13065  i = index;
13066  while ( TRUE ) {
13067  if ( hthis == hstr && ucstrncmp(uthis + i, ustr, lstr) == 0 )
13068  return i;
13069  if ( i == 0 )
13070  return -1;
13071  i--;
13072  hthis -= uthis[i + lstr].cell();
13073  hthis += uthis[i].cell();
13074  }
13075  } else {
13076  for ( i = 0; i < lstr; i++ ) {
13077  hthis += uthis[index + i].lower().cell();
13078  hstr += ustr[i].lower().cell();
13079  }
13080  i = index;
13081  while ( TRUE ) {
13082  if ( hthis == hstr && ucstrnicmp(uthis + i, ustr, lstr) == 0 )
13083  return i;
13084  if ( i == 0 )
13085  return -1;
13086  i--;
13087  hthis -= uthis[i + lstr].lower().cell();
13088  hthis += uthis[i].lower().cell();
13089  }
13090  }
13091 #if defined(Q_SPURIOUS_NON_VOID_WARNING)
13092  return -1;
13093 #endif
13094 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uchar & cell()
Definition: qstring.h:167
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10711
uint length() const
Definition: qstring.h:679
static int ucstrnicmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:10720
QChar lower() const
Definition: qstring.cpp:11229
const char * cs
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
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.

See also
find()

Definition at line 13732 of file qstring.cpp.

13733 {
13734  if ( index < 0 ) // neg index ==> start from end
13735  index += length();
13736  if ( (uint)index > length() ) // bad index
13737  return -1;
13738  while( index >= 0 ) {
13739  if ( rx.match( data(), index ) == index )
13740  return index;
13741  index--;
13742  }
13743  return -1;
13744 }
const char * data() const
Definition: qstring.h:542
uint length() const
Definition: qstring.h:679
int match(const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
Definition: qregexp.cpp:649
unsigned uint
Definition: qglobal.h:351
int QString::findRev ( const char *  str,
int  index = -1 
) const
inline

Equivalent to findRev(QString(str), index).

Definition at line 744 of file qstring.h.

745 { return findRev(QString::fromLatin1(str), index); }
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
static QCString str
QString QString::fromLatin1 ( const char *  chars,
int  len = -1 
)
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.

14540 {
14541  uint l;
14542  QChar *uc;
14543  if ( len < 0 ) {
14544  uc = internalAsciiToUnicode(chars,&l);
14545  } else {
14546  uc = internalAsciiToUnicode(chars,&l,len);
14547  }
14548  return QString(new QStringData(uc,l,l), TRUE);
14549 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
static QChar * internalAsciiToUnicode(const QByteArray &ba, uint *len)
Definition: qstring.cpp:11977
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
QString()
Definition: qstring.h:652
QString QString::fromLocal8Bit ( const char *  local8Bit,
int  len = -1 
)
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.

14606 {
14607 #ifdef QT_NO_TEXTCODEC
14608  return fromLatin1( local8Bit, len );
14609 #else
14610 
14611  if ( !local8Bit )
14612  return QString::null;
14613 #ifdef _WS_X11_
14614  static QTextCodec* codec = QTextCodec::codecForLocale();
14615  if ( len < 0 ) len = qstrlen(local8Bit);
14616  return codec
14617  ? codec->toUnicode(local8Bit, len)
14619 #endif
14620 #ifdef _WS_MAC_
14621  static QTextCodec* codec = QTextCodec::codecForLocale();
14622  if ( len < 0 ) len = qstrlen(local8Bit);
14623  return codec
14624  ? codec->toUnicode(local8Bit, len)
14626 #endif
14627 // Should this be OS_WIN32?
14628 #ifdef _WS_WIN_
14629  if ( len >= 0 ) {
14630  QCString s(local8Bit,len+1);
14631  return qt_winMB2QString(s);
14632  }
14633  return qt_winMB2QString( local8Bit );
14634 #endif
14635 #ifdef _WS_QWS_
14636  return fromUtf8(local8Bit,len);
14637 #endif
14638 #endif // QT_NO_TEXTCODEC
14639 }
static QTextCodec * codecForLocale()
Definition: qtextcodec.cpp:542
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
QCString local8Bit() const
Definition: qstring.cpp:14569
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
virtual QString toUnicode(const char *chars, int len) const
Definition: qtextcodec.cpp:757
static QString fromUtf8(const char *, int len=-1)
Definition: qstring.cpp:14523
static const Null null
Definition: qstring.h:376
Provides conversion between text encodings.
Definition: qtextcodec.h:62
static QCString * s
Definition: config.cpp:1042
QString QString::fromUcs2 ( const unsigned short *  str)
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.

See also
isNull()

Definition at line 12119 of file qstring.cpp.

12120 {
12121  if ( !str ) {
12122  return QString::null;
12123  } else {
12124  int length = 0;
12125  while ( str[length] != 0 )
12126  length++;
12127  QChar* uc = QT_ALLOC_QCHAR_VEC( length );
12128  memcpy( uc, str, length*sizeof(QChar) );
12129  return QString( new QStringData( uc, length, length ), TRUE );
12130  }
12131 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
static const Null null
Definition: qstring.h:376
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
const bool TRUE
Definition: qglobal.h:371
static QCString str
QString()
Definition: qstring.h:652
QString QString::fromUtf8 ( const char *  utf8,
int  len = -1 
)
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.

14524 {
14525  static QTextCodec* codec = QTextCodec::codecForMib(106);
14526  if ( len < 0 ) len = qstrlen(utf8);
14527  return codec
14528  ? codec->toUnicode(utf8, len)
14529  : QString::fromLatin1(utf8, len);
14530 }
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
virtual QString toUnicode(const char *chars, int len) const
Definition: qtextcodec.cpp:757
static QTextCodec * codecForMib(int mib)
Definition: qtextcodec.cpp:354
Provides conversion between text encodings.
Definition: qtextcodec.h:62
QCString utf8() const
Definition: qstring.cpp:14507
QString & QString::insert ( uint  index,
const QString s 
)

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.

QString s = "I like fish";
s.insert( 2, "don't "); // s == "I don't like fish"
s = "x";
s.insert( 3, "yz" ); // s == "x yz"

Definition at line 13523 of file qstring.cpp.

13524 {
13525  // the sub function takes care of &s == this case.
13526  return insert( index, s.unicode(), s.length() );
13527 }
const QChar * unicode() const
Definition: qstring.h:508
uint length() const
Definition: qstring.h:679
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
QString & QString::insert ( uint  index,
const QChar s,
uint  len 
)

Insert len units of QChar data from s into the string before position index.

Definition at line 13534 of file qstring.cpp.

13535 {
13536  if ( len == 0 )
13537  return *this;
13538  uint olen = length();
13539  int nlen = olen + len;
13540 
13541  int df = (int)(s - d->unicode); // ### pointer subtraction, cast down to int
13542  if ( df >= 0 && (uint)df < d->maxl ) {
13543  // Part of me - take a copy.
13544  QChar *tmp = QT_ALLOC_QCHAR_VEC( len );
13545  memcpy(tmp,s,len*sizeof(QChar));
13546  insert(index,tmp,len);
13547  QT_DELETE_QCHAR_VEC( tmp );
13548  return *this;
13549  }
13550 
13551  if ( index >= olen ) { // insert after end of string
13552  setLength( len+index );
13553  int n = index-olen;
13554  QChar* uc = d->unicode+olen;
13555  while (n--)
13556  *uc++ = ' ';
13557  memcpy( d->unicode+index, s, sizeof(QChar)*len );
13558  } else { // normal insert
13559  setLength( nlen );
13560  memmove( d->unicode+index+len, unicode()+index,
13561  sizeof(QChar)*(olen-index) );
13562  memcpy( d->unicode+index, s, sizeof(QChar)*len );
13563  }
13564  return *this;
13565 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint maxl
Definition: qstring.h:345
uint length() const
Definition: qstring.h:679
std::void_t< T > n
string tmp
Definition: languages.py:63
QStringData * d
Definition: qstring.h:560
#define QT_DELETE_QCHAR_VEC(P)
Definition: qstring.cpp:11947
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
unsigned uint
Definition: qglobal.h:351
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
QString & QString::insert ( uint  index,
QChar  c 
)

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.

Example:

QString s = "Ys";
s.insert( 1, 'e' ); // s == "Yes"
s.insert( 3, '!'); // s == "Yes!"
See also
remove(), replace()

Definition at line 13584 of file qstring.cpp.

13585 {
13586  QString s( c );
13587  return insert( index, s );
13588 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
static QCString * s
Definition: config.cpp:1042
QString & QString::insert ( uint  index,
char  c 
)
inline

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 448 of file qstring.h.

448 { return insert(index,QChar(c)); }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
bool QString::isEmpty ( ) const
inline

Returns TRUE if the string is empty, i.e. if length() == 0. An empty string is not always a null string.

See example in isNull().

See also
isNull(), length()

Definition at line 682 of file qstring.h.

683 { return length() == 0; }
uint length() const
Definition: qstring.h:679
bool QString::isNull ( ) const
inline

Returns TRUE if the string is null. A null string is also an empty string.

Example:

QString a; // a.unicode() == 0, a.length() == 0
QString b = ""; // b.unicode() == "", b.length() == 0
a.isNull(); // TRUE, because a.unicode() == 0
a.isEmpty(); // TRUE, because a.length() == 0
b.isNull(); // FALSE, because b.unicode() != 0
b.isEmpty(); // TRUE, because b.length() == 0
See also
isEmpty(), length()

Definition at line 379 of file qstring.h.

379 { return d == shared_null; }
QStringData * d
Definition: qstring.h:560
static QStringData * shared_null
Definition: qstring.h:561
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.

See also
utf8(), local8Bit()

Definition at line 14457 of file qstring.cpp.

14458 {
14459  if ( d->ascii ) {
14460  if ( d->dirtyascii )
14461  delete [] d->ascii;
14462  else
14463  return d->ascii;
14464  }
14465  Q2HELPER(stat_get_ascii++)
14466  Q2HELPER(stat_get_ascii_size+=d->len)
14467  static QTextCodec* codec = QTextCodec::codecForMib(106);
14468  if (codec) // we use utf8 coding also for latin1 if possible
14469  {
14470  QCString utf8str(codec->fromUnicode(*this));
14471  d->ascii = new char[utf8str.length()+1];
14472  if (utf8str.isEmpty())
14473  {
14474  d->ascii[0]='\0'; // make empty string
14475  }
14476  else // copy string
14477  {
14478  qstrcpy(d->ascii,utf8str.data());
14479  }
14480  }
14481  else // fall back to latin1
14482  {
14483  d->ascii = unicodeToAscii( d->unicode, d->len );
14484  }
14485  QCString utf8str(utf8());
14486  d->dirtyascii = 0;
14487  return d->ascii;
14488 }
char * ascii
Definition: qstring.h:343
uint len
Definition: qstring.h:344
static char * unicodeToAscii(const QChar *, uint len)
Definition: qstring.cpp:12058
#define Q2HELPER(x)
Definition: qstring.cpp:12221
QStringData * d
Definition: qstring.h:560
uint dirtyascii
Definition: qstring.h:346
QChar * unicode
Definition: qstring.h:342
Q_EXPORT char * qstrcpy(char *dst, const char *src)
Definition: qcstring.h:87
Provides conversion between text encodings.
Definition: qtextcodec.h:62
QCString utf8() const
Definition: qstring.cpp:14507
if(!yymsg) yymsg
QString QString::left ( uint  len) const

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.

Example:

QString s = "Pineapple";
QString t = s.left( 4 ); // t == "Pine"
See also
right(), mid(), isEmpty()

Definition at line 13199 of file qstring.cpp.

13200 {
13201  if ( isEmpty() ) {
13202  return QString();
13203  } else if ( len == 0 ) { // ## just for 1.x compat:
13204  return QString::fromLatin1("");
13205  } else if ( len > length() ) {
13206  return *this;
13207  } else {
13208  QString s( len, TRUE );
13209  memcpy( s.d->unicode, d->unicode, len*sizeof(QChar) );
13210  s.d->len = len;
13211  return s;
13212  }
13213 }
bool isEmpty() const
Definition: qstring.h:682
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
QString()
Definition: qstring.h:652
QString QString::leftJustify ( uint  width,
QChar  fill = ' ',
bool  truncate = FALSE 
) const

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).

Example:

QString s("apple");
QString t = s.leftJustify(8, '.'); // t == "apple..."
See also
rightJustify()

Definition at line 13303 of file qstring.cpp.

13304 {
13305  QString result;
13306  int len = length();
13307  int padlen = width - len;
13308  if ( padlen > 0 ) {
13309  result.setLength(len+padlen);
13310  if ( len )
13311  memcpy( result.d->unicode, unicode(), sizeof(QChar)*len );
13312  QChar* uc = result.d->unicode + len;
13313  while (padlen--)
13314  *uc++ = fill;
13315  } else {
13316  if ( truncate )
13317  result = left( width );
13318  else
13319  result = *this;
13320  }
13321  return result;
13322 }
const QChar * unicode() const
Definition: qstring.h:508
static QCString result
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
void fill(QChar c, int len=-1)
Definition: qstring.cpp:12865
QString left(uint len) const
Definition: qstring.cpp:13199
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
void truncate(uint pos)
Definition: qstring.cpp:12490
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
uint QString::length ( ) const
inline

Returns the length of the string.

Null strings and empty strings have zero length.

See also
isNull(), isEmpty()

Definition at line 679 of file qstring.h.

680 { return d->len; }
uint len
Definition: qstring.h:344
QStringData * d
Definition: qstring.h:560
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.

See also
QString::fromLocal8Bit(), latin1(), utf8()

Definition at line 14569 of file qstring.cpp.

14570 {
14571 #ifdef QT_NO_TEXTCODEC
14572  return latin1();
14573 #else
14574 #ifdef _WS_X11_
14575  static QTextCodec* codec = QTextCodec::codecForLocale();
14576  return codec
14577  ? codec->fromUnicode(*this)
14578  : QCString(latin1());
14579 #endif
14580 #ifdef _WS_MAC_
14581  static QTextCodec* codec = QTextCodec::codecForLocale();
14582  return codec
14583  ? codec->fromUnicode(*this)
14584  : QCString(latin1());
14585 #endif
14586 #ifdef _WS_WIN_
14587  return qt_winQString2MB( *this );
14588 #endif
14589 #ifdef _WS_QWS_
14590  return utf8(); // ##### if there is ANY 8 bit format supported?
14591 #endif
14592 #endif
14593 }
static QTextCodec * codecForLocale()
Definition: qtextcodec.cpp:542
virtual QCString fromUnicode(const QString &uc, int &lenInOut) const
Definition: qtextcodec.cpp:783
const char * latin1() const
Definition: qstring.cpp:14457
Provides conversion between text encodings.
Definition: qtextcodec.h:62
QCString utf8() const
Definition: qstring.cpp:14507
QString QString::lower ( ) const

Returns a new string that is the string converted to lower case.

Example:

QString s("TeX");
QString t = s.lower(); // t == "tex"
See also
upper()

Definition at line 13375 of file qstring.cpp.

13376 {
13377  QString s(*this);
13378  int l=length();
13379  if ( l ) {
13380  s.real_detach(); // could do this only when we find a change
13381  register QChar *p=s.d->unicode;
13382  if ( p ) {
13383  while ( l-- ) {
13384  *p = p->lower();
13385  p++;
13386  }
13387  }
13388  }
13389  return s;
13390 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
QChar lower() const
Definition: qstring.cpp:11229
static QCString * s
Definition: config.cpp:1042
QStringData * QString::makeSharedNull ( )
staticprivate

Definition at line 12190 of file qstring.cpp.

12191 {
12192  return shared_null=new QStringData;
12193 }
static QStringData * shared_null
Definition: qstring.h:561
QString QString::mid ( uint  index,
uint  len = 0xffffffff 
) const

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.

Example:

QString s = "Five pineapples";
QString t = s.mid( 5, 4 ); // t == "pine"
See also
left(), right()

Definition at line 13265 of file qstring.cpp.

13266 {
13267  uint slen = length();
13268  if ( isEmpty() || index >= slen ) {
13269  return QString();
13270  } else if ( len == 0 ) { // ## just for 1.x compat:
13271  return QString::fromLatin1("");
13272  } else {
13273  if ( len > slen-index )
13274  len = slen - index;
13275  if ( index == 0 && len == length() )
13276  return *this;
13277  register const QChar *p = unicode()+index;
13278  QString s( len, TRUE );
13279  memcpy( s.d->unicode, p, len*sizeof(QChar) );
13280  s.d->len = len;
13281  return s;
13282  }
13283 }
const QChar * unicode() const
Definition: qstring.h:508
bool isEmpty() const
Definition: qstring.h:682
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
QString()
Definition: qstring.h:652
QString QString::number ( long  n,
int  base = 10 
)
static

A convenience factory function that returns a string representation of the number n.

See also
setNum()

Definition at line 14249 of file qstring.cpp.

14250 {
14251  QString s;
14252  s.setNum( n, base );
14253  return s;
14254 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
static QCString * s
Definition: config.cpp:1042
QString QString::number ( ulong  n,
int  base = 10 
)
static

A convenience factory function that returns a string representation of the number n.

See also
setNum()

Definition at line 14262 of file qstring.cpp.

14263 {
14264  QString s;
14265  s.setNum( n, base );
14266  return s;
14267 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
static QCString * s
Definition: config.cpp:1042
QString QString::number ( int  n,
int  base = 10 
)
static

A convenience factory function that returns a string representation of the number n.

See also
setNum()

Definition at line 14275 of file qstring.cpp.

14276 {
14277  QString s;
14278  s.setNum( n, base );
14279  return s;
14280 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
static QCString * s
Definition: config.cpp:1042
QString QString::number ( uint  n,
int  base = 10 
)
static

A convenience factory function that returns a string representation of the number n.

See also
setNum()

Definition at line 14288 of file qstring.cpp.

14289 {
14290  QString s;
14291  s.setNum( n, base );
14292  return s;
14293 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
static QCString * s
Definition: config.cpp:1042
QString QString::number ( double  n,
char  f = 'g',
int  prec = 6 
)
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().

See also
setNum()

Definition at line 14304 of file qstring.cpp.

14305 {
14306  QString s;
14307  s.setNum( n, f, prec );
14308  return s;
14309 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
static QCString * s
Definition: config.cpp:1042
bool QString::operator! ( ) const
inline

Returns TRUE if it is a null string, otherwise FALSE. Thus you can write:

QString name = getName();
if ( !name )
name = "Rodney";

Note that if you say:

QString name = getName();
if ( name )
doSomethingWith(name);

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 !!:

QString name = getName();
if ( !!name )
doSomethingWith(name);

Definition at line 676 of file qstring.h.

677 { return isNull(); }
bool isNull() const
Definition: qstring.h:379
QString & QString::operator+= ( const QString str)

Appends str to the string and returns a reference to the string.

Definition at line 14399 of file qstring.cpp.

14400 {
14401  uint len1 = length();
14402  uint len2 = str.length();
14403  if ( len2 ) {
14404  setLength(len1+len2);
14405  memcpy( d->unicode+len1, str.unicode(), sizeof(QChar)*len2 );
14406  } else if ( isNull() && !str.isNull() ) { // ## just for 1.x compat:
14407  *this = fromLatin1("");
14408  }
14409  return *this;
14410 }
const QChar * unicode() const
Definition: qstring.h:508
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
bool isNull() const
Definition: qstring.h:379
void setLength(uint pos)
Definition: qstring.cpp:12508
unsigned uint
Definition: qglobal.h:351
QString & QString::operator+= ( QChar  c)

Appends c to the string and returns a reference to the string.

Definition at line 14416 of file qstring.cpp.

14417 {
14418  setLength(length()+1);
14419  d->unicode[length()-1] = c;
14420  return *this;
14421 }
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
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.

14428 {
14429  setLength(length()+1);
14430  d->unicode[length()-1] = c;
14431  return *this;
14432 }
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
QString & QString::operator= ( const QString s)

Assigns a shallow copy of s to this string and returns a reference to this string.

Definition at line 12402 of file qstring.cpp.

12403 {
12404  Q2HELPER(stat_fast_copy++)
12405  s.d->ref();
12406  deref();
12407  d = s.d;
12408  return *this;
12409 }
void deref()
Definition: qstring.cpp:12373
#define Q2HELPER(x)
Definition: qstring.cpp:12221
QStringData * d
Definition: qstring.h:560
QChar & ref(uint i)
Definition: qstring.h:500
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.

See also
isNull()

Definition at line 12429 of file qstring.cpp.

12430 {
12431  return setLatin1(str);
12432 }
QString & setLatin1(const char *, int len=-1)
Definition: qstring.cpp:14804
static QCString str
QString & QString::operator= ( const QCString cs)

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.

12416 {
12417  return setLatin1(cs);
12418 }
QString & setLatin1(const char *, int len=-1)
Definition: qstring.cpp:14804
QString & QString::operator= ( QChar  c)
inline

Sets the string to contain just the single character c.

Definition at line 667 of file qstring.h.

668 { return *this = QString(c); }
QString()
Definition: qstring.h:652
QString & QString::operator= ( char  c)
inline

Sets the string to contain just the single character c.

Definition at line 670 of file qstring.h.

671 { return *this = QString(QChar(c)); }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
QString()
Definition: qstring.h:652
QString& QString::operator= ( const Null )
inline

Definition at line 378 of file qstring.h.

378 { *this = QString(); return *this; }
QString()
Definition: qstring.h:652
QChar QString::operator[] ( int  i) const
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.

494 { return at((uint)i); }
QChar at(uint i) const
Definition: qstring.h:492
unsigned uint
Definition: qglobal.h:351
QCharRef QString::operator[] ( int  i)
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.

624 { return at((uint)i); }
QChar at(uint i) const
Definition: qstring.h:492
unsigned uint
Definition: qglobal.h:351
QString & QString::prepend ( char  ch)
inline

Prepends ch to the string and returns a reference to the result.

See also
insert()

Definition at line 694 of file qstring.h.

695 { return insert(0,c); }
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
QString & QString::prepend ( QChar  ch)
inline

Prepends ch to the string and returns a reference to the result.

See also
insert()

Definition at line 691 of file qstring.h.

692 { return insert(0,c); }
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
QString & QString::prepend ( const QString s)
inline

Prepend s to the string. Equivalent to insert(0,s).

See also
insert()

Definition at line 688 of file qstring.h.

689 { return insert(0,s); }
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
void QString::real_detach ( )
private

Deallocates any space reserved solely by this QString.

Definition at line 12368 of file qstring.cpp.

12369 {
12370  setLength( length() );
12371 }
uint length() const
Definition: qstring.h:679
void setLength(uint pos)
Definition: qstring.cpp:12508
QChar & QString::ref ( uint  i)
inline

Returns the QChar at i by reference.

See also
constref()

Definition at line 500 of file qstring.h.

501  { // Optimized for easy-inlining by simple compilers.
502  if (d->count!=1 || i>=d->len)
503  subat(i);
504  d->dirtyascii=1;
505  return d->unicode[i];
506  }
uint len
Definition: qstring.h:344
uint count
Definition: qshared.h:51
void subat(uint)
Definition: qstring.cpp:14713
QStringData * d
Definition: qstring.h:560
uint dirtyascii
Definition: qstring.h:346
QChar * unicode
Definition: qstring.h:342
QString & QString::remove ( uint  index,
uint  len 
)

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.

QString s = "Montreal";
s.remove( 1, 4 );
// s == "Meal"
See also
insert(), replace()

Definition at line 13633 of file qstring.cpp.

13634 {
13635  uint olen = length();
13636  if ( index + len >= olen ) { // range problems
13637  if ( index < olen ) { // index ok
13638  setLength( index );
13639  }
13640  } else if ( len != 0 ) {
13641  real_detach();
13642  memmove( d->unicode+index, d->unicode+index+len,
13643  sizeof(QChar)*(olen-index-len) );
13644  setLength( olen-len );
13645  }
13646  return *this;
13647 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
unsigned uint
Definition: qglobal.h:351
void real_detach()
Definition: qstring.cpp:12368
QString & QString::replace ( uint  index,
uint  len,
const QString s 
)

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.

QString s = "Say yes!";
s.replace( 4, 3, "NO" ); // s == "Say NO!"
See also
insert(), remove()

Definition at line 13665 of file qstring.cpp.

13666 {
13667  return replace( index, len, s.unicode(), s.length() );
13668 }
const QChar * unicode() const
Definition: qstring.h:508
uint length() const
Definition: qstring.h:679
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
QString & QString::replace ( uint  index,
uint  len,
const QChar s,
uint  slen 
)

Replaces len characters starting at position index by slen units ot QChar data from s, and returns a reference to the string.

See also
insert(), remove()

Definition at line 13678 of file qstring.cpp.

13679 {
13680  if ( len == slen && index + len <= length() ) {
13681  // Optimized common case: replace without size change
13682  real_detach();
13683  memcpy( d->unicode+index, s, len*sizeof(QChar) );
13684  } else {
13685  int df = (int)(s - d->unicode); // ### pointer subtraction, cast down to int
13686  if ( df >= 0 && (uint)df < d->maxl ) {
13687  // Part of me - take a copy.
13688  QChar *tmp = QT_ALLOC_QCHAR_VEC( slen );
13689  memcpy(tmp,s,slen*sizeof(QChar));
13690  replace(index,len,tmp,slen);
13691  QT_DELETE_QCHAR_VEC( tmp );
13692  return *this;
13693  }
13694 
13695  remove( index, len );
13696  insert( index, s, slen );
13697  }
13698  return *this;
13699 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint maxl
Definition: qstring.h:345
uint length() const
Definition: qstring.h:679
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
string tmp
Definition: languages.py:63
QStringData * d
Definition: qstring.h:560
#define QT_DELETE_QCHAR_VEC(P)
Definition: qstring.cpp:11947
QChar * unicode
Definition: qstring.h:342
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
unsigned uint
Definition: qglobal.h:351
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
void real_detach()
Definition: qstring.cpp:12368
QString & QString::replace ( const QRegExp rx,
const QString str 
)

Replaces every occurrence of rx in the string with str. Returns a reference to the string.

Examples:

QString s = "banana";
s.replace( QRegExp("a.*a"), "" ); // becomes "b"
QString s = "banana";
s.replace( QRegExp("^[bn]a"), " " ); // becomes " nana"
QString s = "banana";
s.replace( QRegExp("^[bn]a"), "" ); // NOTE! becomes ""
See also
find() findRev()

Definition at line 13795 of file qstring.cpp.

13796 {
13797  if ( isEmpty() )
13798  return *this;
13799  int index = 0;
13800  int slen = str.length();
13801  int len;
13802  while ( index < (int)length() ) {
13803  index = rx.match( data(), index, &len, FALSE );
13804  if ( index >= 0 ) {
13805  replace( index, len, str );
13806  index += slen;
13807  if ( !len )
13808  break; // Avoid infinite loop on 0-length matches, e.g. [a-z]*
13809  }
13810  else
13811  break;
13812  }
13813  return *this;
13814 }
bool isEmpty() const
Definition: qstring.h:682
const bool FALSE
Definition: qglobal.h:370
const char * data() const
Definition: qstring.h:542
uint length() const
Definition: qstring.h:679
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
int match(const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
Definition: qregexp.cpp:649
QString QString::right ( uint  len) const

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.

Example:

QString s = "Pineapple";
QString t = s.right( 5 ); // t == "apple"
See also
left(), mid(), isEmpty()

Definition at line 13231 of file qstring.cpp.

13232 {
13233  if ( isEmpty() ) {
13234  return QString();
13235  } else if ( len == 0 ) { // ## just for 1.x compat:
13236  return QString::fromLatin1("");
13237  } else {
13238  uint l = length();
13239  if ( len > l )
13240  len = l;
13241  QString s( len, TRUE );
13242  memcpy( s.d->unicode, d->unicode+(l-len), len*sizeof(QChar) );
13243  s.d->len = len;
13244  return s;
13245  }
13246 }
bool isEmpty() const
Definition: qstring.h:682
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
QString()
Definition: qstring.h:652
QString QString::rightJustify ( uint  width,
QChar  fill = ' ',
bool  truncate = FALSE 
) const

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).

Example:

QString s("pie");
QString t = s.rightJustify(8, '.'); // t == ".....pie"
See also
leftJustify()

Definition at line 13342 of file qstring.cpp.

13343 {
13344  QString result;
13345  int len = length();
13346  int padlen = width - len;
13347  if ( padlen > 0 ) {
13348  result.setLength( len+padlen );
13349  QChar* uc = result.d->unicode;
13350  while (padlen--)
13351  *uc++ = fill;
13352  if ( len )
13353  memcpy( uc, unicode(), sizeof(QChar)*len );
13354  } else {
13355  if ( truncate )
13356  result = left( width );
13357  else
13358  result = *this;
13359  }
13360  return result;
13361 }
const QChar * unicode() const
Definition: qstring.h:508
static QCString result
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
void fill(QChar c, int len=-1)
Definition: qstring.cpp:12865
QString left(uint len) const
Definition: qstring.cpp:13199
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
void truncate(uint pos)
Definition: qstring.cpp:12490
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
void QString::setExpand ( uint  index,
QChar  c 
)

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.

14322 {
14323  int spaces = index - d->len;
14324  at(index) = c;
14325  while (spaces-->0)
14326  d->unicode[--index]=' ';
14327 }
uint len
Definition: qstring.h:344
QChar at(uint i) const
Definition: qstring.h:492
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
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.

See also
isNull(), isEmpty()

Definition at line 14804 of file qstring.cpp.

14805 {
14806  if ( str == 0 )
14807  return setUnicode(0,0);
14808  if ( len < 0 )
14809  len = qstrlen(str);
14810  if ( len == 0 ) { // won't make a null string
14811  deref();
14812  uint l;
14813  QChar *uc = internalAsciiToUnicode(str,&l);
14814  d = new QStringData(uc,l,l);
14815  } else {
14816  setUnicode( 0, len ); // resize but not copy
14817  QChar *p = d->unicode;
14818  while ( len-- )
14819  *p++ = *str++;
14820  }
14821  return *this;
14822 }
void deref()
Definition: qstring.cpp:12373
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
p
Definition: test.py:223
QStringData * d
Definition: qstring.h:560
static QChar * internalAsciiToUnicode(const QByteArray &ba, uint *len)
Definition: qstring.cpp:11977
QChar * unicode
Definition: qstring.h:342
unsigned uint
Definition: qglobal.h:351
QString & setUnicode(const QChar *unicode, uint len)
Definition: qstring.cpp:14736
static QCString str
void QString::setLength ( uint  pos)
private

Definition at line 12508 of file qstring.cpp.

12509 {
12510  if ( d->count != 1 || newLen > d->maxl || // detach, grow, or
12511  ( newLen*4 < d->maxl && d->maxl > 4 ) ) { // shrink
12512  Q2HELPER(stat_copy_on_write++)
12513  Q2HELPER(stat_copy_on_write_size+=d->len)
12514  uint newMax = 4;
12515  while ( newMax < newLen )
12516  newMax *= 2;
12517  QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
12518  uint len = QMIN( d->len, newLen );
12519  if ( d->unicode )
12520  memcpy( nd, d->unicode, sizeof(QChar)*len );
12521  deref();
12522  d = new QStringData( nd, newLen, newMax );
12523  } else {
12524  d->len = newLen;
12525  d->dirtyascii = 1;
12526  }
12527 }
const QChar * unicode() const
Definition: qstring.h:508
while(1)
Definition: code.cpp:12603
uint len
Definition: qstring.h:344
uint count
Definition: qshared.h:51
void deref()
Definition: qstring.cpp:12373
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
#define QMIN(a, b)
Definition: qglobal.h:391
#define Q2HELPER(x)
Definition: qstring.cpp:12221
uint maxl
Definition: qstring.h:345
QStringData * d
Definition: qstring.h:560
uint dirtyascii
Definition: qstring.h:346
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
if(!yymsg) yymsg
unsigned uint
Definition: qglobal.h:351
QString & QString::setNum ( short  n,
int  base = 10 
)
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.

707 { return setNum((long)n, base); }
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
QString & QString::setNum ( ushort  n,
int  base = 10 
)
inline

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.

710 { return setNum((ulong)n, base); }
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
unsigned long ulong
Definition: qglobal.h:352
QString & QString::setNum ( int  n,
int  base = 10 
)
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.

713 { return setNum((long)n, base); }
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
QString & QString::setNum ( uint  n,
int  base = 10 
)
inline

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.

716 { return setNum((ulong)n, base); }
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
unsigned long ulong
Definition: qglobal.h:352
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.

14110 {
14111 #if defined(CHECK_RANGE)
14112  if ( base < 2 || base > 36 ) {
14113  qWarning( "QString::setNum: Invalid base %d", base );
14114  base = 10;
14115  }
14116 #endif
14117  char charbuf[65*sizeof(QChar)];
14118  QChar *buf = (QChar*)charbuf;
14119  QChar *p = &buf[64];
14120  int len = 0;
14121  bool neg;
14122  if ( n < 0 ) {
14123  neg = TRUE;
14124  if ( n == INT_MIN ) {
14125  // Cannot always negate this special case
14126  QString s1, s2;
14127  s1.setNum(n/base);
14128  s2.setNum((-(n+base))%base);
14129  *this = s1 + s2;
14130  return *this;
14131  }
14132  n = -n;
14133  } else {
14134  neg = FALSE;
14135  }
14136  do {
14137  *--p = "0123456789abcdefghijklmnopqrstuvwxyz"[((int)(n%base))];
14138  n /= base;
14139  len++;
14140  } while ( n );
14141  if ( neg ) {
14142  *--p = '-';
14143  len++;
14144  }
14145  return setUnicode( p, len );
14146 }
const bool FALSE
Definition: qglobal.h:370
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
p
Definition: test.py:223
QString & setUnicode(const QChar *unicode, uint len)
Definition: qstring.cpp:14736
const bool TRUE
Definition: qglobal.h:371
QString & QString::setNum ( ulong  n,
int  base = 10 
)

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.

14157 {
14158 #if defined(CHECK_RANGE)
14159  if ( base < 2 || base > 36 ) {
14160  qWarning( "QString::setNum: Invalid base %d", base );
14161  base = 10;
14162  }
14163 #endif
14164  char charbuf[65*sizeof(QChar)];
14165  QChar *buf = (QChar*)charbuf;
14166  QChar *p = &buf[64];
14167  int len = 0;
14168  do {
14169  *--p = "0123456789abcdefghijklmnopqrstuvwxyz"[((int)(n%base))];
14170  n /= base;
14171  len++;
14172  } while ( n );
14173  return setUnicode(p,len);
14174 }
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
std::void_t< T > n
p
Definition: test.py:223
QString & setUnicode(const QChar *unicode, uint len)
Definition: qstring.cpp:14736
QString & QString::setNum ( float  n,
char  f = 'g',
int  prec = 6 
)
inline

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 718 of file qstring.h.

719 { return setNum((double)n,f,prec); }
QString & setNum(short, int base=10)
Definition: qstring.h:706
std::void_t< T > n
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.

14209 {
14210 #if defined(CHECK_RANGE)
14211  if ( !(f=='f' || f=='F' || f=='e' || f=='E' || f=='g' || f=='G') ) {
14212  qWarning( "QString::setNum: Invalid format char '%c'", f );
14213  f = 'f';
14214  }
14215 #endif
14216  char format[20];
14217  char buf[120]; // enough for 99 precision?
14218  char *fs = format; // generate format string
14219  *fs++ = '%'; // "%.<prec>l<f>"
14220  if ( prec >= 0 ) {
14221  if ( prec > 99 ) // buf big enough for precision?
14222  prec = 99;
14223  *fs++ = '.';
14224  if ( prec >= 10 ) {
14225  *fs++ = prec / 10 + '0';
14226  *fs++ = prec % 10 + '0';
14227  } else {
14228  *fs++ = prec + '0';
14229  }
14230  }
14231  *fs++ = 'l';
14232  *fs++ = f;
14233  *fs = '\0';
14234  ::sprintf( buf, format, n );
14235  return setLatin1(buf);
14236 }
QString & sprintf(const char *format,...)
Definition: qstring.cpp:12719
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
static constexpr double fs
Definition: Units.h:100
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
std::void_t< T > n
QString & setLatin1(const char *, int len=-1)
Definition: qstring.cpp:14804
QString & QString::setUnicode ( const QChar unicode,
uint  len 
)

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.

See also
setLatin1(), isNull()

Definition at line 14736 of file qstring.cpp.

14737 {
14738  if ( len == 0 ) { // set to null string
14739  if ( d != shared_null ) { // beware of nullstring being set to nullstring
14740  deref();
14742  d->ref();
14743  }
14744  } else if ( d->count != 1 || len > d->maxl ||
14745  ( len*4 < d->maxl && d->maxl > 4 ) ) { // detach, grown or shrink
14746  Q2HELPER(stat_copy_on_write++)
14747  Q2HELPER(stat_copy_on_write_size+=d->len)
14748  uint newMax = 4;
14749  while ( newMax < len )
14750  newMax *= 2;
14751  QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
14752  if ( unicode )
14753  memcpy( nd, unicode, sizeof(QChar)*len );
14754  deref();
14755  d = new QStringData( nd, len, newMax );
14756  } else {
14757  d->len = len;
14758  d->dirtyascii = 1;
14759  if ( unicode )
14760  memcpy( d->unicode, unicode, sizeof(QChar)*len );
14761  }
14762  return *this;
14763 }
while(1)
Definition: code.cpp:12603
uint len
Definition: qstring.h:344
uint count
Definition: qshared.h:51
void deref()
Definition: qstring.cpp:12373
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
#define Q2HELPER(x)
Definition: qstring.cpp:12221
uint maxl
Definition: qstring.h:345
void ref()
Definition: qshared.h:49
QStringData * d
Definition: qstring.h:560
uint dirtyascii
Definition: qstring.h:346
QChar * unicode
Definition: qstring.h:342
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
if(!yymsg) yymsg
unsigned uint
Definition: qglobal.h:351
static QStringData * makeSharedNull()
Definition: qstring.cpp:12190
static QStringData * shared_null
Definition: qstring.h:561
QString & QString::setUnicodeCodes ( const ushort unicode_as_ushorts,
uint  len 
)

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.

See also
setLatin1(), isNull()

Definition at line 14776 of file qstring.cpp.

14777 {
14778  setUnicode((const QChar*)unicode_as_ushorts, len);
14779  QChar t(0x1234);
14780  if ( unicode_as_ushorts && *((ushort*)&t) == 0x3412 ) {
14781  // Need to byteswap
14782  char* b = (char*)d->unicode;
14783  while ( len-- ) {
14784  char c = b[0];
14785  b[0] = b[1];
14786  b[1] = c;
14787  b += sizeof(QChar);
14788  }
14789  }
14790  return *this;
14791 }
while(1)
Definition: code.cpp:12603
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
unsigned short ushort
Definition: qglobal.h:350
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
static bool * b
Definition: config.cpp:1043
QString & setUnicode(const QChar *unicode, uint len)
Definition: qstring.cpp:14736
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).

QString s = " lots\t of\nwhite space ";
QString t = s.simplifyWhiteSpace(); // t == "lots of white space"
See also
stripWhiteSpace()

Definition at line 13482 of file qstring.cpp.

13483 {
13484  if ( isEmpty() ) // nothing to do
13485  return *this;
13486  QString result;
13487  result.setLength( length() );
13488  const QChar *from = unicode();
13489  const QChar *fromend = from+length();
13490  int outc=0;
13491  QChar *to = result.d->unicode;
13492  while ( TRUE ) {
13493  while ( from!=fromend && from->isSpace() )
13494  from++;
13495  while ( from!=fromend && !from->isSpace() )
13496  to[outc++] = *from++;
13497  if ( from!=fromend )
13498  to[outc++] = ' ';
13499  else
13500  break;
13501  }
13502  if ( outc > 0 && to[outc-1] == ' ' )
13503  outc--;
13504  result.truncate( outc );
13505  return result;
13506 }
const QChar * unicode() const
Definition: qstring.h:508
bool isEmpty() const
Definition: qstring.h:682
static QCString result
bool isSpace() const
Definition: qstring.cpp:11006
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
void truncate(uint pos)
Definition: qstring.cpp:12490
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
const bool TRUE
Definition: qglobal.h:371
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:

QString s = ...;
int x = ...;
QTextOStream(&str) << s << " : " << x;

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.

See also
arg()

Definition at line 12719 of file qstring.cpp.

12720 {
12721  va_list ap;
12722  va_start( ap, cformat );
12723 
12724  if ( !cformat || !*cformat ) {
12725  // Qt 1.x compat
12726  *this = QString::fromLatin1( "" );
12727  return *this;
12728  }
12729  QString format = QString::fromLatin1( cformat );
12730 
12731  static QRegExp *escape = 0;
12732  if (!escape)
12733  escape = new QRegExp( "%#?0?-? ?\\+?'?[0-9*]*\\.?[0-9*]*h?l?L?q?Z?" );
12734 
12735  QString result;
12736  uint last = 0;
12737 
12738  int len = 0;
12739  int pos;
12740  while ( 1 ) {
12741  pos = escape->match( cformat, last, &len );
12742  // Non-escaped text
12743  if ( pos > (int)last )
12744  result += format.mid(last,pos-last);
12745  if ( pos < 0 ) {
12746  // The rest
12747  if ( last < format.length() )
12748  result += format.mid(last);
12749  break;
12750  }
12751  last = pos + len + 1;
12752 
12753  // Escape
12754  QString f = format.mid( pos, len );
12755  uint width, decimals;
12756  int params = 0;
12757  int wpos = f.find('*');
12758  if ( wpos >= 0 ) {
12759  params++;
12760  width = va_arg( ap, int );
12761  if ( f.find('*', wpos + 1) >= 0 ) {
12762  decimals = va_arg( ap, int );
12763  params++;
12764  } else {
12765  decimals = 0;
12766  }
12767  } else {
12768  decimals = width = 0;
12769  }
12770  QString replacement;
12771  if ( format[pos+len] == 's' ||
12772  format[pos+len] == 'S' ||
12773  format[pos+len] == 'c' )
12774  {
12775  bool rightjust = ( f.find('-') < 0 );
12776  // Yes, %-5s really means left adjust in sprintf
12777 
12778  if ( wpos < 0 ) {
12779  QRegExp num( "[0-9]+" );
12780  QRegExp dot( "\\." );
12781  int nlen;
12782  int p = num.match( f.data(), 0, &nlen );
12783  int q = dot.match( f.data(), 0 );
12784  if ( q < 0 || (p < q && p >= 0) )
12785  width = f.mid( p, nlen ).toInt();
12786  if ( q >= 0 ) {
12787  p = num.match( f.data(), q );
12788  // "decimals" is used to specify string truncation
12789  if ( p >= 0 )
12790  decimals = f.mid( p, nlen ).toInt();
12791  }
12792  }
12793 
12794  if ( format[pos+len] == 's' ) {
12795 #ifndef QT_NO_TEXTCODEC
12796  QString s = QString::fromUtf8(va_arg(ap, char*));
12797 #else
12798  QString s = QString::fromLatin1(va_arg(ap, char*));
12799 #endif
12800  if ( decimals <= 0 )
12801  replacement = s;
12802  else
12803  replacement = s.left(decimals);
12804  } else {
12805  int ch = va_arg(ap, int);
12806  replacement = QChar((ushort)ch);
12807  }
12808  if ( replacement.length() < width ) {
12809  replacement = rightjust
12810  ? replacement.rightJustify(width)
12811  : replacement.leftJustify(width);
12812  }
12813  } else if ( format[pos+len] == '%' ) {
12814  replacement = '%';
12815  } else if ( format[pos+len] == 'n' ) {
12816  int* n = va_arg(ap, int*);
12817  *n = result.length();
12818  } else {
12819  char in[64], out[330] = "";
12820  strncpy(in,f.latin1(),63);
12821  char fch = format[pos+len].latin1();
12822  in[f.length()] = fch;
12823  switch ( fch ) {
12824  case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': {
12825  int value = va_arg(ap, int);
12826  switch (params) {
12827  case 0: ::sprintf( out, in, value ); break;
12828  case 1: ::sprintf( out, in, width, value ); break;
12829  case 2: ::sprintf( out, in, width, decimals, value ); break;
12830  }
12831  } break;
12832  case 'e': case 'E': case 'f': case 'g': case 'G': {
12833  double value = va_arg(ap, double);
12834  switch (params) {
12835  case 0: ::sprintf( out, in, value ); break;
12836  case 1: ::sprintf( out, in, width, value ); break;
12837  case 2: ::sprintf( out, in, width, decimals, value ); break;
12838  }
12839  } break;
12840  case 'p': {
12841  void* value = va_arg(ap, void*);
12842  switch (params) {
12843  case 0: ::sprintf( out, in, value ); break;
12844  case 1: ::sprintf( out, in, width, value ); break;
12845  case 2: ::sprintf( out, in, width, decimals, value ); break;
12846  }
12847  } break;
12848  }
12849  replacement = QString::fromLatin1(out);
12850  }
12851  result += replacement;
12852  }
12853  *this = result;
12854 
12855  va_end( ap );
12856  return *this;
12857 }
QString & sprintf(const char *format,...)
Definition: qstring.cpp:12719
QString leftJustify(uint width, QChar fill=' ', bool trunc=FALSE) const
Definition: qstring.cpp:13303
static QCString result
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
QString rightJustify(uint width, QChar fill=' ', bool trunc=FALSE) const
Definition: qstring.cpp:13342
QString mid(uint index, uint len=0xffffffff) const
Definition: qstring.cpp:13265
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
const char * data() const
Definition: qstring.h:542
QString left(uint len) const
Definition: qstring.cpp:13199
uint length() const
Definition: qstring.h:679
std::void_t< T > n
p
Definition: test.py:223
int match(const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
Definition: qregexp.cpp:649
unsigned short ushort
Definition: qglobal.h:350
static QString fromUtf8(const char *, int len=-1)
Definition: qstring.cpp:14523
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
int toInt(bool *ok=0, int base=10) const
Definition: qstring.cpp:14045
const char * latin1() const
Definition: qstring.cpp:14457
std::string escape(std::string const &str)
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
bool QString::startsWith ( const QString s) const

Returns whether the strings starts with s, or not.

Definition at line 15211 of file qstring.cpp.

15212 {
15213  for ( int i =0; i < (int) s.length(); i++ ) {
15214  if ( i >= (int) length() || d->unicode[i] != s[i] )
15215  return FALSE;
15216  }
15217  return TRUE;
15218 }
const bool FALSE
Definition: qglobal.h:370
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
const bool TRUE
Definition: qglobal.h:371
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).

Example:

QString s = " space ";
QString t = s.stripWhiteSpace(); // t == "space"
See also
simplifyWhiteSpace()

Definition at line 13438 of file qstring.cpp.

13439 {
13440  if ( isEmpty() ) // nothing to do
13441  return *this;
13442  if ( !at(0).isSpace() && !at(length()-1).isSpace() )
13443  return *this;
13444 
13445  register const QChar *s = unicode();
13446  QString result = fromLatin1("");
13447 
13448  int start = 0;
13449  int end = length() - 1;
13450  while ( start<=end && s[start].isSpace() ) // skip white space from start
13451  start++;
13452  if ( start > end ) { // only white space
13453  return result;
13454  }
13455  while ( end && s[end].isSpace() ) // skip white space from end
13456  end--;
13457  int l = end - start + 1;
13458  result.setLength( l );
13459  if ( l )
13460  memcpy( result.d->unicode, &s[start], sizeof(QChar)*l );
13461  return result;
13462 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
const QChar * unicode() const
Definition: qstring.h:508
bool isEmpty() const
Definition: qstring.h:682
static QCString result
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
QChar at(uint i) const
Definition: qstring.h:492
uint length() const
Definition: qstring.h:679
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
void setLength(uint pos)
Definition: qstring.cpp:12508
static QCString * s
Definition: config.cpp:1042
void QString::subat ( uint  i)
private

Internal chunk of code to handle the uncommon cases of at() above.

Definition at line 14713 of file qstring.cpp.

14714 {
14715  uint olen = d->len;
14716  if ( i >= olen ) {
14717  setLength( i+1 ); // i is index; i+1 is needed length
14718  for ( uint j=olen; j<=i; j++ )
14719  d->unicode[j] = QChar::null;
14720  } else {
14721  // Just be sure to detach
14722  real_detach();
14723  }
14724 }
uint len
Definition: qstring.h:344
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
QT_STATIC_CONST QChar null
Definition: qstring.h:68
void setLength(uint pos)
Definition: qstring.cpp:12508
unsigned uint
Definition: qglobal.h:351
void real_detach()
Definition: qstring.cpp:12368
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.

14072 {
14073  char *end;
14074 
14075  QCString a = latin1();
14076  // Just latin1() is not sufficient, since U0131 would look like '1'.
14077  for (uint i=0; i<d->len; i++)
14078  if ( d->unicode[i].row() )
14079  a[(int)i]='z';
14080 
14081  double val = strtod( a.data() ? a.data() : "", &end );
14082  if ( ok )
14083  *ok = ( a && *a && ( end == 0 || *end == '\0' ) );
14084  return val;
14085 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
uint len
Definition: qstring.h:344
const double a
const char * data() const
Definition: qcstring.h:207
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
const char * latin1() const
Definition: qstring.cpp:14457
uchar & row()
Definition: qstring.h:168
unsigned uint
Definition: qglobal.h:351
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.

14096 {
14097  return (float)toDouble( ok );
14098 }
double toDouble(bool *ok=0) const
Definition: qstring.cpp:14071
int QString::toInt ( bool ok = 0,
int  base = 10 
) const

Returns the string converted to a int value.

QString str("FF");
bool ok;
int hex = str.toInt( &ok, 16 ); // will return 255, and ok set to TRUE
int dec = str.toInt( &ok, 10 ); // will return 0, and ok set to FALSE

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.

14046 {
14047  return (int)toLong( ok, base );
14048 }
long toLong(bool *ok=0, int base=10) const
Definition: qstring.cpp:13834
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.

13835 {
13836  const QChar *p = unicode();
13837  long val=0;
13838  int l = length();
13839  const long max_mult = INT_MAX / base;
13840  bool is_ok = FALSE;
13841  int neg = 0;
13842  if ( !p )
13843  goto bye;
13844  while ( l && p->isSpace() ) // skip leading space
13845  l--,p++;
13846  if ( l && *p == '-' ) {
13847  l--;
13848  p++;
13849  neg = 1;
13850  } else if ( *p == '+' ) {
13851  l--;
13852  p++;
13853  }
13854 
13855  // NOTE: toULong() code is similar
13856  if ( !l || !ok_in_base(*p,base) )
13857  goto bye;
13858  while ( l && ok_in_base(*p,base) ) {
13859  l--;
13860  int dv;
13861  if ( p->isDigit() ) {
13862  dv = p->digitValue();
13863  } else {
13864  if ( *p >= 'a' && *p <= 'z' )
13865  dv = *p - 'a' + 10;
13866  else
13867  dv = *p - 'A' + 10;
13868  }
13869  if ( val > max_mult || (val == max_mult && dv > (INT_MAX%base)+neg) )
13870  goto bye;
13871  val = base*val + dv;
13872  p++;
13873  }
13874  if ( neg )
13875  val = -val;
13876  while ( l && p->isSpace() ) // skip trailing space
13877  l--,p++;
13878  if ( !l )
13879  is_ok = TRUE;
13880 bye:
13881  if ( ok )
13882  *ok = is_ok;
13883  return is_ok ? val : 0;
13884 }
const QChar * unicode() const
Definition: qstring.h:508
bool isSpace() const
Definition: qstring.cpp:11006
static bool ok_in_base(QChar c, int base)
Definition: qstring.cpp:13817
const bool FALSE
Definition: qglobal.h:370
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
int digitValue() const
Definition: qstring.cpp:11075
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
bool isDigit() const
Definition: qstring.cpp:11066
const bool TRUE
Definition: qglobal.h:371
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.

14002 {
14003  long v = toLong( ok, base );
14004  if ( ok && *ok && (v < -32768 || v > 32767) ) {
14005  *ok = FALSE;
14006  v = 0;
14007  }
14008  return (short)v;
14009 }
long toLong(bool *ok=0, int base=10) const
Definition: qstring.cpp:13834
const bool FALSE
Definition: qglobal.h:370
uint QString::toUInt ( bool ok = 0,
int  base = 10 
) const

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.

14059 {
14060  return (uint)toULong( ok, base );
14061 }
unsigned uint
Definition: qglobal.h:351
ulong toULong(bool *ok=0, int base=10) const
Definition: qstring.cpp:13895
uint64 QString::toUInt64 ( bool ok = 0,
int  base = 10 
) const

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.

13949 {
13950  const QChar *p = unicode();
13951  uint64 val=0;
13952  int l = length();
13953  const uint64 max_mult = 1844674407370955161ULL; // ULLONG_MAX/10, rounded down
13954  bool is_ok = FALSE;
13955  if ( !p )
13956  goto bye;
13957  while ( l && p->isSpace() ) // skip leading space
13958  l--,p++;
13959  if ( *p == '+' )
13960  l--,p++;
13961 
13962  // NOTE: toULong() code is similar
13963  if ( !l || !ok_in_base(*p,base) )
13964  goto bye;
13965  while ( l && ok_in_base(*p,base) ) {
13966  l--;
13967  uint dv;
13968  if ( p->isDigit() ) {
13969  dv = p->digitValue();
13970  } else {
13971  if ( *p >= 'a' && *p <= 'z' )
13972  dv = *p - 'a' + 10;
13973  else
13974  dv = *p - 'A' + 10;
13975  }
13976  if ( val > max_mult || (val == max_mult && dv > (ULLONG_MAX%base)) )
13977  goto bye;
13978  val = base*val + dv;
13979  p++;
13980  }
13981 
13982  while ( l && p->isSpace() ) // skip trailing space
13983  l--,p++;
13984  if ( !l )
13985  is_ok = TRUE;
13986 bye:
13987  if ( ok )
13988  *ok = is_ok;
13989  return is_ok ? val : 0;
13990 }
const QChar * unicode() const
Definition: qstring.h:508
bool isSpace() const
Definition: qstring.cpp:11006
static bool ok_in_base(QChar c, int base)
Definition: qstring.cpp:13817
const bool FALSE
Definition: qglobal.h:370
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
int digitValue() const
Definition: qstring.cpp:11075
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
unsigned long long uint64
Definition: qglobal.h:361
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
ulong QString::toULong ( bool ok = 0,
int  base = 10 
) const

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.

13896 {
13897  const QChar *p = unicode();
13898  ulong val=0;
13899  int l = length();
13900  const ulong max_mult = 429496729; // UINT_MAX/10, rounded down
13901  bool is_ok = FALSE;
13902  if ( !p )
13903  goto bye;
13904  while ( l && p->isSpace() ) // skip leading space
13905  l--,p++;
13906  if ( *p == '+' )
13907  l--,p++;
13908 
13909  // NOTE: toLong() code is similar
13910  if ( !l || !ok_in_base(*p,base) )
13911  goto bye;
13912  while ( l && ok_in_base(*p,base) ) {
13913  l--;
13914  uint dv;
13915  if ( p->isDigit() ) {
13916  dv = p->digitValue();
13917  } else {
13918  if ( *p >= 'a' && *p <= 'z' )
13919  dv = *p - 'a' + 10;
13920  else
13921  dv = *p - 'A' + 10;
13922  }
13923  if ( val > max_mult || (val == max_mult && dv > (UINT_MAX%base)) )
13924  goto bye;
13925  val = base*val + dv;
13926  p++;
13927  }
13928 
13929  while ( l && p->isSpace() ) // skip trailing space
13930  l--,p++;
13931  if ( !l )
13932  is_ok = TRUE;
13933 bye:
13934  if ( ok )
13935  *ok = is_ok;
13936  return is_ok ? val : 0;
13937 }
const QChar * unicode() const
Definition: qstring.h:508
bool isSpace() const
Definition: qstring.cpp:11006
static bool ok_in_base(QChar c, int base)
Definition: qstring.cpp:13817
const bool FALSE
Definition: qglobal.h:370
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
int digitValue() const
Definition: qstring.cpp:11075
uint length() const
Definition: qstring.h:679
unsigned long ulong
Definition: qglobal.h:352
p
Definition: test.py:223
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
ushort QString::toUShort ( bool ok = 0,
int  base = 10 
) const

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.

14020 {
14021  ulong v = toULong( ok, base );
14022  if ( ok && *ok && (v > 65535) ) {
14023  *ok = FALSE;
14024  v = 0;
14025  }
14026  return (ushort)v;
14027 }
const bool FALSE
Definition: qglobal.h:370
unsigned long ulong
Definition: qglobal.h:352
unsigned short ushort
Definition: qglobal.h:350
ulong toULong(bool *ok=0, int base=10) const
Definition: qstring.cpp:13895
void QString::truncate ( uint  newLen)

Truncates the string at position newLen if newLen is less than the current length . Otherwise, nothing happens.

Example:

QString s = "truncate this string";
s.truncate( 5 ); // s == "trunc"

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.

12491 {
12492  if ( newLen < d->len )
12493  setLength( newLen );
12494 }
void setLength(uint pos)
Definition: qstring.cpp:12508
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.

12093 {
12094  if ( ! d->unicode )
12095  return 0;
12096  unsigned int len = d->len;
12097  if ( d->maxl < len + 1 ) {
12098  // detach, grow or shrink
12099  uint newMax = computeNewMax( len + 1 );
12100  QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
12101  if ( nd ) {
12102  if ( d->unicode )
12103  memcpy( nd, d->unicode, sizeof(QChar)*len );
12104  ((QString *)this)->deref();
12105  ((QString *)this)->d = new QStringData( nd, len, newMax );
12106  }
12107  }
12108  d->unicode[len] = 0;
12109  return (unsigned short *) d->unicode;
12110 }
static uint computeNewMax(uint len)
Definition: qstring.cpp:12071
uint len
Definition: qstring.h:344
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint maxl
Definition: qstring.h:345
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
#define QT_ALLOC_QCHAR_VEC(N)
Definition: qstring.cpp:11946
unsigned uint
Definition: qglobal.h:351
const QChar * QString::unicode ( ) const
inline

Returns the Unicode representation of the string. The result remains valid until the string is modified.

Definition at line 508 of file qstring.h.

508 { return d->unicode; }
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
char * QString::unicodeToAscii ( const QChar uc,
uint  l 
)
staticprivate

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.

12059 {
12060  if (!uc) {
12061  return 0;
12062  }
12063  char *a = new char[l+1];
12064  char *result = a;
12065  while (l--)
12066  *a++ = *uc++;
12067  *a = '\0';
12068  return result;
12069 }
static QCString result
static QStrList * l
Definition: config.cpp:1044
const double a
QString QString::upper ( ) const

Returns a new string that is the string converted to upper case.

Example:

QString s("TeX");
QString t = s.upper(); // t == "TEX"
See also
lower()

Definition at line 13404 of file qstring.cpp.

13405 {
13406  QString s(*this);
13407  int l=length();
13408  if ( l ) {
13409  s.real_detach(); // could do this only when we find a change
13410  register QChar *p=s.d->unicode;
13411  if ( p ) {
13412  while ( l-- ) {
13413  *p = p->upper();
13414  p++;
13415  }
13416  }
13417  }
13418  return s;
13419 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
static QCString * s
Definition: config.cpp:1042
QChar upper() const
Definition: qstring.cpp:11248
QCString QString::utf8 ( ) const

Returns the string encoded in UTF8 format.

See QTextCodec for more diverse coding/decoding of Unicode strings.

See also
QString::fromUtf8(), local8Bit(), latin1()

Definition at line 14507 of file qstring.cpp.

14508 {
14509  static QTextCodec* codec = QTextCodec::codecForMib(106);
14510  return codec
14511  ? codec->fromUnicode(*this)
14512  : QCString(latin1());
14513 }
virtual QCString fromUnicode(const QString &uc, int &lenInOut) const
Definition: qtextcodec.cpp:783
static QTextCodec * codecForMib(int mib)
Definition: qtextcodec.cpp:354
const char * latin1() const
Definition: qstring.cpp:14457
Provides conversion between text encodings.
Definition: qtextcodec.h:62
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.

11706 {
11707 #ifndef QT_NO_UNICODETABLES
11708  // #### This needs much more optimizing - it is called for
11709  // #### every text operation.
11710 
11711  unsigned char *level;
11713  unsigned char base = 0;
11714 
11715  unsigned int l = length();
11716 
11717  // check bounds
11718  if (len == -1)
11719  len = length()-index;
11720  if ((uint)index > l)
11721  return QString::null;
11722 
11723  // find base direction
11724  unsigned int pos = 0;
11725  while ((pos < length()) &&
11726  (at(pos) != RLE) &&
11727  (at(pos) != LRE) &&
11728  (at(pos) != RLO) &&
11729  (at(pos) != LRO) &&
11730  (at(pos).direction() > 1) &&
11731  (at(pos).direction() != QChar::DirAL)
11732  ) // not R and not L
11733  pos++;
11734 
11735  if ((pos < length()) &&
11736  ((at(pos).direction() == QChar::DirR) ||
11737  (at(pos).direction() == QChar::DirAL) ||
11738  (at(pos) == RLE) ||
11739  (at(pos) == RLO)))
11740  base = 1;
11741 
11742  // is there any BiDi char at all?
11743  if ( base == 0 && pos == l ) {
11744  return mid(index, len);
11745  }
11746 
11747 
11748  level = new uchar[l];
11749  dir = new QChar::Direction[l];
11750 
11751  // explicit override pass
11752  //unsigned int code_count = 0;
11753 
11754  QStack<QBidiState> stack;
11755  stack.setAutoDelete(TRUE);
11756 
11757  unsigned char clevel = base;
11758  signed char override = -1;
11759 
11760  for (pos = 0; pos < l; pos++) {
11761 
11762  if (at(pos) == RLE) {
11763  //code_count++;
11764  stack.push(new QBidiState(clevel, override));
11765  if (clevel < 254)
11766  clevel += 1 + clevel % 2;
11767  override = -1;
11768  }
11769  else if (at(pos) == LRE) {
11770  //code_count++;
11771  stack.push(new QBidiState(clevel, override));
11772  if (clevel < 254)
11773  clevel += 2 - clevel % 2;
11774  override = -1;
11775  }
11776  else if (at(pos) == RLO) {
11777  //code_count++;
11778  stack.push(new QBidiState(clevel, override));
11779  if (clevel < 254)
11780  clevel += 1 + clevel % 2;
11781  override = QChar::DirR;
11782  }
11783  else if (at(pos) == LRO) {
11784  //code_count++;
11785  stack.push(new QBidiState(clevel, override));
11786  if (clevel < 254)
11787  clevel += 2 - clevel % 2;
11788  override = QChar::DirL;
11789  }
11790  else if (at(pos) == PDF) {
11791  //code_count++;
11792  if (!stack.isEmpty()) {
11793  override = stack.top()->override;
11794  clevel = stack.top()->level;
11795  stack.remove();
11796  }
11797  }
11798 
11799  // TODO: catch block separators (newlines, paras, etc.)
11800 
11801  level[pos] = clevel;
11802  if (override != -1)
11803  dir[pos] = (QChar::Direction) override;
11804  else
11805  dir[pos] = at(pos).direction();
11806  }
11807 
11808  // weak type pass
11809  for (pos = 0; pos < l; pos++) {
11810 
11811  int i;
11812 
11813  switch (at(pos).direction()) {
11814  case QChar::DirEN:
11815  i = pos-1;
11816  while ((i >= 0) &&
11817  !(at(i).direction() == QChar::DirAN) &&
11818  !(at(i).direction() == QChar::DirAL) &&
11819  !(at(i).direction() == QChar::DirB))
11820  i--;
11821 
11822  if ((i >= 0) &&
11823  ((at(i).direction() == QChar::DirAN) ||
11824  (at(i).direction() == QChar::DirAL)))
11825  dir[pos] = QChar::DirAN;
11826 
11827  break;
11828  case QChar::DirES:
11829  case QChar::DirCS:
11830  if ((pos > 0) && (pos < l-1) &&
11831  (dir[pos-1] == dir[pos+1]))
11832  dir[pos] = dir[pos-1];
11833  else
11834  dir[pos] = QChar::DirON;
11835 
11836  break;
11837  case QChar::DirET:
11838  if (((pos > 0) && (dir[pos-1] == QChar::DirEN)) ||
11839  ((pos < l-1) && (dir[pos+1] == QChar::DirEN)))
11840  dir[pos] = QChar::DirEN;
11841  else
11842  dir[pos] = QChar::DirON;
11843 
11844  break;
11845  case QChar::DirAL:
11846  dir[pos] = QChar::DirR;
11847  break;
11848  default:
11849  break;
11850  }
11851  }
11852 
11853  // neutral type pass
11854  for (pos = 0; pos < l; pos++) {
11855  QChar::Direction left,right; // declaring l here shadowed previous l
11856 
11857  if (is_neutral(dir[pos])) {
11858  if (pos > 0)
11859  left = dir[pos-1];
11860  else
11861  left = (base == 0 ? QChar::DirL : QChar::DirR);
11862 
11863  int i = pos;
11864 
11865  while ((i < (int)l-1) && is_neutral(dir[i+1]))
11866  i++;
11867 
11868  if (i < (int)l-1)
11869  right = dir[i+1];
11870  else
11871  right = (base == 0 ? QChar::DirL : QChar::DirR);
11872 
11873  for (int j=pos; j <= i; j++) {
11874  int a = 1, b = 1;
11875  while ((a < 5) && (left != resolv[0][a]))
11876  a++;
11877  while ((b < 5) && (right != resolv[0][b]))
11878  b++;
11879  if ((a == 5) || (b == 5))
11880  dir[j] = (base == 0 ? QChar::DirL : QChar::DirR);
11881  else
11882  dir[j] = resolv[a][b];
11883 
11884  if (dir[j] == (QChar::Direction)(-1))
11885  dir[j] = (base == 0 ? QChar::DirL : QChar::DirR);
11886  }
11887  }
11888  }
11889 
11890  // implicit level pass
11891  QChar::Direction prec = (base == 0 ? QChar::DirL : QChar::DirR);
11892 
11893  for (pos = 0; pos < l; pos++) {
11894  if (level[pos] % 2) {
11895  switch (dir[pos]) {
11896  case QChar::DirL:
11897  case QChar::DirAN:
11898  case QChar::DirEN:
11899  level[pos] += 1;
11900  break;
11901  default:
11902  break;
11903  }
11904  } else {
11905  switch (dir[pos]) {
11906  case QChar::DirL:
11907  // do nothing
11908  break;
11909  case QChar::DirR:
11910  level[pos] += 1;
11911  break;
11912  case QChar::DirEN:
11913  if (prec == QChar::DirL)
11914  continue;
11915  // fall through
11916  case QChar::DirAN:
11917  level[pos] += 2;
11918  break;
11919  default:
11920  break;
11921  }
11922  }
11923 
11924  prec = dir[pos];
11925  }
11926 
11927  // now do the work!
11928  QString ret(*this);
11929  reverse(ret, level, index, index+len);
11930 
11931  delete [] level;
11932  delete [] dir;
11933 
11934  return ret;
11935 #else
11936  return mid(index,len);
11937 #endif
11938 }
void setAutoDelete(bool del)
Definition: qstack.h:55
Direction direction() const
Definition: qstring.cpp:11114
QString mid(uint index, uint len=0xffffffff) const
Definition: qstring.cpp:13265
static QChar LRO((ushort) 0x202d)
Definition: qstack.h:46
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
unsigned char level
Definition: qstring.cpp:11679
string dir
static QStrList * l
Definition: config.cpp:1044
unsigned char uchar
Definition: nybbler.cc:11
void push(const type *d)
Definition: qstack.h:58
static QChar::Direction resolv[5][5]
Definition: qstring.cpp:11689
static QChar PDF((ushort) 0x202c)
QChar at(uint i) const
Definition: qstring.h:492
bool isEmpty() const
Definition: qstack.h:57
QString left(uint len) const
Definition: qstring.cpp:13199
uint length() const
Definition: qstring.h:679
const double a
static QChar LRE((ushort) 0x202a)
static QChar RLE((ushort) 0x202b)
signed char override
Definition: qstring.cpp:11680
Direction
Definition: qstring.h:118
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
bool remove()
Definition: qstack.h:60
static bool * b
Definition: config.cpp:1043
static const Null null
Definition: qstring.h:376
static bool is_neutral(unsigned short dir)
Definition: qstring.cpp:11607
static QChar RLO((ushort) 0x202e)
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
QString right(uint len) const
Definition: qstring.cpp:13231
type * top() const
Definition: qstack.h:63

Friends And Related Function Documentation

bool operator!= ( const QString s1,
const QString s2 
)
related

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.

14851 { return !(s1==s2); }
bool operator!= ( const QString s1,
const char *  s2 
)
related

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.

14873 { return !(s1==s2); }
bool operator!= ( const char *  s1,
const QString s2 
)
related

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.

14876 { return !(s1==s2); }
QString operator+ ( const QString s1,
const QString s2 
)
related

Returns the concatenated string of s1 and s2.

Definition at line 774 of file qstring.h.

775 {
776  QString tmp( s1 );
777  tmp += s2;
778  return tmp;
779 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
string tmp
Definition: languages.py:63
QString operator+ ( const QString s1,
const char *  s2 
)
related

Returns the concatenated string of s1 and s2.

Definition at line 782 of file qstring.h.

783 {
784  QString tmp( s1 );
785  tmp += QString::fromLatin1(s2);
786  return tmp;
787 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
string tmp
Definition: languages.py:63
QString operator+ ( const char *  s1,
const QString s2 
)
related

Returns the concatenated string of s1 and s2.

Definition at line 789 of file qstring.h.

790 {
792  tmp += s2;
793  return tmp;
794 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
string tmp
Definition: languages.py:63
QString operator+ ( const QString s,
char  c 
)
related

Returns the concatenated string of s and c.

Definition at line 804 of file qstring.h.

805 {
806  QString tmp( s1 );
807  tmp += c2;
808  return tmp;
809 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
string tmp
Definition: languages.py:63
QString operator+ ( char  c,
const QString s 
)
related

Returns the concatenated string of c and s.

Definition at line 819 of file qstring.h.

820 {
821  QString tmp;
822  tmp += c1;
823  tmp += s2;
824  return tmp;
825 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
string tmp
Definition: languages.py:63
bool operator< ( const QString s1,
const char *  s2 
)
related

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.

14879 { return ucstrcmp(s1,s2) < 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator< ( const char *  s1,
const QString s2 
)
related

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.

14882 { return ucstrcmp(s1,s2) < 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
QDataStream & operator<< ( QDataStream s,
const QString str 
)
related

Writes a string to the stream.

See also
Format of the QDataStream operators

Definition at line 15066 of file qstring.cpp.

15067 {
15068  if ( s.version() == 1 ) {
15069  QCString l( str.latin1() );
15070  s << l;
15071  }
15072  else {
15073  const char* ub = (const char*)str.unicode();
15074  if ( ub || s.version() < 3 ) {
15075  if ( QChar::networkOrdered() ==
15077  s.writeBytes( ub, (int)sizeof(QChar)*str.length() );
15078  } else {
15079  static const uint auto_size = 1024;
15080  char t[auto_size];
15081  char *b;
15082  if ( str.length()*sizeof(QChar) > auto_size ) {
15083  b = new char[str.length()*sizeof(QChar)];
15084  } else {
15085  b = t;
15086  }
15087  int l = str.length();
15088  char *c=b;
15089  while ( l-- ) {
15090  *c++ = ub[1];
15091  *c++ = ub[0];
15092  ub+=sizeof(QChar);
15093  }
15094  s.writeBytes( b, (int)sizeof(QChar)*str.length() );
15095  if ( str.length()*sizeof(QChar) > auto_size )
15096  delete [] b;
15097  }
15098  } else {
15099  // write null marker
15100  s << (Q_UINT32)0xffffffff;
15101  }
15102  }
15103  return s;
15104 }
const QChar * unicode() const
Definition: qstring.h:508
int byteOrder() const
Definition: qdatastream.h:132
static constexpr double ub
Definition: Units.h:80
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
static QStrList * l
Definition: config.cpp:1044
QDataStream & writeBytes(const char *, uint len)
static bool networkOrdered()
Definition: qstring.h:172
uint length() const
Definition: qstring.h:679
unsigned int Q_UINT32
Definition: qglobal.h:420
int version() const
Definition: qdatastream.h:141
const char * latin1() const
Definition: qstring.cpp:14457
static bool * b
Definition: config.cpp:1043
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
bool operator<= ( const QString s1,
const char *  s2 
)
related

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.

14885 { return ucstrcmp(s1,s2) <= 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator<= ( const char *  s1,
const QString s2 
)
related

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.

14888 { return ucstrcmp(s1,s2) <= 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator== ( const QString s1,
const QString s2 
)
related

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.

14844 {
14845  return (s1.length() == s2.length()) && s1.isNull() == s2.isNull() &&
14846  (memcmp((char*)s1.unicode(),(char*)s2.unicode(),
14847  s1.length()*sizeof(QChar)) ==0);
14848 }
const QChar * unicode() const
Definition: qstring.h:508
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
bool isNull() const
Definition: qstring.h:379
bool operator== ( const QString s1,
const char *  s2 
)
related

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.

14867 { return s1==QString(s2); }
QString()
Definition: qstring.h:652
bool operator== ( const char *  s1,
const QString s2 
)
related

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.

14870 { return QString(s1)==s2; }
QString()
Definition: qstring.h:652
bool operator> ( const QString s1,
const char *  s2 
)
related

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.

14891 { return ucstrcmp(s1,s2) > 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator> ( const char *  s1,
const QString s2 
)
related

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.

14894 { return ucstrcmp(s1,s2) > 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator>= ( const QString s1,
const char *  s2 
)
related

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.

14897 { return ucstrcmp(s1,s2) >= 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
bool operator>= ( const char *  s1,
const QString s2 
)
related

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.

14900 { return ucstrcmp(s1,s2) >= 0; }
static int ucstrcmp(const QString &as, const QString &bs)
Definition: qstring.cpp:10693
QDataStream & operator>> ( QDataStream s,
QString str 
)
friend

Reads a string from the stream.

See also
Format of the QDataStream operators

Definition at line 15113 of file qstring.cpp.

15114 {
15115 #ifdef QT_QSTRING_UCS_4
15116 #if defined(_CC_GNU_)
15117 #warning "operator>> not working properly"
15118 #endif
15119 #endif
15120  if ( s.version() == 1 ) {
15121  QCString l;
15122  s >> l;
15123  str = QString( l );
15124  }
15125  else {
15126  Q_UINT32 bytes;
15127  s >> bytes; // read size of string
15128  if ( bytes == 0xffffffff ) { // null string
15129  str = QString::null;
15130  } else if ( bytes > 0 ) { // not empty
15131  str.setLength( bytes/2 );
15132  char* b = (char*)str.d->unicode;
15133  s.readRawBytes( b, bytes );
15134  if ( QChar::networkOrdered() !=
15136  bytes /= 2;
15137  while ( bytes-- ) {
15138  char c = b[0];
15139  b[0] = b[1];
15140  b[1] = c;
15141  b += 2;
15142  }
15143  }
15144  } else {
15145  str = "";
15146  }
15147  }
15148  return s;
15149 }
int byteOrder() const
Definition: qdatastream.h:132
static QStrList * l
Definition: config.cpp:1044
static bool networkOrdered()
Definition: qstring.h:172
QDataStream & readRawBytes(char *, uint len)
unsigned int Q_UINT32
Definition: qglobal.h:420
int version() const
Definition: qdatastream.h:141
QStringData * d
Definition: qstring.h:560
QChar * unicode
Definition: qstring.h:342
static bool * b
Definition: config.cpp:1043
void setLength(uint pos)
Definition: qstring.cpp:12508
static const Null null
Definition: qstring.h:376
byte bytes
Alias for common language habits.
Definition: datasize.h:101
static QCString * s
Definition: config.cpp:1042
QString()
Definition: qstring.h:652
friend class QConstString
friend

Definition at line 564 of file qstring.h.

Member Data Documentation

QStringData* QString::d
private

Definition at line 560 of file qstring.h.

const QString::Null QString::null = { }
static

Definition at line 376 of file qstring.h.

Q_EXPORT QStringData * QString::shared_null = 0
staticprivate

Definition at line 561 of file qstring.h.


The documentation for this class was generated from the following files: