-rw-r--r-- | qmake/tools/qcstring.cpp | 107 |
1 files changed, 72 insertions, 35 deletions
diff --git a/qmake/tools/qcstring.cpp b/qmake/tools/qcstring.cpp index cf1b853..4651b97 100644 --- a/qmake/tools/qcstring.cpp +++ b/qmake/tools/qcstring.cpp | |||
@@ -142,4 +142,15 @@ char *qstrncpy( char *dst, const char *src, uint len ) | |||
142 | 142 | ||
143 | /*! | 143 | /*! |
144 | \fn uint qstrlen( const char *str ); | ||
145 | |||
146 | \relates QCString | ||
147 | |||
148 | A safe strlen function. | ||
149 | |||
150 | Returns the number of characters that precede the terminating '\0'. | ||
151 | or 0 if \a str is 0. | ||
152 | */ | ||
153 | |||
154 | /*! | ||
144 | \fn int qstrcmp( const char *str1, const char *str2 ); | 155 | \fn int qstrcmp( const char *str1, const char *str2 ); |
145 | 156 | ||
@@ -300,5 +311,6 @@ Q_UINT16 qChecksum( const char *data, uint len ) | |||
300 | 311 | ||
301 | #ifdef QT_THREAD_SUPPORT | 312 | #ifdef QT_THREAD_SUPPORT |
302 | QMutexLocker locker( qt_global_mutexpool->get( &crc_tbl_init ) ); | 313 | QMutexLocker locker( qt_global_mutexpool ? |
314 | qt_global_mutexpool->get( &crc_tbl_init ) : 0 ); | ||
303 | #endif // QT_THREAD_SUPPORT | 315 | #endif // QT_THREAD_SUPPORT |
304 | 316 | ||
@@ -320,16 +332,22 @@ Q_UINT16 qChecksum( const char *data, uint len ) | |||
320 | } | 332 | } |
321 | 333 | ||
322 | /*! \fn QByteArray qCompress( const QByteArray& data) | 334 | /*! |
323 | \relates QByteArray | 335 | \fn QByteArray qCompress( const QByteArray& data ) |
324 | \overload | 336 | |
337 | \relates QByteArray | ||
338 | |||
339 | Compresses the array \a data and returns the compressed byte | ||
340 | array. | ||
341 | |||
342 | \sa qUncompress() | ||
325 | */ | 343 | */ |
326 | 344 | ||
327 | /*! | 345 | /*! |
328 | \relates QByteArray | 346 | \relates QByteArray |
329 | 347 | ||
330 | Compresses the array \a data which is \a nbytes long and returns the | 348 | \overload |
331 | compressed byte array. | ||
332 | 349 | ||
333 | \sa qUncompress() | 350 | Compresses the array \a data which is \a nbytes long and returns the |
351 | compressed byte array. | ||
334 | */ | 352 | */ |
335 | 353 | ||
@@ -380,18 +398,30 @@ QByteArray qCompress( const uchar* data, int nbytes ) | |||
380 | #endif | 398 | #endif |
381 | 399 | ||
382 | /*! \fn QByteArray qUncompress( const QByteArray& data ) | 400 | /*! |
383 | \relates QByteArray | 401 | \fn QByteArray qUncompress( const QByteArray& data ) |
384 | \overload | 402 | |
403 | \relates QByteArray | ||
404 | |||
405 | Uncompresses the array \a data and returns the uncompressed byte | ||
406 | array. | ||
407 | |||
408 | Returns an empty QByteArray if the input data was corrupt. | ||
409 | \omit | ||
410 | ADD THE FOLLOWING FOR Qt 4.0 | ||
411 | This function will uncompress data compressed with qCompress() | ||
412 | from this and any earlier Qt version, back to Qt 3.1 when this | ||
413 | feature was added. | ||
414 | \endomit | ||
415 | |||
416 | \sa qCompress() | ||
385 | */ | 417 | */ |
386 | 418 | ||
387 | /*! | 419 | /*! |
388 | \relates QByteArray | 420 | \relates QByteArray |
389 | |||
390 | Uncompresses the array \a data which is \a nbytes long and returns | ||
391 | the uncompressed byte array. | ||
392 | 421 | ||
393 | Returns an empty QByteArray if the input data was corrupt. | 422 | \overload |
394 | 423 | ||
395 | \sa qCompress() | 424 | Uncompresses the array \a data which is \a nbytes long and returns |
425 | the uncompressed byte array. | ||
396 | */ | 426 | */ |
397 | 427 | ||
@@ -937,4 +967,9 @@ int QCString::find( char c, int index, bool cs ) const | |||
937 | int QCString::find( const char *str, int index, bool cs ) const | 967 | int QCString::find( const char *str, int index, bool cs ) const |
938 | { | 968 | { |
969 | return find( str, index, cs, length() ); | ||
970 | } | ||
971 | |||
972 | int QCString::find( const char *str, int index, bool cs, uint l ) const | ||
973 | { | ||
939 | if ( (uint)index >= size() ) | 974 | if ( (uint)index >= size() ) |
940 | return -1; | 975 | return -1; |
@@ -943,5 +978,4 @@ int QCString::find( const char *str, int index, bool cs ) const | |||
943 | if ( !*str ) | 978 | if ( !*str ) |
944 | return index; | 979 | return index; |
945 | const uint l = length(); | ||
946 | const uint sl = qstrlen( str ); | 980 | const uint sl = qstrlen( str ); |
947 | if ( sl + index > l ) | 981 | if ( sl + index > l ) |
@@ -1153,6 +1187,7 @@ int QCString::contains( const char *str, bool cs ) const | |||
1153 | int count = 0; | 1187 | int count = 0; |
1154 | int i = -1; | 1188 | int i = -1; |
1189 | uint l = length(); | ||
1155 | // use find for the faster hashing algorithm | 1190 | // use find for the faster hashing algorithm |
1156 | while ( ( i = find ( str, i+1, cs ) ) != -1 ) | 1191 | while ( ( i = find ( str, i+1, cs, l ) ) != -1 ) |
1157 | count++; | 1192 | count++; |
1158 | return count; | 1193 | return count; |
@@ -1174,5 +1209,4 @@ int QCString::contains( const char *str, bool cs ) const | |||
1174 | \sa right(), mid() | 1209 | \sa right(), mid() |
1175 | */ | 1210 | */ |
1176 | |||
1177 | QCString QCString::left( uint len ) const | 1211 | QCString QCString::left( uint len ) const |
1178 | { | 1212 | { |
@@ -1498,12 +1532,14 @@ QCString &QCString::insert( uint index, const char *s ) | |||
1498 | if ( index >= olen ) { // insert after end of string | 1532 | if ( index >= olen ) { // insert after end of string |
1499 | detach(); | 1533 | detach(); |
1500 | if ( QByteArray::resize(nlen+index-olen+1) ) { | 1534 | if ( QByteArray::resize(nlen+index-olen+1, QByteArray::SpeedOptim ) ) { |
1501 | memset( data()+olen, ' ', index-olen ); | 1535 | memset( data()+olen, ' ', index-olen ); |
1502 | memcpy( data()+index, s, len+1 ); | 1536 | memcpy( data()+index, s, len+1 ); |
1503 | } | 1537 | } |
1504 | } else if ( QByteArray::resize(nlen+1) ) {// normal insert | 1538 | } else { |
1505 | detach(); | 1539 | detach(); |
1506 | memmove( data()+index+len, data()+index, olen-index+1 ); | 1540 | if ( QByteArray::resize(nlen+1, QByteArray::SpeedOptim ) ) {// normal insert |
1507 | memcpy( data()+index, s, len ); | 1541 | memmove( data()+index+len, data()+index, olen-index+1 ); |
1542 | memcpy( data()+index, s, len ); | ||
1543 | } | ||
1508 | } | 1544 | } |
1509 | return *this; | 1545 | return *this; |
@@ -1570,5 +1606,5 @@ QCString &QCString::remove( uint index, uint len ) | |||
1570 | detach(); | 1606 | detach(); |
1571 | memmove( data()+index, data()+index+len, olen-index-len+1 ); | 1607 | memmove( data()+index, data()+index+len, olen-index-len+1 ); |
1572 | QByteArray::resize(olen-len+1); | 1608 | QByteArray::resize(olen-len+1, QByteArray::SpeedOptim ); |
1573 | } | 1609 | } |
1574 | return *this; | 1610 | return *this; |
@@ -1632,4 +1668,5 @@ QCString &QCString::replace( char c, const char *after ) | |||
1632 | \endcode | 1668 | \endcode |
1633 | */ | 1669 | */ |
1670 | |||
1634 | QCString &QCString::replace( const char *before, const char *after ) | 1671 | QCString &QCString::replace( const char *before, const char *after ) |
1635 | { | 1672 | { |
@@ -1647,5 +1684,5 @@ QCString &QCString::replace( const char *before, const char *after ) | |||
1647 | if ( bl == al ) { | 1684 | if ( bl == al ) { |
1648 | if ( bl ) { | 1685 | if ( bl ) { |
1649 | while( (index = find( before, index ) ) != -1 ) { | 1686 | while( (index = find( before, index, TRUE, len ) ) != -1 ) { |
1650 | memcpy( d+index, after, al ); | 1687 | memcpy( d+index, after, al ); |
1651 | index += bl; | 1688 | index += bl; |
@@ -1656,5 +1693,5 @@ QCString &QCString::replace( const char *before, const char *after ) | |||
1656 | uint movestart = 0; | 1693 | uint movestart = 0; |
1657 | uint num = 0; | 1694 | uint num = 0; |
1658 | while( (index = find( before, index ) ) != -1 ) { | 1695 | while( (index = find( before, index, TRUE, len ) ) != -1 ) { |
1659 | if ( num ) { | 1696 | if ( num ) { |
1660 | int msize = index - movestart; | 1697 | int msize = index - movestart; |
@@ -1687,5 +1724,5 @@ QCString &QCString::replace( const char *before, const char *after ) | |||
1687 | uint pos = 0; | 1724 | uint pos = 0; |
1688 | while( pos < 4095 ) { | 1725 | while( pos < 4095 ) { |
1689 | index = find(before, index); | 1726 | index = find(before, index, TRUE, len); |
1690 | if ( index == -1 ) | 1727 | if ( index == -1 ) |
1691 | break; | 1728 | break; |
@@ -1764,5 +1801,5 @@ QCString &QCString::replace( char c1, char c2 ) | |||
1764 | int QCString::find( const QRegExp& rx, int index ) const | 1801 | int QCString::find( const QRegExp& rx, int index ) const |
1765 | { | 1802 | { |
1766 | QString d = QString::fromLatin1( data() ); | 1803 | QString d = QString::fromAscii( data() ); |
1767 | return d.find( rx, index ); | 1804 | return d.find( rx, index ); |
1768 | } | 1805 | } |
@@ -1784,5 +1821,5 @@ int QCString::find( const QRegExp& rx, int index ) const | |||
1784 | int QCString::findRev( const QRegExp& rx, int index ) const | 1821 | int QCString::findRev( const QRegExp& rx, int index ) const |
1785 | { | 1822 | { |
1786 | QString d = QString::fromLatin1( data() ); | 1823 | QString d = QString::fromAscii( data() ); |
1787 | return d.findRev( rx, index ); | 1824 | return d.findRev( rx, index ); |
1788 | } | 1825 | } |
@@ -1809,5 +1846,5 @@ int QCString::findRev( const QRegExp& rx, int index ) const | |||
1809 | int QCString::contains( const QRegExp &rx ) const | 1846 | int QCString::contains( const QRegExp &rx ) const |
1810 | { | 1847 | { |
1811 | QString d = QString::fromLatin1( data() ); | 1848 | QString d = QString::fromAscii( data() ); |
1812 | return d.contains( rx ); | 1849 | return d.contains( rx ); |
1813 | } | 1850 | } |
@@ -1839,6 +1876,6 @@ int QCString::contains( const QRegExp &rx ) const | |||
1839 | QCString &QCString::replace( const QRegExp &rx, const char *str ) | 1876 | QCString &QCString::replace( const QRegExp &rx, const char *str ) |
1840 | { | 1877 | { |
1841 | QString d = QString::fromLatin1( data() ); | 1878 | QString d = QString::fromAscii( data() ); |
1842 | QString r = QString::fromLatin1( str ); | 1879 | QString r = QString::fromAscii( str ); |
1843 | d.replace( rx, r ); | 1880 | d.replace( rx, r ); |
1844 | setStr( d.ascii() ); | 1881 | setStr( d.ascii() ); |
@@ -2200,5 +2237,5 @@ QCString& QCString::operator+=( const char *str ) | |||
2200 | uint len1 = length(); | 2237 | uint len1 = length(); |
2201 | uint len2 = qstrlen(str); | 2238 | uint len2 = qstrlen(str); |
2202 | if ( !QByteArray::resize( len1 + len2 + 1 ) ) | 2239 | if ( !QByteArray::resize( len1 + len2 + 1, QByteArray::SpeedOptim ) ) |
2203 | return *this; // no memory | 2240 | return *this; // no memory |
2204 | memcpy( data() + len1, str, len2 + 1 ); | 2241 | memcpy( data() + len1, str, len2 + 1 ); |
@@ -2216,5 +2253,5 @@ QCString &QCString::operator+=( char c ) | |||
2216 | detach(); | 2253 | detach(); |
2217 | uint len = length(); | 2254 | uint len = length(); |
2218 | if ( !QByteArray::resize( len + 2 ) ) | 2255 | if ( !QByteArray::resize( len + 2, QByteArray::SpeedOptim ) ) |
2219 | return *this; // no memory | 2256 | return *this; // no memory |
2220 | *(data() + len) = c; | 2257 | *(data() + len) = c; |