summaryrefslogtreecommitdiff
path: root/qmake/tools/qcstring.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qcstring.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qcstring.cpp107
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
@@ -138,12 +138,23 @@ char *qstrncpy( char *dst, const char *src, uint len )
138 if ( len > 0 ) 138 if ( len > 0 )
139 dst[len-1] = '\0'; 139 dst[len-1] = '\0';
140 return dst; 140 return dst;
141} 141}
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
146 \relates QCString 157 \relates QCString
147 158
148 A safe strcmp() function. 159 A safe strcmp() function.
149 160
@@ -296,13 +307,14 @@ static void createCRC16Table() // build CRC16 lookup table
296 307
297Q_UINT16 qChecksum( const char *data, uint len ) 308Q_UINT16 qChecksum( const char *data, uint len )
298{ 309{
299 if ( !crc_tbl_init ) { // create lookup table 310 if ( !crc_tbl_init ) { // create lookup table
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
305 if ( !crc_tbl_init ) { 317 if ( !crc_tbl_init ) {
306 createCRC16Table(); 318 createCRC16Table();
307 crc_tbl_init = TRUE; 319 crc_tbl_init = TRUE;
308 } 320 }
@@ -316,24 +328,30 @@ Q_UINT16 qChecksum( const char *data, uint len )
316 c >>= 4; 328 c >>= 4;
317 crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)]; 329 crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)];
318 } 330 }
319 return ~crc & 0xffff; 331 return ~crc & 0xffff;
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
336#ifndef QT_NO_COMPRESS 354#ifndef QT_NO_COMPRESS
337QByteArray qCompress( const uchar* data, int nbytes ) 355QByteArray qCompress( const uchar* data, int nbytes )
338{ 356{
339 if ( nbytes == 0 ) { 357 if ( nbytes == 0 ) {
@@ -376,26 +394,38 @@ QByteArray qCompress( const uchar* data, int nbytes )
376 } while ( res == Z_BUF_ERROR ); 394 } while ( res == Z_BUF_ERROR );
377 395
378 return bazip; 396 return bazip;
379} 397}
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
398#ifndef QT_NO_COMPRESS 428#ifndef QT_NO_COMPRESS
399QByteArray qUncompress( const uchar* data, int nbytes ) 429QByteArray qUncompress( const uchar* data, int nbytes )
400{ 430{
401 if ( !data ) { 431 if ( !data ) {
@@ -933,19 +963,23 @@ int QCString::find( char c, int index, bool cs ) const
933 963
934 \sa \link #asciinotion Note on character comparisons \endlink 964 \sa \link #asciinotion Note on character comparisons \endlink
935*/ 965*/
936 966
937int QCString::find( const char *str, int index, bool cs ) const 967int QCString::find( const char *str, int index, bool cs ) const
938{ 968{
969 return find( str, index, cs, length() );
970}
971
972int 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;
941 if ( !str ) 976 if ( !str )
942 return -1; 977 return -1;
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 )
948 return -1; 982 return -1;
949 983
950 if ( sl == 1 ) 984 if ( sl == 1 )
951 return find( *str, index, cs ); 985 return find( *str, index, cs );
@@ -1149,14 +1183,15 @@ int QCString::contains( char c, bool cs ) const
1149*/ 1183*/
1150 1184
1151int QCString::contains( const char *str, bool cs ) const 1185int QCString::contains( const char *str, bool cs ) const
1152{ 1186{
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;
1159} 1194}
1160 1195
1161/*! 1196/*!
1162 Returns a substring that contains the \a len leftmost characters 1197 Returns a substring that contains the \a len leftmost characters
@@ -1170,13 +1205,12 @@ int QCString::contains( const char *str, bool cs ) const
1170 QCString s = "Pineapple"; 1205 QCString s = "Pineapple";
1171 QCString t = s.left( 4 ); // t == "Pine" 1206 QCString t = s.left( 4 ); // t == "Pine"
1172 \endcode 1207 \endcode
1173 1208
1174 \sa right(), mid() 1209 \sa right(), mid()
1175*/ 1210*/
1176
1177QCString QCString::left( uint len ) const 1211QCString QCString::left( uint len ) const
1178{ 1212{
1179 if ( isEmpty() ) { 1213 if ( isEmpty() ) {
1180 QCString empty; 1214 QCString empty;
1181 return empty; 1215 return empty;
1182 } else if ( len >= size() ) { 1216 } else if ( len >= size() ) {
@@ -1494,20 +1528,22 @@ QCString &QCString::insert( uint index, const char *s )
1494 if ( len == 0 ) 1528 if ( len == 0 )
1495 return *this; 1529 return *this;
1496 uint olen = length(); 1530 uint olen = length();
1497 int nlen = olen + len; 1531 int nlen = olen + len;
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;
1510} 1546}
1511 1547
1512/*! 1548/*!
1513 Inserts character \a c into the string at position \a index and 1549 Inserts character \a c into the string at position \a index and
@@ -1566,13 +1602,13 @@ QCString &QCString::remove( uint index, uint len )
1566 detach(); 1602 detach();
1567 resize( index+1 ); 1603 resize( index+1 );
1568 } 1604 }
1569 } else if ( len != 0 ) { 1605 } else if ( len != 0 ) {
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;
1575} 1611}
1576 1612
1577/*! 1613/*!
1578 Replaces \a len characters from the string, starting at position 1614 Replaces \a len characters from the string, starting at position
@@ -1628,12 +1664,13 @@ QCString &QCString::replace( char c, const char *after )
1628 \code 1664 \code
1629 QCString s = "Greek is Greek"; 1665 QCString s = "Greek is Greek";
1630 s.replace( "Greek", "English" ); 1666 s.replace( "Greek", "English" );
1631 // s == "English is English" 1667 // s == "English is English"
1632 \endcode 1668 \endcode
1633*/ 1669*/
1670
1634QCString &QCString::replace( const char *before, const char *after ) 1671QCString &QCString::replace( const char *before, const char *after )
1635{ 1672{
1636 if ( before == after || isNull() ) 1673 if ( before == after || isNull() )
1637 return *this; 1674 return *this;
1638 1675
1639 detach(); 1676 detach();
@@ -1643,22 +1680,22 @@ QCString &QCString::replace( const char *before, const char *after )
1643 const int al = after ? strlen( after ) : 0; 1680 const int al = after ? strlen( after ) : 0;
1644 char *d = data(); 1681 char *d = data();
1645 uint len = length(); 1682 uint len = length();
1646 1683
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;
1652 } 1689 }
1653 } 1690 }
1654 } else if ( al < bl ) { 1691 } else if ( al < bl ) {
1655 uint to = 0; 1692 uint to = 0;
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;
1661 if ( msize > 0 ) { 1698 if ( msize > 0 ) {
1662 memmove( d + to, d + movestart, msize ); 1699 memmove( d + to, d + movestart, msize );
1663 to += msize; 1700 to += msize;
1664 } 1701 }
@@ -1683,13 +1720,13 @@ QCString &QCString::replace( const char *before, const char *after )
1683 // the most complex case. We don't want to loose performance by doing repeated 1720 // the most complex case. We don't want to loose performance by doing repeated
1684 // copies and reallocs of the string. 1721 // copies and reallocs of the string.
1685 while( index != -1 ) { 1722 while( index != -1 ) {
1686 uint indices[4096]; 1723 uint indices[4096];
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;
1692 indices[pos++] = index; 1729 indices[pos++] = index;
1693 index += bl; 1730 index += bl;
1694 // avoid infinite loop 1731 // avoid infinite loop
1695 if ( !bl ) 1732 if ( !bl )
@@ -1760,13 +1797,13 @@ QCString &QCString::replace( char c1, char c2 )
1760 string it is more efficient to convert the string to a QString and 1797 string it is more efficient to convert the string to a QString and
1761 apply the function to that. 1798 apply the function to that.
1762*/ 1799*/
1763 1800
1764int QCString::find( const QRegExp& rx, int index ) const 1801int 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}
1769 1806
1770/*! 1807/*!
1771 \overload 1808 \overload
1772 1809
@@ -1780,13 +1817,13 @@ int QCString::find( const QRegExp& rx, int index ) const
1780 string it is more efficient to convert the string to a QString and 1817 string it is more efficient to convert the string to a QString and
1781 apply the function to that. 1818 apply the function to that.
1782*/ 1819*/
1783 1820
1784int QCString::findRev( const QRegExp& rx, int index ) const 1821int 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}
1789 1826
1790/*! 1827/*!
1791 \overload 1828 \overload
1792 1829
@@ -1805,13 +1842,13 @@ int QCString::findRev( const QRegExp& rx, int index ) const
1805 string it is more efficient to convert the string to a QString and 1842 string it is more efficient to convert the string to a QString and
1806 apply the function to that. 1843 apply the function to that.
1807*/ 1844*/
1808 1845
1809int QCString::contains( const QRegExp &rx ) const 1846int 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}
1814 1851
1815 1852
1816/*! 1853/*!
1817 \overload 1854 \overload
@@ -1835,14 +1872,14 @@ int QCString::contains( const QRegExp &rx ) const
1835 string it is more efficient to convert the string to a QString and 1872 string it is more efficient to convert the string to a QString and
1836 apply the function to that. 1873 apply the function to that.
1837*/ 1874*/
1838 1875
1839QCString &QCString::replace( const QRegExp &rx, const char *str ) 1876QCString &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() );
1845 return *this; 1882 return *this;
1846} 1883}
1847#endif //QT_NO_REGEXP 1884#endif //QT_NO_REGEXP
1848 1885
@@ -2196,13 +2233,13 @@ QCString& QCString::operator+=( const char *str )
2196{ 2233{
2197 if ( !str ) 2234 if ( !str )
2198 return *this; // nothing to append 2235 return *this; // nothing to append
2199 detach(); 2236 detach();
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 );
2205 return *this; 2242 return *this;
2206} 2243}
2207 2244
2208/*! 2245/*!
@@ -2212,13 +2249,13 @@ QCString& QCString::operator+=( const char *str )
2212*/ 2249*/
2213 2250
2214QCString &QCString::operator+=( char c ) 2251QCString &QCString::operator+=( char c )
2215{ 2252{
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;
2221 *(data() + len+1) = '\0'; 2258 *(data() + len+1) = '\0';
2222 return *this; 2259 return *this;
2223} 2260}
2224 2261