Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qcstring.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of the extended char array operations, 00005 ** and QByteArray and QCString classes 00006 ** 00007 ** Created : 920609 00008 ** 00009 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00010 ** 00011 ** This file is part of the tools module of the Qt GUI Toolkit. 00012 ** 00013 ** This file may be distributed under the terms of the Q Public License 00014 ** as defined by Trolltech ASA of Norway and appearing in the file 00015 ** LICENSE.QPL included in the packaging of this file. 00016 ** 00017 ** This file may be distributed and/or modified under the terms of the 00018 ** GNU General Public License version 2 as published by the Free Software 00019 ** Foundation and appearing in the file LICENSE.GPL included in the 00020 ** packaging of this file. 00021 ** 00022 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00023 ** licenses may use this file in accordance with the Qt Commercial License 00024 ** Agreement provided with the Software. 00025 ** 00026 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00027 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00028 ** 00029 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00030 ** information about Qt Commercial License Agreements. 00031 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00032 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00033 ** 00034 ** Contact info@trolltech.com if any conditions of this licensing are 00035 ** not clear to you. 00036 ** 00037 **********************************************************************/ 00038 00039 #ifndef QCSTRING_H 00040 #define QCSTRING_H 00041 00042 #ifndef QT_H 00043 #include "qmemarray.h" 00044 #endif // QT_H 00045 00046 #include <string.h> 00047 00048 00049 /***************************************************************************** 00050 Safe and portable C string functions; extensions to standard string.h 00051 *****************************************************************************/ 00052 00053 Q_EXPORT void *qmemmove( void *dst, const void *src, uint len ); 00054 00055 Q_EXPORT char *qstrdup( const char * ); 00056 00057 Q_EXPORT inline uint qstrlen( const char *str ) 00058 { return str ? (uint)strlen(str) : 0u; } 00059 00060 Q_EXPORT inline char *qstrcpy( char *dst, const char *src ) 00061 { return src ? strcpy(dst, src) : 0; } 00062 00063 Q_EXPORT char *qstrncpy( char *dst, const char *src, uint len ); 00064 00065 Q_EXPORT inline int qstrcmp( const char *str1, const char *str2 ) 00066 { 00067 return ( str1 && str2 ) ? strcmp( str1, str2 ) 00068 : ( str1 ? 1 : ( str2 ? -1 : 0 ) ); 00069 } 00070 00071 Q_EXPORT inline int qstrncmp( const char *str1, const char *str2, uint len ) 00072 { 00073 return ( str1 && str2 ) ? strncmp( str1, str2, len ) 00074 : ( str1 ? 1 : ( str2 ? -1 : 0 ) ); 00075 } 00076 00077 Q_EXPORT int qstricmp( const char *, const char * ); 00078 00079 Q_EXPORT int qstrnicmp( const char *, const char *, uint len ); 00080 00081 #ifndef QT_CLEAN_NAMESPACE 00082 Q_EXPORT inline uint cstrlen( const char *str ) 00083 { return (uint)strlen(str); } 00084 00085 Q_EXPORT inline char *cstrcpy( char *dst, const char *src ) 00086 { return strcpy(dst,src); } 00087 00088 Q_EXPORT inline int cstrcmp( const char *str1, const char *str2 ) 00089 { return strcmp(str1,str2); } 00090 00091 Q_EXPORT inline int cstrncmp( const char *str1, const char *str2, uint len ) 00092 { return strncmp(str1,str2,len); } 00093 #endif 00094 00095 00096 // qChecksum: Internet checksum 00097 00098 Q_EXPORT Q_UINT16 qChecksum( const char *s, uint len ); 00099 00100 /***************************************************************************** 00101 QByteArray class 00102 *****************************************************************************/ 00103 00104 #if defined(Q_QDOC) 00105 /* 00106 We want qdoc to document QByteArray as a real class that inherits 00107 QMemArray<char> and that is inherited by QBitArray. 00108 */ 00109 class QByteArray : public QMemArray<char> 00110 { 00111 public: 00112 QByteArray(); 00113 QByteArray( int size ); 00114 }; 00115 #else 00116 typedef QMemArray<char> QByteArray; 00117 #endif 00118 00119 #ifndef QT_NO_COMPRESS 00120 Q_EXPORT QByteArray qCompress( const uchar* data, int nbytes ); 00121 Q_EXPORT QByteArray qUncompress( const uchar* data, int nbytes ); 00122 Q_EXPORT inline QByteArray qCompress( const QByteArray& data) 00123 { return qCompress( (const uchar*)data.data(), data.size() ); } 00124 Q_EXPORT inline QByteArray qUncompress( const QByteArray& data ) 00125 { return qUncompress( (const uchar*)data.data(), data.size() ); } 00126 #endif 00127 00128 /***************************************************************************** 00129 QByteArray stream functions 00130 *****************************************************************************/ 00131 #ifndef QT_NO_DATASTREAM 00132 Q_EXPORT QDataStream &operator<<( QDataStream &, const QByteArray & ); 00133 Q_EXPORT QDataStream &operator>>( QDataStream &, QByteArray & ); 00134 #endif 00135 00136 /***************************************************************************** 00137 QCString class 00138 *****************************************************************************/ 00139 00140 class QRegExp; 00141 00142 class Q_EXPORT QCString : public QByteArray // C string class 00143 { 00144 public: 00145 QCString() {} // make null string 00146 QCString( int size ); // allocate size incl. \0 00147 QCString( const QCString &s ) : QByteArray( s ) {} 00148 QCString( const char *str ); // deep copy 00149 QCString( const char *str, uint maxlen ); // deep copy, max length 00150 ~QCString(); 00151 00152 QCString &operator=( const QCString &s );// shallow copy 00153 QCString &operator=( const char *str ); // deep copy 00154 00155 bool isNull() const; 00156 bool isEmpty() const; 00157 uint length() const; 00158 bool resize( uint newlen ); 00159 bool truncate( uint pos ); 00160 bool fill( char c, int len = -1 ); 00161 00162 QCString copy() const; 00163 00164 QCString &sprintf( const char *format, ... ); 00165 00166 int find( char c, int index=0, bool cs=TRUE ) const; 00167 int find( const char *str, int index=0, bool cs=TRUE ) const; 00168 #ifndef QT_NO_REGEXP 00169 int find( const QRegExp &, int index=0 ) const; 00170 #endif 00171 int findRev( char c, int index=-1, bool cs=TRUE) const; 00172 int findRev( const char *str, int index=-1, bool cs=TRUE) const; 00173 #ifndef QT_NO_REGEXP_CAPTURE 00174 int findRev( const QRegExp &, int index=-1 ) const; 00175 #endif 00176 int contains( char c, bool cs=TRUE ) const; 00177 int contains( const char *str, bool cs=TRUE ) const; 00178 #ifndef QT_NO_REGEXP 00179 int contains( const QRegExp & ) const; 00180 #endif 00181 QCString left( uint len ) const; 00182 QCString right( uint len ) const; 00183 QCString mid( uint index, uint len=0xffffffff) const; 00184 00185 QCString leftJustify( uint width, char fill=' ', bool trunc=FALSE)const; 00186 QCString rightJustify( uint width, char fill=' ',bool trunc=FALSE)const; 00187 00188 QCString lower() const; 00189 QCString upper() const; 00190 00191 QCString stripWhiteSpace() const; 00192 QCString simplifyWhiteSpace() const; 00193 00194 QCString &insert( uint index, const char * ); 00195 QCString &insert( uint index, char ); 00196 QCString &append( const char * ); 00197 QCString &prepend( const char * ); 00198 QCString &remove( uint index, uint len ); 00199 QCString &replace( uint index, uint len, const char * ); 00200 #ifndef QT_NO_REGEXP 00201 QCString &replace( const QRegExp &, const char * ); 00202 #endif 00203 QCString &replace( char c, const char *after ); 00204 QCString &replace( const char *, const char * ); 00205 QCString &replace( char, char ); 00206 00207 short toShort( bool *ok=0 ) const; 00208 ushort toUShort( bool *ok=0 ) const; 00209 int toInt( bool *ok=0 ) const; 00210 uint toUInt( bool *ok=0 ) const; 00211 long toLong( bool *ok=0 ) const; 00212 ulong toULong( bool *ok=0 ) const; 00213 float toFloat( bool *ok=0 ) const; 00214 double toDouble( bool *ok=0 ) const; 00215 00216 QCString &setStr( const char *s ); 00217 QCString &setNum( short ); 00218 QCString &setNum( ushort ); 00219 QCString &setNum( int ); 00220 QCString &setNum( uint ); 00221 QCString &setNum( long ); 00222 QCString &setNum( ulong ); 00223 QCString &setNum( float, char f='g', int prec=6 ); 00224 QCString &setNum( double, char f='g', int prec=6 ); 00225 00226 bool setExpand( uint index, char c ); 00227 00228 operator const char *() const; 00229 QCString &operator+=( const char *str ); 00230 QCString &operator+=( char c ); 00231 private: 00232 int find( const char *str, int index, bool cs, uint l ) const; 00233 }; 00234 00235 00236 /***************************************************************************** 00237 QCString stream functions 00238 *****************************************************************************/ 00239 #ifndef QT_NO_DATASTREAM 00240 Q_EXPORT QDataStream &operator<<( QDataStream &, const QCString & ); 00241 Q_EXPORT QDataStream &operator>>( QDataStream &, QCString & ); 00242 #endif 00243 00244 /***************************************************************************** 00245 QCString inline functions 00246 *****************************************************************************/ 00247 00248 inline QCString &QCString::operator=( const QCString &s ) 00249 { return (QCString&)assign( s ); } 00250 00251 inline QCString &QCString::operator=( const char *str ) 00252 { return (QCString&)duplicate( str, qstrlen(str)+1 ); } 00253 00254 inline bool QCString::isNull() const 00255 { return data() == 0; } 00256 00257 inline bool QCString::isEmpty() const 00258 { return data() == 0 || *data() == '\0'; } 00259 00260 inline uint QCString::length() const 00261 { return qstrlen( data() ); } 00262 00263 inline bool QCString::truncate( uint pos ) 00264 { return resize(pos+1); } 00265 00266 inline QCString QCString::copy() const 00267 { return QCString( data() ); } 00268 00269 inline QCString &QCString::prepend( const char *s ) 00270 { return insert(0,s); } 00271 00272 inline QCString &QCString::append( const char *s ) 00273 { return operator+=(s); } 00274 00275 inline QCString &QCString::setNum( short n ) 00276 { return setNum((long)n); } 00277 00278 inline QCString &QCString::setNum( ushort n ) 00279 { return setNum((ulong)n); } 00280 00281 inline QCString &QCString::setNum( int n ) 00282 { return setNum((long)n); } 00283 00284 inline QCString &QCString::setNum( uint n ) 00285 { return setNum((ulong)n); } 00286 00287 inline QCString &QCString::setNum( float n, char f, int prec ) 00288 { return setNum((double)n,f,prec); } 00289 00290 inline QCString::operator const char *() const 00291 { return (const char *)data(); } 00292 00293 00294 /***************************************************************************** 00295 QCString non-member operators 00296 *****************************************************************************/ 00297 00298 Q_EXPORT inline bool operator==( const QCString &s1, const QCString &s2 ) 00299 { return qstrcmp( s1.data(), s2.data() ) == 0; } 00300 00301 Q_EXPORT inline bool operator==( const QCString &s1, const char *s2 ) 00302 { return qstrcmp( s1.data(), s2 ) == 0; } 00303 00304 Q_EXPORT inline bool operator==( const char *s1, const QCString &s2 ) 00305 { return qstrcmp( s1, s2.data() ) == 0; } 00306 00307 Q_EXPORT inline bool operator!=( const QCString &s1, const QCString &s2 ) 00308 { return qstrcmp( s1.data(), s2.data() ) != 0; } 00309 00310 Q_EXPORT inline bool operator!=( const QCString &s1, const char *s2 ) 00311 { return qstrcmp( s1.data(), s2 ) != 0; } 00312 00313 Q_EXPORT inline bool operator!=( const char *s1, const QCString &s2 ) 00314 { return qstrcmp( s1, s2.data() ) != 0; } 00315 00316 Q_EXPORT inline bool operator<( const QCString &s1, const QCString& s2 ) 00317 { return qstrcmp( s1.data(), s2.data() ) < 0; } 00318 00319 Q_EXPORT inline bool operator<( const QCString &s1, const char *s2 ) 00320 { return qstrcmp( s1.data(), s2 ) < 0; } 00321 00322 Q_EXPORT inline bool operator<( const char *s1, const QCString &s2 ) 00323 { return qstrcmp( s1, s2.data() ) < 0; } 00324 00325 Q_EXPORT inline bool operator<=( const QCString &s1, const QCString &s2 ) 00326 { return qstrcmp( s1.data(), s2.data() ) <= 0; } 00327 00328 Q_EXPORT inline bool operator<=( const QCString &s1, const char *s2 ) 00329 { return qstrcmp( s1.data(), s2 ) <= 0; } 00330 00331 Q_EXPORT inline bool operator<=( const char *s1, const QCString &s2 ) 00332 { return qstrcmp( s1, s2.data() ) <= 0; } 00333 00334 Q_EXPORT inline bool operator>( const QCString &s1, const QCString &s2 ) 00335 { return qstrcmp( s1.data(), s2.data() ) > 0; } 00336 00337 Q_EXPORT inline bool operator>( const QCString &s1, const char *s2 ) 00338 { return qstrcmp( s1.data(), s2 ) > 0; } 00339 00340 Q_EXPORT inline bool operator>( const char *s1, const QCString &s2 ) 00341 { return qstrcmp( s1, s2.data() ) > 0; } 00342 00343 Q_EXPORT inline bool operator>=( const QCString &s1, const QCString& s2 ) 00344 { return qstrcmp( s1.data(), s2.data() ) >= 0; } 00345 00346 Q_EXPORT inline bool operator>=( const QCString &s1, const char *s2 ) 00347 { return qstrcmp( s1.data(), s2 ) >= 0; } 00348 00349 Q_EXPORT inline bool operator>=( const char *s1, const QCString &s2 ) 00350 { return qstrcmp( s1, s2.data() ) >= 0; } 00351 00352 Q_EXPORT inline const QCString operator+( const QCString &s1, 00353 const QCString &s2 ) 00354 { 00355 QCString tmp( s1.data() ); 00356 tmp += s2; 00357 return tmp; 00358 } 00359 00360 Q_EXPORT inline const QCString operator+( const QCString &s1, const char *s2 ) 00361 { 00362 QCString tmp( s1.data() ); 00363 tmp += s2; 00364 return tmp; 00365 } 00366 00367 Q_EXPORT inline const QCString operator+( const char *s1, const QCString &s2 ) 00368 { 00369 QCString tmp( s1 ); 00370 tmp += s2; 00371 return tmp; 00372 } 00373 00374 Q_EXPORT inline const QCString operator+( const QCString &s1, char c2 ) 00375 { 00376 QCString tmp( s1.data() ); 00377 tmp += c2; 00378 return tmp; 00379 } 00380 00381 Q_EXPORT inline const QCString operator+( char c1, const QCString &s2 ) 00382 { 00383 QCString tmp; 00384 tmp += c1; 00385 tmp += s2; 00386 return tmp; 00387 } 00388 #include "qwinexport.h" 00389 #endif // QCSTRING_H