📄 qstring.h
字号:
ascii = 0; } issimpletext = FALSE; }#ifdef Q_OS_MAC9 uint len;#else uint len : 30;#endif uint issimpletext : 1;#ifdef Q_OS_MAC9 uint maxl;#else uint maxl : 30;#endif uint islatin1 : 1;private:#if defined(Q_DISABLE_COPY) QStringData( const QStringData& ); QStringData& operator=( const QStringData& );#endif};class Q_EXPORT QString{public: QString(); // make null string QString( QChar ); // one-char string QString( const QString & ); // impl-shared copy QString( const QByteArray& ); // deep copy QString( const QChar* unicode, uint length ); // deep copy#ifndef QT_NO_CAST_ASCII QString( const char *str ); // deep copy#endif#ifndef QT_NO_STL QString( const std::string& ); // deep copy#endif ~QString(); QString &operator=( const QString & ); // impl-shared copy QString &operator=( const char * ); // deep copy#ifndef QT_NO_STL QString &operator=( const std::string& ); // deep copy#endif QString &operator=( const QCString& ); // deep copy QString &operator=( QChar c ); QString &operator=( char c ); QT_STATIC_CONST QString null; bool isNull() const; bool isEmpty() const; uint length() const; void truncate( uint pos ); QString & 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( Q_LLONG a, int fieldwidth=0, int base=10 ) const; QString arg( Q_ULLONG 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( double a, int fieldWidth = 0, char fmt = 'g', int prec = -1 ) 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( const QString& a1, const QString& a2 ) const; QString arg( const QString& a1, const QString& a2, const QString& a3 ) const; QString arg( const QString& a1, const QString& a2, const QString& a3, const QString& a4 ) const;#ifndef QT_NO_SPRINTF QString &sprintf( const char* format, ... )#if defined(Q_CC_GNU) && !defined(__INSURE__) __attribute__ ((format (printf, 2, 3)))#endif ;#endif 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;#ifndef QT_NO_REGEXP int find( const QRegExp &, int index=0 ) const;#endif#ifndef QT_NO_CAST_ASCII int find( const char* str, int index=0 ) const;#endif 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;#ifndef QT_NO_REGEXP int findRev( const QRegExp &, int index=-1 ) const;#endif#ifndef QT_NO_CAST_ASCII int findRev( const char* str, int index=-1 ) const;#endif int contains( QChar c, bool cs=TRUE ) const; int contains( char c, bool cs=TRUE ) const { return contains(QChar(c), cs); }#ifndef QT_NO_CAST_ASCII int contains( const char* str, bool cs=TRUE ) const;#endif int contains( const QString &str, bool cs=TRUE ) const;#ifndef QT_NO_REGEXP int contains( const QRegExp & ) const;#endif enum SectionFlags { SectionDefault = 0x00, SectionSkipEmpty = 0x01, SectionIncludeLeadingSep = 0x02, SectionIncludeTrailingSep = 0x04, SectionCaseInsensitiveSeps = 0x08 }; QString section( QChar sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const; QString section( char sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const;#ifndef QT_NO_CAST_ASCII QString section( const char *in_sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const;#endif QString section( const QString &in_sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const;#ifndef QT_NO_REGEXP QString section( const QRegExp ®, int start, int end = 0xffffffff, int flags = SectionDefault ) const;#endif QString left( uint len ) const; QString right( uint len ) const; QString mid( uint index, uint len=0xffffffff) const; QString leftJustify( uint width, QChar fill=' ', bool trunc=FALSE)const; QString rightJustify( uint width, QChar fill=' ',bool trunc=FALSE)const; QString lower() const; QString upper() const; QString stripWhiteSpace() const; QString simplifyWhiteSpace() const; QString &insert( uint index, const QString & );#ifndef QT_NO_CAST_ASCII QString &insert( uint index, const QByteArray & ); QString &insert( uint index, const char * );#endif QString &insert( uint index, const QChar*, uint len ); QString &insert( uint index, QChar ); QString &insert( uint index, char c ) { return insert(index,QChar(c)); } QString &append( char ); QString &append( QChar ); QString &append( const QString & );#ifndef QT_NO_CAST_ASCII QString &append( const QByteArray & ); QString &append( const char * );#endif#ifndef QT_NO_STL QString &append( const std::string& );#endif QString &prepend( char ); QString &prepend( QChar ); QString &prepend( const QString & );#ifndef QT_NO_CAST_ASCII QString &prepend( const QByteArray & ); QString &prepend( const char * );#endif#ifndef QT_NO_STL QString &prepend( const std::string& );#endif QString &remove( uint index, uint len );#if defined(Q_QDOC) QString &remove( const QString & str, bool cs = TRUE );#else // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack QString &remove( const QString & ); QString &remove( const QString &, bool cs );#endif QString &remove( QChar c ); QString &remove( char c ) { return remove( QChar(c) ); }#ifndef QT_NO_CAST_ASCII QString &remove( const char * );#endif#ifndef QT_NO_REGEXP QString &remove( const QRegExp & );#endif QString &replace( uint index, uint len, const QString & ); QString &replace( uint index, uint len, const QChar*, uint clen ); QString &replace( uint index, uint len, QChar ); QString &replace( uint index, uint len, char c ) { return replace( index, len, QChar(c) ); }#if defined(Q_QDOC) QString &replace( QChar c, const QString & after, bool cs = TRUE ); QString &replace( char c, const QString & after, bool cs = TRUE ); QString &replace( const QString & before, const QString & after, bool cs = TRUE );#else // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack QString &replace( QChar c, const QString & ); QString &replace( QChar c, const QString &, bool ); // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack QString &replace( char c, const QString & after ) { return replace( QChar(c), after, TRUE ); } QString &replace( char c, const QString & after, bool cs ) { return replace( QChar(c), after, cs ); } // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack QString &replace( const QString &, const QString & ); QString &replace( const QString &, const QString &, bool );#endif#ifndef QT_NO_REGEXP_CAPTURE QString &replace( const QRegExp &, const QString & );#endif QString &replace( QChar, QChar ); 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; Q_LLONG toLongLong( bool *ok=0, int base=10 ) const; Q_ULLONG 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 ); QString &setNum( long, int base=10 ); QString &setNum( ulong, int base=10 ); QString &setNum( Q_LLONG, int base=10 ); QString &setNum( Q_ULLONG, int base=10 ); QString &setNum( float, char f='g', int prec=6 ); QString &setNum( double, char f='g', int prec=6 ); static QString number( long, int base=10 ); static QString number( ulong, int base=10); static QString number( Q_LLONG, int base=10 ); static QString number( Q_ULLONG, 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 ); void setExpand( uint index, QChar c ); QString &operator+=( const QString &str );#ifndef QT_NO_CAST_ASCII#if defined(Q_STRICT_INLINING_RULES) inline QString &operator+=( const QByteArray &str );#else QString &operator+=( const QByteArray &str );#endif QString &operator+=( const char *str );#endif#ifndef QT_NO_STL QString &operator+=( const std::string& );#endif QString &operator+=( QChar c ); QString &operator+=( char c ); QChar at( uint i ) const { return i < d->len ? d->unicode[i] : QChar::null; } QChar operator[]( int i ) const { return at((uint)i); } QCharRef at( uint i ); QCharRef operator[]( int i ); QChar constref(uint i) const { return at(i); } QChar& ref(uint i) { // Optimized for easy-inlining by simple compilers. if ( d->count != 1 || i >= d->len ) subat( i ); d->setDirty(); return d->unicode[i]; } const QChar* unicode() const { return d->unicode; } const char* ascii() const; static QString fromAscii(const char*, int len=-1); const char* latin1() const; static QString fromLatin1(const char*, int len=-1); QCString utf8() const; static QString fromUtf8(const char*, int len=-1); QCString local8Bit() const; static QString fromLocal8Bit(const char*, int len=-1); bool operator!() const;#ifndef QT_NO_ASCII_CAST operator const char *() const { return ascii(); }#endif#ifndef QT_NO_STL operator std::string() const { return ascii() ? ascii() : ""; }#endif static QString fromUcs2( const unsigned short *ucs2 ); const unsigned short *ucs2() const; QString &setUnicode( const QChar* unicode, uint len ); QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len ); QString &setAscii( const char*, int len=-1 ); QString &setLatin1( const char*, int len=-1 ); int compare( const QString& s ) const; static int compare( const QString& s1, const QString& s2 ) { return s1.compare( s2 ); } int localeAwareCompare( const QString& s ) const; static int localeAwareCompare( const QString& s1, const QString& s2 ) { return s1.localeAwareCompare( s2 ); }#ifndef QT_NO_DATASTREAM friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & );#endif void compose();#ifndef QT_NO_COMPAT const char* data() const { return ascii(); }#endif#if defined(Q_QDOC) bool startsWith( const QString& str, bool cs = TRUE ) const; bool endsWith( const QString& str, bool cs = TRUE ) const;#else // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack bool startsWith( const QString& str ) const; bool startsWith( const QString& str, bool cs ) const; // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack bool endsWith( const QString& str ) const; bool endsWith( const QString& str, bool cs ) const;#endif void setLength( uint newLength ); uint capacity() const; void reserve( uint minCapacity ); void squeeze(); bool simpleText() const { if ( !d->issimpletext ) checkSimpleText(); return (bool)d->issimpletext; } bool isRightToLeft() const;private: QString( int size, bool /* dummy */ ); // allocate size incl. \0 void deref(); void real_detach(); void subat( uint ); QString multiArg( int numArgs, const QString& a1, const QString& a2, const QString& a3 = QString::null, const QString& a4 = QString::null ) const; void checkSimpleText() const; void grow( uint newLength );#ifndef QT_NO_CAST_ASCII QString &insertHelper( uint index, const char *s, uint len=UINT_MAX );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -