?? qstring.h
字號:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#ifndef QSTRING_H#define QSTRING_H#include <QtCore/qchar.h>#include <QtCore/qbytearray.h>#include <QtCore/qatomic.h>#include <QtCore/qnamespace.h>#ifdef QT_INCLUDE_COMPAT#include <Qt3Support/q3cstring.h>#endif#ifndef QT_NO_STL# if defined (Q_CC_MSVC_NET) && _MSC_VER < 1310 // Avoids nasty warning for xlocale, line 450# pragma warning (push)# pragma warning (disable : 4189)# include <string># pragma warning (pop)# else# include <string># endif# ifndef QT_NO_STL_WCHAR// workaround for some headers not typedef'ing std::wstringtypedef std::basic_string<wchar_t> QStdWString;# endif // QT_NO_STL_WCHAR#endif // QT_NO_STL#include <stdarg.h>#ifdef truncate#error qstring.h must be included before any header file that defines truncate#endifQT_BEGIN_HEADERQT_MODULE(Core)class QCharRef;class QRegExp;class QStringList;class QTextCodec;class QLatin1String;template <typename T> class QVector;class Q_CORE_EXPORT QString{public: inline QString(); QString(const QChar *unicode, int size); QString(QChar c); QString(int size, QChar c); inline QString(const QLatin1String &latin1); inline QString(const QString &); inline ~QString(); QString &operator=(QChar c); QString &operator=(const QString &); inline QString &operator=(const QLatin1String &); inline int size() const { return d->size; } inline int count() const { return d->size; } inline int length() const; inline bool isEmpty() const; void resize(int size); QString &fill(QChar c, int size = -1); void truncate(int pos); void chop(int n); int capacity() const; inline void reserve(int size); inline void squeeze() { if (d->size < d->alloc) realloc(); } inline const QChar *unicode() const; inline QChar *data(); inline const QChar *data() const; inline const QChar *constData() const; inline void detach(); inline bool isDetached() const; void clear(); inline const QChar at(int i) const; const QChar operator[](int i) const; QCharRef operator[](int i); const QChar operator[](uint i) const; QCharRef operator[](uint i); QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(qulonglong a, int fieldwidth=0, int base=10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(long a, int fieldwidth=0, int base=10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(ulong a, int fieldwidth=0, int base=10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(int a, int fieldWidth = 0, int base = 10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(uint a, int fieldWidth = 0, int base = 10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(short a, int fieldWidth = 0, int base = 10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(ushort a, int fieldWidth = 0, int base = 10, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(char a, int fieldWidth = 0, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(QChar a, int fieldWidth = 0, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(const QString &a, int fieldWidth = 0, const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; QString arg(const QString &a1, const QString &a2) const Q_REQUIRED_RESULT; QString arg(const QString &a1, const QString &a2, const QString &a3) const Q_REQUIRED_RESULT; QString arg(const QString &a1, const QString &a2, const QString &a3, const QString &a4) const Q_REQUIRED_RESULT; QString &vsprintf(const char *format, va_list ap); QString &sprintf(const char *format, ...)#if defined(Q_CC_GNU) && !defined(__INSURE__) __attribute__ ((format (printf, 2, 3)))#endif ; int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; inline QBool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; inline QBool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;#ifndef QT_NO_REGEXP int indexOf(const QRegExp &, int from = 0) const; int lastIndexOf(const QRegExp &, int from = -1) const; inline QBool contains(const QRegExp &rx) const { return QBool(indexOf(rx) != -1); } int count(const QRegExp &) const;#endif enum SectionFlag { SectionDefault = 0x00, SectionSkipEmpty = 0x01, SectionIncludeLeadingSep = 0x02, SectionIncludeTrailingSep = 0x04, SectionCaseInsensitiveSeps = 0x08 }; Q_DECLARE_FLAGS(SectionFlags, SectionFlag) QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const;#ifndef QT_NO_REGEXP QString section(const QRegExp ®, int start, int end = -1, SectionFlags flags = SectionDefault) const;#endif QString left(int len) const Q_REQUIRED_RESULT; QString right(int len) const Q_REQUIRED_RESULT; QString mid(int i, int len = -1) const Q_REQUIRED_RESULT; bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; QString toLower() const Q_REQUIRED_RESULT; QString toUpper() const Q_REQUIRED_RESULT; QString trimmed() const Q_REQUIRED_RESULT; QString simplified() const Q_REQUIRED_RESULT; QString &insert(int i, QChar c); QString &insert(int i, const QChar *uc, int len); inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); } QString &insert(int i, const QLatin1String &s); QString &append(QChar c); QString &append(const QString &s); QString &append(const QLatin1String &s); inline QString &prepend(QChar c) { return insert(0, c); } inline QString &prepend(const QString &s) { return insert(0, s); } inline QString &prepend(const QLatin1String &s) { return insert(0, s); } inline QString &operator+=(QChar c) { return append(c); } inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); } inline QString &operator+=(const QString &s) { return append(s); } inline QString &operator+=(const QLatin1String &s) { return append(s); } QString &remove(int i, int len); QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(int i, int len, QChar after); QString &replace(int i, int len, const QChar *s, int slen); QString &replace(int i, int len, const QString &after); QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);#ifndef QT_NO_REGEXP QString &replace(const QRegExp &rx, const QString &after); inline QString &remove(const QRegExp &rx) { return replace(rx, QString()); }#endif enum SplitBehavior { KeepEmptyParts, SkipEmptyParts }; QStringList split(const QString &sep, SplitBehavior behavior = KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT; QStringList split(const QChar &sep, SplitBehavior behavior = KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT;#ifndef QT_NO_REGEXP QStringList split(const QRegExp &sep, SplitBehavior behavior = KeepEmptyParts) const Q_REQUIRED_RESULT;#endif enum NormalizationForm { NormalizationForm_D, NormalizationForm_C, NormalizationForm_KD, NormalizationForm_KC }; QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT; QString normalized(NormalizationForm mode, QChar::UnicodeVersion version) const Q_REQUIRED_RESULT; const ushort *utf16() const; QByteArray toAscii() const Q_REQUIRED_RESULT; QByteArray toLatin1() const Q_REQUIRED_RESULT; QByteArray toUtf8() const Q_REQUIRED_RESULT; QByteArray toLocal8Bit() const Q_REQUIRED_RESULT; QVector<uint> toUcs4() const Q_REQUIRED_RESULT; static QString fromAscii(const char *, int size = -1); static QString fromLatin1(const char *, int size = -1); static QString fromUtf8(const char *, int size = -1); static QString fromLocal8Bit(const char *, int size = -1); static QString fromUtf16(const ushort *, int size = -1); static QString fromUcs4(const uint *, int size = -1); static QString fromRawData(const QChar *, int size); int toWCharArray(wchar_t *array) const; static QString fromWCharArray(const wchar_t *, int size = -1); QString &setUnicode(const QChar *unicode, int size); inline QString &setUtf16(const ushort *utf16, int size); // ### Qt 5: merge these two functions int compare(const QString &s) const; int compare(const QString &s, Qt::CaseSensitivity cs) const; int compare(const QLatin1String &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; // ### Qt 5: merge these two functions static inline int compare(const QString &s1, const QString &s2) { return s1.compare(s2); } static inline int compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs) { return s1.compare(s2, cs); } static inline int compare(const QString& s1, const QLatin1String &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) { return s1.compare(s2, cs); } static inline int compare(const QLatin1String& s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) { return -s2.compare(s1, cs); } int localeAwareCompare(const QString& s) const; static int localeAwareCompare(const QString& s1, const QString& s2) { return s1.localeAwareCompare(s2); } 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; qlonglong toLongLong(bool *ok=0, int base=10) const; qulonglong toULongLong(bool *ok=0, int base=10) const; float toFloat(bool *ok=0) const; double toDouble(bool *ok=0) const; QString &setNum(short, int base=10); QString &setNum(ushort, int base=10); QString &setNum(int, int base=10); QString &setNum(uint, int base=10);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -