QLatin1String Class Reference

#include <qstring.h>

List of all members.


Detailed Description

The QLatin1String class provides a thin wrapper around an ASCII/Latin-1 encoded string literal.

Many of QString's member functions are overloaded to accept {const char *} instead of QString. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as insert() , replace(), and indexOf(). These functions are usually optimized to avoid constructing a QString object for the {const char *} data. For example, assuming str is a QString,

        if (str == "auto" || str == "extern"
                || str == "static" || str == "register") {
            ...
        }

is much faster than

        if (str == QString("auto") || str == QString("extern")
                || str == QString("static") || str == QString("register")) {
            ...
        }

because it doesn't construct four temporary QString objects and make a deep copy of the character data.

Applications that define QT_NO_CAST_FROM_ASCII (as explained in the QString documentation) don't have access to QString's {const char *} API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides the QLatin1String, which is just a very thin wrapper around a {const char *}. Using QLatin1String, the example code above becomes

        if (str == QLatin1String("auto")
                || str == QLatin1String("extern")
                || str == QLatin1String("static")
                || str == QLatin1String("register") {
            ...
        }

This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString::fromLatin1().

Thanks to the QString(const QLatin1String &) constructor, QLatin1String can be used everywhere a QString is expected. For example:

        QLabel *label = new QLabel(QLatin1String("MOD"), this);

See also:
QString, QLatin1Char

Definition at line 549 of file qstring.h.

Public Member Functions

 QLatin1String (const char *s)
QLatin1Stringoperator= (const QLatin1String &other)
const char * latin1 () const
bool operator== (const QString &s) const
bool operator!= (const QString &s) const
bool operator> (const QString &s) const
bool operator< (const QString &s) const
bool operator>= (const QString &s) const
bool operator<= (const QString &s) const

Private Attributes

const char * chars


Constructor & Destructor Documentation

QLatin1String::QLatin1String ( const char *  str  )  [inline, explicit]

Constructs a QLatin1String object that stores str.

The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1String object exists.

See also:
latin1()

Definition at line 552 of file qstring.h.

00552 : chars(s) {}


Member Function Documentation

QLatin1String & QLatin1String::operator= ( const QLatin1String other  )  [inline]

Since:
4.1
Constructs a copy of other.

Definition at line 553 of file qstring.h.

References chars.

00554     { chars = other.chars; return *this; }

const char * QLatin1String::latin1 (  )  const [inline]

Returns the Latin-1 string stored in this object.

Definition at line 556 of file qstring.h.

Referenced by QString::append(), QString::compare(), QTextHtmlExporter::emitCharFormatStyle(), QTextHtmlExporter::emitFragment(), QString::insert(), QString::operator<(), QString::operator==(), QString::operator>(), and QTest::toString().

00556 { return chars; }

bool QLatin1String::operator== ( const QString other  )  const [inline]

Returns true if this string is equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 558 of file qstring.h.

References s.

00559     { return s == *this; }

bool QLatin1String::operator!= ( const QString other  )  const [inline]

Returns true if this string is not equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 560 of file qstring.h.

References s.

00561     { return s != *this; }

bool QLatin1String::operator> ( const QString other  )  const [inline]

Returns true if this string is lexically greater than string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 562 of file qstring.h.

References s.

00563     { return s < *this; }

bool QLatin1String::operator< ( const QString other  )  const [inline]

Returns true if this string is lexically less than the other string; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function.

Definition at line 564 of file qstring.h.

References s.

00565     { return s > *this; }

bool QLatin1String::operator>= ( const QString other  )  const [inline]

Returns true if this string is lexically greater than or equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 566 of file qstring.h.

References s.

00567     { return s <= *this; }

bool QLatin1String::operator<= ( const QString other  )  const [inline]

Returns true if this string is lexically less than or equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 568 of file qstring.h.

References s.

00569     { return s >= *this; }


Member Data Documentation

const char* QLatin1String::chars [private]

Definition at line 572 of file qstring.h.

Referenced by operator=().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:08:16 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1