00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "qstringlist.h"
00039
00040 #ifndef QT_NO_STRINGLIST
00041 #include "qregexp.h"
00042 #include "qstrlist.h"
00043 #include "qdatastream.h"
00044 #include "qtl.h"
00045
00181 void QStringList::sort()
00182 {
00183 qHeapSort( *this );
00184 }
00185
00195 QStringList QStringList::split( const QChar &sep, const QString &str,
00196 bool allowEmptyEntries )
00197 {
00198 return split( QString(sep), str, allowEmptyEntries );
00199 }
00200
00218 QStringList QStringList::split( const QString &sep, const QString &str,
00219 bool allowEmptyEntries )
00220 {
00221 QStringList lst;
00222
00223 int j = 0;
00224 int i = str.find( sep, j );
00225
00226 while ( i != -1 ) {
00227 if ( i > j && i <= (int)str.length() )
00228 lst << str.mid( j, i - j );
00229 else if ( allowEmptyEntries )
00230 lst << QString::null;
00231 j = i + sep.length();
00232 i = str.find( sep, sep.length() > 0 ? j : j+1 );
00233 }
00234
00235 int l = str.length() - 1;
00236 if ( str.mid( j, l - j + 1 ).length() > 0 )
00237 lst << str.mid( j, l - j + 1 );
00238 else if ( allowEmptyEntries )
00239 lst << QString::null;
00240
00241 return lst;
00242 }
00243
00244 #ifndef QT_NO_REGEXP
00245
00264 QStringList QStringList::split( const QRegExp &sep, const QString &str,
00265 bool allowEmptyEntries )
00266 {
00267 QStringList lst;
00268
00269 QRegExp tep = sep;
00270
00271 int j = 0;
00272 int i = tep.search( str, j );
00273
00274 while ( i != -1 ) {
00275 if ( str.mid( j, i - j ).length() > 0 )
00276 lst << str.mid( j, i - j );
00277 else if ( allowEmptyEntries )
00278 lst << QString::null;
00279 if ( tep.matchedLength() == 0 )
00280 j = i + 1;
00281 else
00282 j = i + tep.matchedLength();
00283 i = tep.search( str, j );
00284 }
00285
00286 int l = str.length() - 1;
00287 if ( str.mid( j, l - j + 1 ).length() > 0 )
00288 lst << str.mid( j, l - j + 1 );
00289 else if ( allowEmptyEntries )
00290 lst << QString::null;
00291
00292 return lst;
00293 }
00294 #endif
00295
00303 QStringList QStringList::grep( const QString &str, bool cs ) const
00304 {
00305 QStringList res;
00306 for ( QStringList::ConstIterator it = begin(); it != end(); ++it )
00307 if ( (*it).contains(str, cs) )
00308 res << *it;
00309
00310 return res;
00311 }
00312
00313 #ifndef QT_NO_REGEXP
00314
00321 QStringList QStringList::grep( const QRegExp &expr ) const
00322 {
00323 QStringList res;
00324 for ( QStringList::ConstIterator it = begin(); it != end(); ++it )
00325 if ( (*it).contains(expr) )
00326 res << *it;
00327
00328 return res;
00329 }
00330 #endif
00331
00338 QString QStringList::join( const QString &sep ) const
00339 {
00340 QString res;
00341 bool alredy = FALSE;
00342 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00343 if ( alredy )
00344 res += sep;
00345 alredy = TRUE;
00346 res += *it;
00347 }
00348
00349 return res;
00350 }
00351
00352 #ifndef QT_NO_DATASTREAM
00353 Q_EXPORT QDataStream &operator>>( QDataStream & s, QStringList& l )
00354 {
00355 return s >> (QValueList<QString>&)l;
00356 }
00357
00358 Q_EXPORT QDataStream &operator<<( QDataStream & s, const QStringList& l )
00359 {
00360 return s << (const QValueList<QString>&)l;
00361 }
00362 #endif
00363
00367 QStringList QStringList::fromStrList(const QStrList& ascii)
00368 {
00369 QStringList res;
00370 const char * s;
00371 for ( QStrListIterator it(ascii); (s=it.current()); ++it )
00372 res << s;
00373 return res;
00374 }
00375
00376 #endif //QT_NO_STRINGLIST