-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 | |||
@@ -96,96 +96,107 @@ void *qmemmove( void *dst, const void *src, uint len ) | |||
96 | 96 | ||
97 | The returned string must be deleted using \c delete[]. | 97 | The returned string must be deleted using \c delete[]. |
98 | */ | 98 | */ |
99 | 99 | ||
100 | char *qstrdup( const char *src ) | 100 | char *qstrdup( const char *src ) |
101 | { | 101 | { |
102 | if ( !src ) | 102 | if ( !src ) |
103 | return 0; | 103 | return 0; |
104 | char *dst = new char[strlen(src)+1]; | 104 | char *dst = new char[strlen(src)+1]; |
105 | Q_CHECK_PTR( dst ); | 105 | Q_CHECK_PTR( dst ); |
106 | return strcpy( dst, src ); | 106 | return strcpy( dst, src ); |
107 | } | 107 | } |
108 | 108 | ||
109 | /*! | 109 | /*! |
110 | \fn char *qstrcpy( char *dst, const char *src ) | 110 | \fn char *qstrcpy( char *dst, const char *src ) |
111 | 111 | ||
112 | \relates QCString | 112 | \relates QCString |
113 | 113 | ||
114 | A safe strcpy() function. | 114 | A safe strcpy() function. |
115 | 115 | ||
116 | Copies all characters up to and including the '\0' from \a src | 116 | Copies all characters up to and including the '\0' from \a src |
117 | into \a dst and returns a pointer to \a dst. | 117 | into \a dst and returns a pointer to \a dst. |
118 | */ | 118 | */ |
119 | 119 | ||
120 | /*! | 120 | /*! |
121 | \relates QCString | 121 | \relates QCString |
122 | 122 | ||
123 | A safe strncpy() function. | 123 | A safe strncpy() function. |
124 | 124 | ||
125 | Copies at most \a len bytes from \a src (stopping at \a len or the | 125 | Copies at most \a len bytes from \a src (stopping at \a len or the |
126 | terminating '\0' whichever comes first) into \a dst and returns a | 126 | terminating '\0' whichever comes first) into \a dst and returns a |
127 | pointer to \a dst. Guarantees that \a dst is '\0'-terminated. If | 127 | pointer to \a dst. Guarantees that \a dst is '\0'-terminated. If |
128 | \a src or \a dst is 0, returns 0 immediately. | 128 | \a src or \a dst is 0, returns 0 immediately. |
129 | 129 | ||
130 | \sa qstrcpy() | 130 | \sa qstrcpy() |
131 | */ | 131 | */ |
132 | 132 | ||
133 | char *qstrncpy( char *dst, const char *src, uint len ) | 133 | char *qstrncpy( char *dst, const char *src, uint len ) |
134 | { | 134 | { |
135 | if ( !src || !dst ) | 135 | if ( !src || !dst ) |
136 | return 0; | 136 | return 0; |
137 | strncpy( dst, src, len ); | 137 | strncpy( dst, src, 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 | ||
150 | Compares \a str1 and \a str2. Returns a negative value if \a str1 | 161 | Compares \a str1 and \a str2. Returns a negative value if \a str1 |
151 | is less than \a str2, 0 if \a str1 is equal to \a str2 or a | 162 | is less than \a str2, 0 if \a str1 is equal to \a str2 or a |
152 | positive value if \a str1 is greater than \a str2. | 163 | positive value if \a str1 is greater than \a str2. |
153 | 164 | ||
154 | Special case I: Returns 0 if \a str1 and \a str2 are both 0. | 165 | Special case I: Returns 0 if \a str1 and \a str2 are both 0. |
155 | 166 | ||
156 | Special case II: Returns a random nonzero value if \a str1 is 0 | 167 | Special case II: Returns a random nonzero value if \a str1 is 0 |
157 | or \a str2 is 0 (but not both). | 168 | or \a str2 is 0 (but not both). |
158 | 169 | ||
159 | \sa qstrncmp() qstricmp() qstrnicmp() | 170 | \sa qstrncmp() qstricmp() qstrnicmp() |
160 | \link #asciinotion Note on character comparisons \endlink | 171 | \link #asciinotion Note on character comparisons \endlink |
161 | */ | 172 | */ |
162 | 173 | ||
163 | /*! | 174 | /*! |
164 | \fn int qstrncmp( const char *str1, const char *str2, uint len ); | 175 | \fn int qstrncmp( const char *str1, const char *str2, uint len ); |
165 | 176 | ||
166 | \relates QCString | 177 | \relates QCString |
167 | 178 | ||
168 | A safe strncmp() function. | 179 | A safe strncmp() function. |
169 | 180 | ||
170 | Compares at most \a len bytes of \a str1 and \a str2. | 181 | Compares at most \a len bytes of \a str1 and \a str2. |
171 | 182 | ||
172 | Returns a negative value if \a str1 is less than \a str2, 0 if \a | 183 | Returns a negative value if \a str1 is less than \a str2, 0 if \a |
173 | str1 is equal to \a str2 or a positive value if \a str1 is greater | 184 | str1 is equal to \a str2 or a positive value if \a str1 is greater |
174 | than \a str2. | 185 | than \a str2. |
175 | 186 | ||
176 | Special case I: Returns 0 if \a str1 and \a str2 are both 0. | 187 | Special case I: Returns 0 if \a str1 and \a str2 are both 0. |
177 | 188 | ||
178 | Special case II: Returns a random nonzero value if \a str1 is 0 | 189 | Special case II: Returns a random nonzero value if \a str1 is 0 |
179 | or \a str2 is 0 (but not both). | 190 | or \a str2 is 0 (but not both). |
180 | 191 | ||
181 | \sa qstrcmp(), qstricmp(), qstrnicmp() | 192 | \sa qstrcmp(), qstricmp(), qstrnicmp() |
182 | \link #asciinotion Note on character comparisons \endlink | 193 | \link #asciinotion Note on character comparisons \endlink |
183 | */ | 194 | */ |
184 | 195 | ||
185 | /*! | 196 | /*! |
186 | \relates QCString | 197 | \relates QCString |
187 | 198 | ||
188 | A safe stricmp() function. | 199 | A safe stricmp() function. |
189 | 200 | ||
190 | Compares \a str1 and \a str2 ignoring the case. | 201 | Compares \a str1 and \a str2 ignoring the case. |
191 | 202 | ||
@@ -254,190 +265,209 @@ int qstrnicmp( const char *str1, const char *str2, uint len ) | |||
254 | } | 265 | } |
255 | 266 | ||
256 | 267 | ||
257 | static Q_UINT16 crc_tbl[16]; | 268 | static Q_UINT16 crc_tbl[16]; |
258 | static bool crc_tbl_init = FALSE; | 269 | static bool crc_tbl_init = FALSE; |
259 | 270 | ||
260 | static void createCRC16Table() // build CRC16 lookup table | 271 | static void createCRC16Table() // build CRC16 lookup table |
261 | { | 272 | { |
262 | register uint i; | 273 | register uint i; |
263 | register uint j; | 274 | register uint j; |
264 | uint v0, v1, v2, v3; | 275 | uint v0, v1, v2, v3; |
265 | for ( i = 0; i < 16; i++ ) { | 276 | for ( i = 0; i < 16; i++ ) { |
266 | v0 = i & 1; | 277 | v0 = i & 1; |
267 | v1 = ( i >> 1 ) & 1; | 278 | v1 = ( i >> 1 ) & 1; |
268 | v2 = ( i >> 2 ) & 1; | 279 | v2 = ( i >> 2 ) & 1; |
269 | v3 = ( i >> 3 ) & 1; | 280 | v3 = ( i >> 3 ) & 1; |
270 | j = 0; | 281 | j = 0; |
271 | #undef SET_BIT | 282 | #undef SET_BIT |
272 | #define SET_BIT(x, b, v) (x) |= (v) << (b) | 283 | #define SET_BIT(x, b, v) (x) |= (v) << (b) |
273 | SET_BIT( j, 0, v0 ); | 284 | SET_BIT( j, 0, v0 ); |
274 | SET_BIT( j, 7, v0 ); | 285 | SET_BIT( j, 7, v0 ); |
275 | SET_BIT( j, 12, v0 ); | 286 | SET_BIT( j, 12, v0 ); |
276 | SET_BIT( j, 1, v1 ); | 287 | SET_BIT( j, 1, v1 ); |
277 | SET_BIT( j, 8, v1 ); | 288 | SET_BIT( j, 8, v1 ); |
278 | SET_BIT( j, 13, v1 ); | 289 | SET_BIT( j, 13, v1 ); |
279 | SET_BIT( j, 2, v2 ); | 290 | SET_BIT( j, 2, v2 ); |
280 | SET_BIT( j, 9, v2 ); | 291 | SET_BIT( j, 9, v2 ); |
281 | SET_BIT( j, 14, v2 ); | 292 | SET_BIT( j, 14, v2 ); |
282 | SET_BIT( j, 3, v3 ); | 293 | SET_BIT( j, 3, v3 ); |
283 | SET_BIT( j, 10, v3 ); | 294 | SET_BIT( j, 10, v3 ); |
284 | SET_BIT( j, 15, v3 ); | 295 | SET_BIT( j, 15, v3 ); |
285 | crc_tbl[i] = j; | 296 | crc_tbl[i] = j; |
286 | } | 297 | } |
287 | } | 298 | } |
288 | 299 | ||
289 | /*! | 300 | /*! |
290 | \relates QMemArray | 301 | \relates QMemArray |
291 | 302 | ||
292 | Returns the CRC-16 checksum of \a len bytes starting at \a data. | 303 | Returns the CRC-16 checksum of \a len bytes starting at \a data. |
293 | 304 | ||
294 | The checksum is independent of the byte order (endianness). | 305 | The checksum is independent of the byte order (endianness). |
295 | */ | 306 | */ |
296 | 307 | ||
297 | Q_UINT16 qChecksum( const char *data, uint len ) | 308 | Q_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 | } |
309 | } | 321 | } |
310 | register Q_UINT16 crc = 0xffff; | 322 | register Q_UINT16 crc = 0xffff; |
311 | uchar c; | 323 | uchar c; |
312 | uchar *p = (uchar *)data; | 324 | uchar *p = (uchar *)data; |
313 | while ( len-- ) { | 325 | while ( len-- ) { |
314 | c = *p++; | 326 | c = *p++; |
315 | crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)]; | 327 | crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)]; |
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 |
337 | QByteArray qCompress( const uchar* data, int nbytes ) | 355 | QByteArray qCompress( const uchar* data, int nbytes ) |
338 | { | 356 | { |
339 | if ( nbytes == 0 ) { | 357 | if ( nbytes == 0 ) { |
340 | QByteArray tmp( 4 ); | 358 | QByteArray tmp( 4 ); |
341 | tmp.fill( 0 ); | 359 | tmp.fill( 0 ); |
342 | return tmp; | 360 | return tmp; |
343 | } | 361 | } |
344 | if ( !data ) { | 362 | if ( !data ) { |
345 | #if defined(QT_CHECK_RANGE) | 363 | #if defined(QT_CHECK_RANGE) |
346 | qWarning( "qCompress: data is NULL." ); | 364 | qWarning( "qCompress: data is NULL." ); |
347 | #endif | 365 | #endif |
348 | return QByteArray(); | 366 | return QByteArray(); |
349 | } | 367 | } |
350 | 368 | ||
351 | ulong len = nbytes * 2; | 369 | ulong len = nbytes * 2; |
352 | QByteArray bazip; | 370 | QByteArray bazip; |
353 | int res; | 371 | int res; |
354 | do { | 372 | do { |
355 | bazip.resize( len + 4 ); | 373 | bazip.resize( len + 4 ); |
356 | res = ::compress( (uchar*)bazip.data()+4, &len, (uchar*)data, nbytes ); | 374 | res = ::compress( (uchar*)bazip.data()+4, &len, (uchar*)data, nbytes ); |
357 | 375 | ||
358 | switch ( res ) { | 376 | switch ( res ) { |
359 | case Z_OK: | 377 | case Z_OK: |
360 | bazip.resize( len + 4 ); | 378 | bazip.resize( len + 4 ); |
361 | bazip[0] = ( nbytes & 0xff000000 ) >> 24; | 379 | bazip[0] = ( nbytes & 0xff000000 ) >> 24; |
362 | bazip[1] = ( nbytes & 0x00ff0000 ) >> 16; | 380 | bazip[1] = ( nbytes & 0x00ff0000 ) >> 16; |
363 | bazip[2] = ( nbytes & 0x0000ff00 ) >> 8; | 381 | bazip[2] = ( nbytes & 0x0000ff00 ) >> 8; |
364 | bazip[3] = ( nbytes & 0x000000ff ); | 382 | bazip[3] = ( nbytes & 0x000000ff ); |
365 | break; | 383 | break; |
366 | case Z_MEM_ERROR: | 384 | case Z_MEM_ERROR: |
367 | #if defined(QT_CHECK_RANGE) | 385 | #if defined(QT_CHECK_RANGE) |
368 | qWarning( "qCompress: Z_MEM_ERROR: Not enough memory." ); | 386 | qWarning( "qCompress: Z_MEM_ERROR: Not enough memory." ); |
369 | #endif | 387 | #endif |
370 | bazip.resize( 0 ); | 388 | bazip.resize( 0 ); |
371 | break; | 389 | break; |
372 | case Z_BUF_ERROR: | 390 | case Z_BUF_ERROR: |
373 | len *= 2; | 391 | len *= 2; |
374 | break; | 392 | break; |
375 | } | 393 | } |
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 |
399 | QByteArray qUncompress( const uchar* data, int nbytes ) | 429 | QByteArray qUncompress( const uchar* data, int nbytes ) |
400 | { | 430 | { |
401 | if ( !data ) { | 431 | if ( !data ) { |
402 | #if defined(QT_CHECK_RANGE) | 432 | #if defined(QT_CHECK_RANGE) |
403 | qWarning( "qUncompress: data is NULL." ); | 433 | qWarning( "qUncompress: data is NULL." ); |
404 | #endif | 434 | #endif |
405 | return QByteArray(); | 435 | return QByteArray(); |
406 | } | 436 | } |
407 | if ( nbytes <= 4 ) { | 437 | if ( nbytes <= 4 ) { |
408 | #if defined(QT_CHECK_RANGE) | 438 | #if defined(QT_CHECK_RANGE) |
409 | if ( nbytes < 4 || ( data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0 ) ) | 439 | if ( nbytes < 4 || ( data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0 ) ) |
410 | qWarning( "qUncompress: Input data is corrupted." ); | 440 | qWarning( "qUncompress: Input data is corrupted." ); |
411 | #endif | 441 | #endif |
412 | return QByteArray(); | 442 | return QByteArray(); |
413 | } | 443 | } |
414 | ulong expectedSize = ( data[0] << 24 ) | ( data[1] << 16 ) | ( data[2] << 8 ) | data[3]; | 444 | ulong expectedSize = ( data[0] << 24 ) | ( data[1] << 16 ) | ( data[2] << 8 ) | data[3]; |
415 | ulong len = QMAX( expectedSize, 1 ); | 445 | ulong len = QMAX( expectedSize, 1 ); |
416 | QByteArray baunzip; | 446 | QByteArray baunzip; |
417 | int res; | 447 | int res; |
418 | do { | 448 | do { |
419 | baunzip.resize( len ); | 449 | baunzip.resize( len ); |
420 | res = ::uncompress( (uchar*)baunzip.data(), &len, | 450 | res = ::uncompress( (uchar*)baunzip.data(), &len, |
421 | (uchar*)data+4, nbytes-4 ); | 451 | (uchar*)data+4, nbytes-4 ); |
422 | 452 | ||
423 | switch ( res ) { | 453 | switch ( res ) { |
424 | case Z_OK: | 454 | case Z_OK: |
425 | if ( len != baunzip.size() ) | 455 | if ( len != baunzip.size() ) |
426 | baunzip.resize( len ); | 456 | baunzip.resize( len ); |
427 | break; | 457 | break; |
428 | case Z_MEM_ERROR: | 458 | case Z_MEM_ERROR: |
429 | #if defined(QT_CHECK_RANGE) | 459 | #if defined(QT_CHECK_RANGE) |
430 | qWarning( "qUncompress: Z_MEM_ERROR: Not enough memory." ); | 460 | qWarning( "qUncompress: Z_MEM_ERROR: Not enough memory." ); |
431 | #endif | 461 | #endif |
432 | break; | 462 | break; |
433 | case Z_BUF_ERROR: | 463 | case Z_BUF_ERROR: |
434 | len *= 2; | 464 | len *= 2; |
435 | break; | 465 | break; |
436 | case Z_DATA_ERROR: | 466 | case Z_DATA_ERROR: |
437 | #if defined(QT_CHECK_RANGE) | 467 | #if defined(QT_CHECK_RANGE) |
438 | qWarning( "qUncompress: Z_DATA_ERROR: Input data is corrupted." ); | 468 | qWarning( "qUncompress: Z_DATA_ERROR: Input data is corrupted." ); |
439 | #endif | 469 | #endif |
440 | break; | 470 | break; |
441 | } | 471 | } |
442 | } while ( res == Z_BUF_ERROR ); | 472 | } while ( res == Z_BUF_ERROR ); |
443 | 473 | ||
@@ -891,103 +921,107 @@ bool QCString::fill( char c, int len ) | |||
891 | The search is case sensitive if \a cs is TRUE, or case insensitive | 921 | The search is case sensitive if \a cs is TRUE, or case insensitive |
892 | if \a cs is FALSE. | 922 | if \a cs is FALSE. |
893 | 923 | ||
894 | Returns the position of \a c, or -1 if \a c could not be found. | 924 | Returns the position of \a c, or -1 if \a c could not be found. |
895 | 925 | ||
896 | \sa \link #asciinotion Note on character comparisons \endlink | 926 | \sa \link #asciinotion Note on character comparisons \endlink |
897 | */ | 927 | */ |
898 | 928 | ||
899 | int QCString::find( char c, int index, bool cs ) const | 929 | int QCString::find( char c, int index, bool cs ) const |
900 | { | 930 | { |
901 | if ( (uint)index >= size() ) // index outside string | 931 | if ( (uint)index >= size() ) // index outside string |
902 | return -1; | 932 | return -1; |
903 | register const char *d; | 933 | register const char *d; |
904 | if ( cs ) { // case sensitive | 934 | if ( cs ) { // case sensitive |
905 | d = strchr( data()+index, c ); | 935 | d = strchr( data()+index, c ); |
906 | } else { | 936 | } else { |
907 | d = data()+index; | 937 | d = data()+index; |
908 | c = tolower( (uchar) c ); | 938 | c = tolower( (uchar) c ); |
909 | while ( *d && tolower((uchar) *d) != c ) | 939 | while ( *d && tolower((uchar) *d) != c ) |
910 | d++; | 940 | d++; |
911 | if ( !*d && c ) // not found | 941 | if ( !*d && c ) // not found |
912 | d = 0; | 942 | d = 0; |
913 | } | 943 | } |
914 | return d ? (int)(d - data()) : -1; | 944 | return d ? (int)(d - data()) : -1; |
915 | } | 945 | } |
916 | 946 | ||
917 | #define REHASH( a ) \ | 947 | #define REHASH( a ) \ |
918 | if ( sl_minus_1 < sizeof(uint) * CHAR_BIT ) \ | 948 | if ( sl_minus_1 < sizeof(uint) * CHAR_BIT ) \ |
919 | hashHaystack -= (a) << sl_minus_1; \ | 949 | hashHaystack -= (a) << sl_minus_1; \ |
920 | hashHaystack <<= 1 | 950 | hashHaystack <<= 1 |
921 | 951 | ||
922 | /*! | 952 | /*! |
923 | \overload | 953 | \overload |
924 | 954 | ||
925 | Finds the first occurrence of the string \a str, starting at | 955 | Finds the first occurrence of the string \a str, starting at |
926 | position \a index. | 956 | position \a index. |
927 | 957 | ||
928 | The search is case sensitive if \a cs is TRUE, or case insensitive | 958 | The search is case sensitive if \a cs is TRUE, or case insensitive |
929 | if \a cs is FALSE. | 959 | if \a cs is FALSE. |
930 | 960 | ||
931 | Returns the position of \a str, or -1 if \a str could not be | 961 | Returns the position of \a str, or -1 if \a str could not be |
932 | found. | 962 | found. |
933 | 963 | ||
934 | \sa \link #asciinotion Note on character comparisons \endlink | 964 | \sa \link #asciinotion Note on character comparisons \endlink |
935 | */ | 965 | */ |
936 | 966 | ||
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; |
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 ); |
952 | 986 | ||
953 | /* | 987 | /* |
954 | See QString::find() for details. | 988 | See QString::find() for details. |
955 | */ | 989 | */ |
956 | const char* needle = str; | 990 | const char* needle = str; |
957 | const char* haystack = data() + index; | 991 | const char* haystack = data() + index; |
958 | const char* end = data() + (l-sl); | 992 | const char* end = data() + (l-sl); |
959 | const uint sl_minus_1 = sl-1; | 993 | const uint sl_minus_1 = sl-1; |
960 | uint hashNeedle = 0, hashHaystack = 0,i; | 994 | uint hashNeedle = 0, hashHaystack = 0,i; |
961 | 995 | ||
962 | if ( cs ) { | 996 | if ( cs ) { |
963 | for ( i = 0; i < sl; ++i ) { | 997 | for ( i = 0; i < sl; ++i ) { |
964 | hashNeedle = ((hashNeedle<<1) + needle[i] ); | 998 | hashNeedle = ((hashNeedle<<1) + needle[i] ); |
965 | hashHaystack = ((hashHaystack<<1) + haystack[i] ); | 999 | hashHaystack = ((hashHaystack<<1) + haystack[i] ); |
966 | } | 1000 | } |
967 | hashHaystack -= *(haystack+sl_minus_1); | 1001 | hashHaystack -= *(haystack+sl_minus_1); |
968 | 1002 | ||
969 | while ( haystack <= end ) { | 1003 | while ( haystack <= end ) { |
970 | hashHaystack += *(haystack+sl_minus_1); | 1004 | hashHaystack += *(haystack+sl_minus_1); |
971 | if ( hashHaystack == hashNeedle && *needle == *haystack | 1005 | if ( hashHaystack == hashNeedle && *needle == *haystack |
972 | && qstrncmp( needle, haystack, sl ) == 0 ) | 1006 | && qstrncmp( needle, haystack, sl ) == 0 ) |
973 | return haystack - data(); | 1007 | return haystack - data(); |
974 | 1008 | ||
975 | REHASH( *haystack ); | 1009 | REHASH( *haystack ); |
976 | ++haystack; | 1010 | ++haystack; |
977 | } | 1011 | } |
978 | } else { | 1012 | } else { |
979 | for ( i = 0; i < sl; ++i ) { | 1013 | for ( i = 0; i < sl; ++i ) { |
980 | hashNeedle = ((hashNeedle<<1) + | 1014 | hashNeedle = ((hashNeedle<<1) + |
981 | tolower( needle[i] ) ); | 1015 | tolower( needle[i] ) ); |
982 | hashHaystack = ((hashHaystack<<1) + | 1016 | hashHaystack = ((hashHaystack<<1) + |
983 | tolower( haystack[i] ) ); | 1017 | tolower( haystack[i] ) ); |
984 | } | 1018 | } |
985 | hashHaystack -= tolower(*(haystack+sl_minus_1)); | 1019 | hashHaystack -= tolower(*(haystack+sl_minus_1)); |
986 | 1020 | ||
987 | while ( haystack <= end ) { | 1021 | while ( haystack <= end ) { |
988 | hashHaystack += tolower(*(haystack+sl_minus_1)); | 1022 | hashHaystack += tolower(*(haystack+sl_minus_1)); |
989 | if ( hashHaystack == hashNeedle | 1023 | if ( hashHaystack == hashNeedle |
990 | && qstrnicmp( needle, haystack, sl ) == 0 ) | 1024 | && qstrnicmp( needle, haystack, sl ) == 0 ) |
991 | return haystack - data(); | 1025 | return haystack - data(); |
992 | 1026 | ||
993 | REHASH( tolower(*haystack) ); | 1027 | REHASH( tolower(*haystack) ); |
@@ -1107,118 +1141,118 @@ int QCString::findRev( const char *str, int index, bool cs ) const | |||
1107 | string. | 1141 | string. |
1108 | 1142 | ||
1109 | The match is case sensitive if \a cs is TRUE, or case insensitive | 1143 | The match is case sensitive if \a cs is TRUE, or case insensitive |
1110 | if \a cs if FALSE. | 1144 | if \a cs if FALSE. |
1111 | 1145 | ||
1112 | \sa \link #asciinotion Note on character comparisons \endlink | 1146 | \sa \link #asciinotion Note on character comparisons \endlink |
1113 | */ | 1147 | */ |
1114 | 1148 | ||
1115 | int QCString::contains( char c, bool cs ) const | 1149 | int QCString::contains( char c, bool cs ) const |
1116 | { | 1150 | { |
1117 | int count = 0; | 1151 | int count = 0; |
1118 | char *d = data(); | 1152 | char *d = data(); |
1119 | if ( !d ) | 1153 | if ( !d ) |
1120 | return 0; | 1154 | return 0; |
1121 | if ( cs ) { // case sensitive | 1155 | if ( cs ) { // case sensitive |
1122 | while ( *d ) | 1156 | while ( *d ) |
1123 | if ( *d++ == c ) | 1157 | if ( *d++ == c ) |
1124 | count++; | 1158 | count++; |
1125 | } else { // case insensitive | 1159 | } else { // case insensitive |
1126 | c = tolower( (uchar) c ); | 1160 | c = tolower( (uchar) c ); |
1127 | while ( *d ) { | 1161 | while ( *d ) { |
1128 | if ( tolower((uchar) *d) == c ) | 1162 | if ( tolower((uchar) *d) == c ) |
1129 | count++; | 1163 | count++; |
1130 | d++; | 1164 | d++; |
1131 | } | 1165 | } |
1132 | } | 1166 | } |
1133 | return count; | 1167 | return count; |
1134 | } | 1168 | } |
1135 | 1169 | ||
1136 | /*! | 1170 | /*! |
1137 | \overload | 1171 | \overload |
1138 | 1172 | ||
1139 | Returns the number of times \a str occurs in the string. | 1173 | Returns the number of times \a str occurs in the string. |
1140 | 1174 | ||
1141 | The match is case sensitive if \a cs is TRUE, or case insensitive | 1175 | The match is case sensitive if \a cs is TRUE, or case insensitive |
1142 | if \a cs if FALSE. | 1176 | if \a cs if FALSE. |
1143 | 1177 | ||
1144 | This function counts overlapping substrings, for example, "banana" | 1178 | This function counts overlapping substrings, for example, "banana" |
1145 | contains two occurrences of "ana". | 1179 | contains two occurrences of "ana". |
1146 | 1180 | ||
1147 | \sa findRev() | 1181 | \sa findRev() |
1148 | \link #asciinotion Note on character comparisons \endlink | 1182 | \link #asciinotion Note on character comparisons \endlink |
1149 | */ | 1183 | */ |
1150 | 1184 | ||
1151 | int QCString::contains( const char *str, bool cs ) const | 1185 | int 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 |
1163 | of the string. | 1198 | of the string. |
1164 | 1199 | ||
1165 | The whole string is returned if \a len exceeds the length of the | 1200 | The whole string is returned if \a len exceeds the length of the |
1166 | string. | 1201 | string. |
1167 | 1202 | ||
1168 | Example: | 1203 | Example: |
1169 | \code | 1204 | \code |
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 | |||
1177 | QCString QCString::left( uint len ) const | 1211 | QCString 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() ) { |
1183 | QCString same( data() ); | 1217 | QCString same( data() ); |
1184 | return same; | 1218 | return same; |
1185 | } else { | 1219 | } else { |
1186 | QCString s( len+1 ); | 1220 | QCString s( len+1 ); |
1187 | strncpy( s.data(), data(), len ); | 1221 | strncpy( s.data(), data(), len ); |
1188 | *(s.data()+len) = '\0'; | 1222 | *(s.data()+len) = '\0'; |
1189 | return s; | 1223 | return s; |
1190 | } | 1224 | } |
1191 | } | 1225 | } |
1192 | 1226 | ||
1193 | /*! | 1227 | /*! |
1194 | Returns a substring that contains the \a len rightmost characters | 1228 | Returns a substring that contains the \a len rightmost characters |
1195 | of the string. | 1229 | of the string. |
1196 | 1230 | ||
1197 | The whole string is returned if \a len exceeds the length of the | 1231 | The whole string is returned if \a len exceeds the length of the |
1198 | string. | 1232 | string. |
1199 | 1233 | ||
1200 | Example: | 1234 | Example: |
1201 | \code | 1235 | \code |
1202 | QCString s = "Pineapple"; | 1236 | QCString s = "Pineapple"; |
1203 | QCString t = s.right( 5 ); // t == "apple" | 1237 | QCString t = s.right( 5 ); // t == "apple" |
1204 | \endcode | 1238 | \endcode |
1205 | 1239 | ||
1206 | \sa left(), mid() | 1240 | \sa left(), mid() |
1207 | */ | 1241 | */ |
1208 | 1242 | ||
1209 | QCString QCString::right( uint len ) const | 1243 | QCString QCString::right( uint len ) const |
1210 | { | 1244 | { |
1211 | if ( isEmpty() ) { | 1245 | if ( isEmpty() ) { |
1212 | QCString empty; | 1246 | QCString empty; |
1213 | return empty; | 1247 | return empty; |
1214 | } else { | 1248 | } else { |
1215 | uint l = length(); | 1249 | uint l = length(); |
1216 | if ( len > l ) | 1250 | if ( len > l ) |
1217 | len = l; | 1251 | len = l; |
1218 | char *p = data() + (l - len); | 1252 | char *p = data() + (l - len); |
1219 | return QCString( p ); | 1253 | return QCString( p ); |
1220 | } | 1254 | } |
1221 | } | 1255 | } |
1222 | 1256 | ||
1223 | /*! | 1257 | /*! |
1224 | Returns a substring that contains at most \a len characters from | 1258 | Returns a substring that contains at most \a len characters from |
@@ -1452,439 +1486,442 @@ QCString QCString::simplifyWhiteSpace() const | |||
1452 | char *from= data(); | 1486 | char *from= data(); |
1453 | char *to= result.data(); | 1487 | char *to= result.data(); |
1454 | char *first = to; | 1488 | char *first = to; |
1455 | for ( ;; ) { | 1489 | for ( ;; ) { |
1456 | while ( isspace((uchar) *from) ) | 1490 | while ( isspace((uchar) *from) ) |
1457 | from++; | 1491 | from++; |
1458 | while ( *from && !isspace((uchar) *from) ) | 1492 | while ( *from && !isspace((uchar) *from) ) |
1459 | *to++ = *from++; | 1493 | *to++ = *from++; |
1460 | if ( *from ) | 1494 | if ( *from ) |
1461 | *to++ = 0x20; // ' ' | 1495 | *to++ = 0x20; // ' ' |
1462 | else | 1496 | else |
1463 | break; | 1497 | break; |
1464 | } | 1498 | } |
1465 | if ( to > first && *(to-1) == 0x20 ) | 1499 | if ( to > first && *(to-1) == 0x20 ) |
1466 | to--; | 1500 | to--; |
1467 | *to = '\0'; | 1501 | *to = '\0'; |
1468 | result.resize( (int)(to - result.data()) + 1 ); | 1502 | result.resize( (int)(to - result.data()) + 1 ); |
1469 | return result; | 1503 | return result; |
1470 | } | 1504 | } |
1471 | 1505 | ||
1472 | 1506 | ||
1473 | /*! | 1507 | /*! |
1474 | \overload | 1508 | \overload |
1475 | 1509 | ||
1476 | Inserts string \a s into the string at position \a index. | 1510 | Inserts string \a s into the string at position \a index. |
1477 | 1511 | ||
1478 | If \a index is beyond the end of the string, the string is | 1512 | If \a index is beyond the end of the string, the string is |
1479 | padded with spaces (ASCII 32) to length \a index and then \a s | 1513 | padded with spaces (ASCII 32) to length \a index and then \a s |
1480 | is appended. | 1514 | is appended. |
1481 | 1515 | ||
1482 | \code | 1516 | \code |
1483 | QCString s = "I like fish"; | 1517 | QCString s = "I like fish"; |
1484 | s.insert( 2, "don't "); // s == "I don't like fish" | 1518 | s.insert( 2, "don't "); // s == "I don't like fish" |
1485 | 1519 | ||
1486 | s = "x"; // index 01234 | 1520 | s = "x"; // index 01234 |
1487 | s.insert( 3, "yz" ); // s == "x yz" | 1521 | s.insert( 3, "yz" ); // s == "x yz" |
1488 | \endcode | 1522 | \endcode |
1489 | */ | 1523 | */ |
1490 | 1524 | ||
1491 | QCString &QCString::insert( uint index, const char *s ) | 1525 | QCString &QCString::insert( uint index, const char *s ) |
1492 | { | 1526 | { |
1493 | int len = qstrlen(s); | 1527 | int len = qstrlen(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 |
1514 | returns a reference to the string. | 1550 | returns a reference to the string. |
1515 | 1551 | ||
1516 | If \a index is beyond the end of the string, the string is | 1552 | If \a index is beyond the end of the string, the string is |
1517 | padded with spaces (ASCII 32) to length \a index and then \a c | 1553 | padded with spaces (ASCII 32) to length \a index and then \a c |
1518 | is appended. | 1554 | is appended. |
1519 | 1555 | ||
1520 | Example: | 1556 | Example: |
1521 | \code | 1557 | \code |
1522 | QCString s = "Yes"; | 1558 | QCString s = "Yes"; |
1523 | s.insert( 3, '!'); // s == "Yes!" | 1559 | s.insert( 3, '!'); // s == "Yes!" |
1524 | \endcode | 1560 | \endcode |
1525 | 1561 | ||
1526 | \sa remove(), replace() | 1562 | \sa remove(), replace() |
1527 | */ | 1563 | */ |
1528 | 1564 | ||
1529 | QCString &QCString::insert( uint index, char c )// insert char | 1565 | QCString &QCString::insert( uint index, char c )// insert char |
1530 | { | 1566 | { |
1531 | char buf[2]; | 1567 | char buf[2]; |
1532 | buf[0] = c; | 1568 | buf[0] = c; |
1533 | buf[1] = '\0'; | 1569 | buf[1] = '\0'; |
1534 | return insert( index, buf ); | 1570 | return insert( index, buf ); |
1535 | } | 1571 | } |
1536 | 1572 | ||
1537 | /*! | 1573 | /*! |
1538 | \fn QCString &QCString::prepend( const char *s ) | 1574 | \fn QCString &QCString::prepend( const char *s ) |
1539 | 1575 | ||
1540 | Prepend \a s to the string. Equivalent to insert(0, s). | 1576 | Prepend \a s to the string. Equivalent to insert(0, s). |
1541 | 1577 | ||
1542 | \sa insert() | 1578 | \sa insert() |
1543 | */ | 1579 | */ |
1544 | 1580 | ||
1545 | /*! | 1581 | /*! |
1546 | Removes \a len characters from the string, starting at position \a | 1582 | Removes \a len characters from the string, starting at position \a |
1547 | index, and returns a reference to the string. | 1583 | index, and returns a reference to the string. |
1548 | 1584 | ||
1549 | If \a index is out of range, nothing happens. If \a index is | 1585 | If \a index is out of range, nothing happens. If \a index is |
1550 | valid, but \a index + \a len is larger than the length of the | 1586 | valid, but \a index + \a len is larger than the length of the |
1551 | string, the string is truncated at position \a index. | 1587 | string, the string is truncated at position \a index. |
1552 | 1588 | ||
1553 | \code | 1589 | \code |
1554 | QCString s = "Montreal"; | 1590 | QCString s = "Montreal"; |
1555 | s.remove( 1, 4 ); // s == "Meal" | 1591 | s.remove( 1, 4 ); // s == "Meal" |
1556 | \endcode | 1592 | \endcode |
1557 | 1593 | ||
1558 | \sa insert(), replace() | 1594 | \sa insert(), replace() |
1559 | */ | 1595 | */ |
1560 | 1596 | ||
1561 | QCString &QCString::remove( uint index, uint len ) | 1597 | QCString &QCString::remove( uint index, uint len ) |
1562 | { | 1598 | { |
1563 | uint olen = length(); | 1599 | uint olen = length(); |
1564 | if ( index + len >= olen ) { // range problems | 1600 | if ( index + len >= olen ) { // range problems |
1565 | if ( index < olen ) { // index ok | 1601 | if ( index < olen ) { // index ok |
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 |
1579 | \a index, with \a str, and returns a reference to the string. | 1615 | \a index, with \a str, and returns a reference to the string. |
1580 | 1616 | ||
1581 | If \a index is out of range, nothing is removed and \a str is | 1617 | If \a index is out of range, nothing is removed and \a str is |
1582 | appended at the end of the string. If \a index is valid, but \a | 1618 | appended at the end of the string. If \a index is valid, but \a |
1583 | index + \a len is larger than the length of the string, \a str | 1619 | index + \a len is larger than the length of the string, \a str |
1584 | replaces the rest of the string from position \a index. | 1620 | replaces the rest of the string from position \a index. |
1585 | 1621 | ||
1586 | \code | 1622 | \code |
1587 | QCString s = "Say yes!"; | 1623 | QCString s = "Say yes!"; |
1588 | s.replace( 4, 3, "NO" ); // s == "Say NO!" | 1624 | s.replace( 4, 3, "NO" ); // s == "Say NO!" |
1589 | \endcode | 1625 | \endcode |
1590 | 1626 | ||
1591 | \sa insert(), remove() | 1627 | \sa insert(), remove() |
1592 | */ | 1628 | */ |
1593 | 1629 | ||
1594 | QCString &QCString::replace( uint index, uint len, const char *str ) | 1630 | QCString &QCString::replace( uint index, uint len, const char *str ) |
1595 | { | 1631 | { |
1596 | remove( index, len ); | 1632 | remove( index, len ); |
1597 | insert( index, str ); | 1633 | insert( index, str ); |
1598 | return *this; | 1634 | return *this; |
1599 | } | 1635 | } |
1600 | 1636 | ||
1601 | 1637 | ||
1602 | /*! \overload | 1638 | /*! \overload |
1603 | 1639 | ||
1604 | Replaces every occurrence of the character \a c in the string | 1640 | Replaces every occurrence of the character \a c in the string |
1605 | with \a after. Returns a reference to the string. | 1641 | with \a after. Returns a reference to the string. |
1606 | 1642 | ||
1607 | Example: | 1643 | Example: |
1608 | \code | 1644 | \code |
1609 | QCString s = "a,b,c"; | 1645 | QCString s = "a,b,c"; |
1610 | s.replace( ',', " or " ); | 1646 | s.replace( ',', " or " ); |
1611 | // s == "a or b or c" | 1647 | // s == "a or b or c" |
1612 | \endcode | 1648 | \endcode |
1613 | */ | 1649 | */ |
1614 | QCString &QCString::replace( char c, const char *after ) | 1650 | QCString &QCString::replace( char c, const char *after ) |
1615 | { | 1651 | { |
1616 | char str[2]; | 1652 | char str[2]; |
1617 | str[0] = c; | 1653 | str[0] = c; |
1618 | str[1] = '\0'; | 1654 | str[1] = '\0'; |
1619 | return replace( str, after ); | 1655 | return replace( str, after ); |
1620 | } | 1656 | } |
1621 | 1657 | ||
1622 | /*! \overload | 1658 | /*! \overload |
1623 | 1659 | ||
1624 | Replaces every occurrence of the string \a before in the string | 1660 | Replaces every occurrence of the string \a before in the string |
1625 | with the string \a after. Returns a reference to the string. | 1661 | with the string \a after. Returns a reference to the string. |
1626 | 1662 | ||
1627 | Example: | 1663 | Example: |
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 | |||
1634 | QCString &QCString::replace( const char *before, const char *after ) | 1671 | QCString &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(); |
1640 | 1677 | ||
1641 | int index = 0; | 1678 | int index = 0; |
1642 | const int bl = before ? strlen( before ) : 0; | 1679 | const int bl = before ? strlen( before ) : 0; |
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 | } |
1665 | } else { | 1702 | } else { |
1666 | to = index; | 1703 | to = index; |
1667 | } | 1704 | } |
1668 | if ( al ) { | 1705 | if ( al ) { |
1669 | memcpy( d + to, after, al ); | 1706 | memcpy( d + to, after, al ); |
1670 | to += al; | 1707 | to += al; |
1671 | } | 1708 | } |
1672 | index += bl; | 1709 | index += bl; |
1673 | movestart = index; | 1710 | movestart = index; |
1674 | num++; | 1711 | num++; |
1675 | } | 1712 | } |
1676 | if ( num ) { | 1713 | if ( num ) { |
1677 | int msize = len - movestart; | 1714 | int msize = len - movestart; |
1678 | if ( msize > 0 ) | 1715 | if ( msize > 0 ) |
1679 | memmove( d + to, d + movestart, msize ); | 1716 | memmove( d + to, d + movestart, msize ); |
1680 | resize( len - num*(bl-al) + 1 ); | 1717 | resize( len - num*(bl-al) + 1 ); |
1681 | } | 1718 | } |
1682 | } else { | 1719 | } else { |
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 ) |
1696 | index++; | 1733 | index++; |
1697 | } | 1734 | } |
1698 | if ( !pos ) | 1735 | if ( !pos ) |
1699 | break; | 1736 | break; |
1700 | 1737 | ||
1701 | // we have a table of replacement positions, use them for fast replacing | 1738 | // we have a table of replacement positions, use them for fast replacing |
1702 | int adjust = pos*(al-bl); | 1739 | int adjust = pos*(al-bl); |
1703 | // index has to be adjusted in case we get back into the loop above. | 1740 | // index has to be adjusted in case we get back into the loop above. |
1704 | if ( index != -1 ) | 1741 | if ( index != -1 ) |
1705 | index += adjust; | 1742 | index += adjust; |
1706 | uint newlen = len + adjust; | 1743 | uint newlen = len + adjust; |
1707 | int moveend = len; | 1744 | int moveend = len; |
1708 | if ( newlen > len ) { | 1745 | if ( newlen > len ) { |
1709 | resize( newlen + 1 ); | 1746 | resize( newlen + 1 ); |
1710 | len = newlen; | 1747 | len = newlen; |
1711 | } | 1748 | } |
1712 | d = data(); | 1749 | d = data(); |
1713 | 1750 | ||
1714 | while( pos ) { | 1751 | while( pos ) { |
1715 | pos--; | 1752 | pos--; |
1716 | int movestart = indices[pos] + bl; | 1753 | int movestart = indices[pos] + bl; |
1717 | int insertstart = indices[pos] + pos*(al-bl); | 1754 | int insertstart = indices[pos] + pos*(al-bl); |
1718 | int moveto = insertstart + al; | 1755 | int moveto = insertstart + al; |
1719 | memmove( d + moveto, d + movestart, (moveend - movestart) ); | 1756 | memmove( d + moveto, d + movestart, (moveend - movestart) ); |
1720 | if ( after ) | 1757 | if ( after ) |
1721 | memcpy( d + insertstart, after, al ); | 1758 | memcpy( d + insertstart, after, al ); |
1722 | moveend = movestart - bl; | 1759 | moveend = movestart - bl; |
1723 | } | 1760 | } |
1724 | } | 1761 | } |
1725 | } | 1762 | } |
1726 | return *this; | 1763 | return *this; |
1727 | } | 1764 | } |
1728 | 1765 | ||
1729 | /*! \overload | 1766 | /*! \overload |
1730 | 1767 | ||
1731 | Replaces every occurrence of \a c1 with the char \a c2. | 1768 | Replaces every occurrence of \a c1 with the char \a c2. |
1732 | Returns a reference to the string. | 1769 | Returns a reference to the string. |
1733 | */ | 1770 | */ |
1734 | QCString &QCString::replace( char c1, char c2 ) | 1771 | QCString &QCString::replace( char c1, char c2 ) |
1735 | { | 1772 | { |
1736 | detach(); | 1773 | detach(); |
1737 | uint i = 0; | 1774 | uint i = 0; |
1738 | char *d = data(); | 1775 | char *d = data(); |
1739 | uint len = length(); | 1776 | uint len = length(); |
1740 | while ( i < len ) { | 1777 | while ( i < len ) { |
1741 | if ( d[i] == c1 ) | 1778 | if ( d[i] == c1 ) |
1742 | d[i] = c2; | 1779 | d[i] = c2; |
1743 | i++; | 1780 | i++; |
1744 | } | 1781 | } |
1745 | return *this; | 1782 | return *this; |
1746 | } | 1783 | } |
1747 | 1784 | ||
1748 | 1785 | ||
1749 | #ifndef QT_NO_REGEXP_CAPTURE | 1786 | #ifndef QT_NO_REGEXP_CAPTURE |
1750 | /*! | 1787 | /*! |
1751 | \overload | 1788 | \overload |
1752 | 1789 | ||
1753 | Finds the first occurrence of the regular expression \a rx, | 1790 | Finds the first occurrence of the regular expression \a rx, |
1754 | starting at position \a index. | 1791 | starting at position \a index. |
1755 | 1792 | ||
1756 | Returns the position of the next match, or -1 if \a rx was not | 1793 | Returns the position of the next match, or -1 if \a rx was not |
1757 | found. | 1794 | found. |
1758 | 1795 | ||
1759 | \warning If you want to apply this function repeatedly to the same | 1796 | \warning If you want to apply this function repeatedly to the same |
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 | ||
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 | } |
1769 | 1806 | ||
1770 | /*! | 1807 | /*! |
1771 | \overload | 1808 | \overload |
1772 | 1809 | ||
1773 | Finds the first occurrence of the regular expression \a rx, | 1810 | Finds the first occurrence of the regular expression \a rx, |
1774 | starting at position \a index and searching backwards. | 1811 | starting at position \a index and searching backwards. |
1775 | 1812 | ||
1776 | Returns the position of the next match (backwards), or -1 if \a rx | 1813 | Returns the position of the next match (backwards), or -1 if \a rx |
1777 | was not found. | 1814 | was not found. |
1778 | 1815 | ||
1779 | \warning If you want to apply this function repeatedly to the same | 1816 | \warning If you want to apply this function repeatedly to the same |
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 | ||
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 | } |
1789 | 1826 | ||
1790 | /*! | 1827 | /*! |
1791 | \overload | 1828 | \overload |
1792 | 1829 | ||
1793 | Counts the number of overlapping occurrences of \a rx in the string. | 1830 | Counts the number of overlapping occurrences of \a rx in the string. |
1794 | 1831 | ||
1795 | Example: | 1832 | Example: |
1796 | \code | 1833 | \code |
1797 | QString s = "banana and panama"; | 1834 | QString s = "banana and panama"; |
1798 | QRegExp r = QRegExp( "a[nm]a", TRUE, FALSE ); | 1835 | QRegExp r = QRegExp( "a[nm]a", TRUE, FALSE ); |
1799 | s.contains( r ); // 4 matches | 1836 | s.contains( r ); // 4 matches |
1800 | \endcode | 1837 | \endcode |
1801 | 1838 | ||
1802 | \sa find(), findRev() | 1839 | \sa find(), findRev() |
1803 | 1840 | ||
1804 | \warning If you want to apply this function repeatedly to the same | 1841 | \warning If you want to apply this function repeatedly to the same |
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 | ||
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 | } |
1814 | 1851 | ||
1815 | 1852 | ||
1816 | /*! | 1853 | /*! |
1817 | \overload | 1854 | \overload |
1818 | 1855 | ||
1819 | Replaces every occurrence of \a rx in the string with \a str. | 1856 | Replaces every occurrence of \a rx in the string with \a str. |
1820 | Returns a reference to the string. | 1857 | Returns a reference to the string. |
1821 | 1858 | ||
1822 | Example: | 1859 | Example: |
1823 | \code | 1860 | \code |
1824 | QString s = "banana"; | 1861 | QString s = "banana"; |
1825 | s.replace( QRegExp("a.*a"), "" ); // becomes "b" | 1862 | s.replace( QRegExp("a.*a"), "" ); // becomes "b" |
1826 | 1863 | ||
1827 | s = "banana"; | 1864 | s = "banana"; |
1828 | s.replace( QRegExp("^[bn]a"), "X" ); // becomes "Xnana" | 1865 | s.replace( QRegExp("^[bn]a"), "X" ); // becomes "Xnana" |
1829 | 1866 | ||
1830 | s = "banana"; | 1867 | s = "banana"; |
1831 | s.replace( QRegExp("^[bn]a"), "" ); // becomes "nana" | 1868 | s.replace( QRegExp("^[bn]a"), "" ); // becomes "nana" |
1832 | \endcode | 1869 | \endcode |
1833 | 1870 | ||
1834 | \warning If you want to apply this function repeatedly to the same | 1871 | \warning If you want to apply this function repeatedly to the same |
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 | ||
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() ); |
1845 | return *this; | 1882 | return *this; |
1846 | } | 1883 | } |
1847 | #endif //QT_NO_REGEXP | 1884 | #endif //QT_NO_REGEXP |
1848 | 1885 | ||
1849 | /*! | 1886 | /*! |
1850 | Returns the string converted to a \c long value. | 1887 | Returns the string converted to a \c long value. |
1851 | 1888 | ||
1852 | If \a ok is not 0: \a *ok is set to FALSE if the string is not a | 1889 | If \a ok is not 0: \a *ok is set to FALSE if the string is not a |
1853 | number, or if it has trailing garbage; otherwise \a *ok is set to | 1890 | number, or if it has trailing garbage; otherwise \a *ok is set to |
1854 | TRUE. | 1891 | TRUE. |
1855 | */ | 1892 | */ |
1856 | 1893 | ||
1857 | long QCString::toLong( bool *ok ) const | 1894 | long QCString::toLong( bool *ok ) const |
1858 | { | 1895 | { |
1859 | char *p = data(); | 1896 | char *p = data(); |
1860 | long val=0; | 1897 | long val=0; |
1861 | const long max_mult = 214748364; | 1898 | const long max_mult = 214748364; |
1862 | bool is_ok = FALSE; | 1899 | bool is_ok = FALSE; |
1863 | int neg = 0; | 1900 | int neg = 0; |
1864 | if ( !p ) | 1901 | if ( !p ) |
1865 | goto bye; | 1902 | goto bye; |
1866 | while ( isspace((uchar) *p) ) // skip leading space | 1903 | while ( isspace((uchar) *p) ) // skip leading space |
1867 | p++; | 1904 | p++; |
1868 | if ( *p == '-' ) { | 1905 | if ( *p == '-' ) { |
1869 | p++; | 1906 | p++; |
1870 | neg = 1; | 1907 | neg = 1; |
1871 | } else if ( *p == '+' ) { | 1908 | } else if ( *p == '+' ) { |
1872 | p++; | 1909 | p++; |
1873 | } | 1910 | } |
1874 | if ( !isdigit((uchar) *p) ) | 1911 | if ( !isdigit((uchar) *p) ) |
1875 | goto bye; | 1912 | goto bye; |
1876 | while ( isdigit((uchar) *p) ) { | 1913 | while ( isdigit((uchar) *p) ) { |
1877 | if ( val > max_mult || (val == max_mult && (*p-'0') > 7+neg) ) | 1914 | if ( val > max_mult || (val == max_mult && (*p-'0') > 7+neg) ) |
1878 | goto bye; | 1915 | goto bye; |
1879 | val = 10*val + (*p++ - '0'); | 1916 | val = 10*val + (*p++ - '0'); |
1880 | } | 1917 | } |
1881 | if ( neg ) | 1918 | if ( neg ) |
1882 | val = -val; | 1919 | val = -val; |
1883 | while ( isspace((uchar) *p) ) // skip trailing space | 1920 | while ( isspace((uchar) *p) ) // skip trailing space |
1884 | p++; | 1921 | p++; |
1885 | if ( *p == '\0' ) | 1922 | if ( *p == '\0' ) |
1886 | is_ok = TRUE; | 1923 | is_ok = TRUE; |
1887 | bye: | 1924 | bye: |
1888 | if ( ok ) | 1925 | if ( ok ) |
1889 | *ok = is_ok; | 1926 | *ok = is_ok; |
1890 | return is_ok ? val : 0; | 1927 | return is_ok ? val : 0; |
@@ -2154,113 +2191,113 @@ QCString &QCString::setNum( double n, char f, int prec ) | |||
2154 | Sets the character at position \a index to \a c and expands the | 2191 | Sets the character at position \a index to \a c and expands the |
2155 | string if necessary, padding with spaces. | 2192 | string if necessary, padding with spaces. |
2156 | 2193 | ||
2157 | Returns FALSE if \a index was out of range and the string could | 2194 | Returns FALSE if \a index was out of range and the string could |
2158 | not be expanded; otherwise returns TRUE. | 2195 | not be expanded; otherwise returns TRUE. |
2159 | */ | 2196 | */ |
2160 | 2197 | ||
2161 | bool QCString::setExpand( uint index, char c ) | 2198 | bool QCString::setExpand( uint index, char c ) |
2162 | { | 2199 | { |
2163 | detach(); | 2200 | detach(); |
2164 | uint oldlen = length(); | 2201 | uint oldlen = length(); |
2165 | if ( index >= oldlen ) { | 2202 | if ( index >= oldlen ) { |
2166 | if ( !QByteArray::resize( index+2 ) )// no memory | 2203 | if ( !QByteArray::resize( index+2 ) )// no memory |
2167 | return FALSE; | 2204 | return FALSE; |
2168 | if ( index > oldlen ) | 2205 | if ( index > oldlen ) |
2169 | memset( data() + oldlen, ' ', index - oldlen ); | 2206 | memset( data() + oldlen, ' ', index - oldlen ); |
2170 | *(data() + index+1) = '\0'; // terminate padded string | 2207 | *(data() + index+1) = '\0'; // terminate padded string |
2171 | } | 2208 | } |
2172 | *(data() + index) = c; | 2209 | *(data() + index) = c; |
2173 | return TRUE; | 2210 | return TRUE; |
2174 | } | 2211 | } |
2175 | 2212 | ||
2176 | 2213 | ||
2177 | /*! | 2214 | /*! |
2178 | \fn QCString::operator const char *() const | 2215 | \fn QCString::operator const char *() const |
2179 | 2216 | ||
2180 | Returns the string data. | 2217 | Returns the string data. |
2181 | */ | 2218 | */ |
2182 | 2219 | ||
2183 | 2220 | ||
2184 | /*! | 2221 | /*! |
2185 | \fn QCString& QCString::append( const char *str ) | 2222 | \fn QCString& QCString::append( const char *str ) |
2186 | 2223 | ||
2187 | Appends string \a str to the string and returns a reference to the | 2224 | Appends string \a str to the string and returns a reference to the |
2188 | string. Equivalent to operator+=(). | 2225 | string. Equivalent to operator+=(). |
2189 | */ | 2226 | */ |
2190 | 2227 | ||
2191 | /*! | 2228 | /*! |
2192 | Appends string \a str to the string and returns a reference to the string. | 2229 | Appends string \a str to the string and returns a reference to the string. |
2193 | */ | 2230 | */ |
2194 | 2231 | ||
2195 | QCString& QCString::operator+=( const char *str ) | 2232 | 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 | /*! |
2209 | \overload | 2246 | \overload |
2210 | 2247 | ||
2211 | Appends character \a c to the string and returns a reference to the string. | 2248 | Appends character \a c to the string and returns a reference to the string. |
2212 | */ | 2249 | */ |
2213 | 2250 | ||
2214 | QCString &QCString::operator+=( char c ) | 2251 | QCString &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 | ||
2225 | 2262 | ||
2226 | /***************************************************************************** | 2263 | /***************************************************************************** |
2227 | QCString stream functions | 2264 | QCString stream functions |
2228 | *****************************************************************************/ | 2265 | *****************************************************************************/ |
2229 | #ifndef QT_NO_DATASTREAM | 2266 | #ifndef QT_NO_DATASTREAM |
2230 | /*! | 2267 | /*! |
2231 | \relates QCString | 2268 | \relates QCString |
2232 | 2269 | ||
2233 | Writes string \a str to the stream \a s. | 2270 | Writes string \a str to the stream \a s. |
2234 | 2271 | ||
2235 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink | 2272 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink |
2236 | */ | 2273 | */ |
2237 | QDataStream &operator<<( QDataStream &s, const QCString &str ) | 2274 | QDataStream &operator<<( QDataStream &s, const QCString &str ) |
2238 | { | 2275 | { |
2239 | return s.writeBytes( str.data(), str.size() ); | 2276 | return s.writeBytes( str.data(), str.size() ); |
2240 | } | 2277 | } |
2241 | 2278 | ||
2242 | /*! | 2279 | /*! |
2243 | \relates QCString | 2280 | \relates QCString |
2244 | 2281 | ||
2245 | Reads a string into \a str from the stream \a s. | 2282 | Reads a string into \a str from the stream \a s. |
2246 | 2283 | ||
2247 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink | 2284 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink |
2248 | */ | 2285 | */ |
2249 | 2286 | ||
2250 | QDataStream &operator>>( QDataStream &s, QCString &str ) | 2287 | QDataStream &operator>>( QDataStream &s, QCString &str ) |
2251 | { | 2288 | { |
2252 | str.detach(); | 2289 | str.detach(); |
2253 | Q_UINT32 len; | 2290 | Q_UINT32 len; |
2254 | s >> len; // read size of string | 2291 | s >> len; // read size of string |
2255 | if ( len == 0 || s.eof() ) { // end of file reached | 2292 | if ( len == 0 || s.eof() ) { // end of file reached |
2256 | str.resize( 0 ); | 2293 | str.resize( 0 ); |
2257 | return s; | 2294 | return s; |
2258 | } | 2295 | } |
2259 | if ( !str.QByteArray::resize( (uint)len )) {// resize string | 2296 | if ( !str.QByteArray::resize( (uint)len )) {// resize string |
2260 | #if defined(QT_CHECK_NULL) | 2297 | #if defined(QT_CHECK_NULL) |
2261 | qWarning( "QDataStream: Not enough memory to read QCString" ); | 2298 | qWarning( "QDataStream: Not enough memory to read QCString" ); |
2262 | #endif | 2299 | #endif |
2263 | len = 0; | 2300 | len = 0; |
2264 | } | 2301 | } |
2265 | if ( len > 0 ) // not null array | 2302 | if ( len > 0 ) // not null array |
2266 | s.readRawBytes( str.data(), (uint)len ); | 2303 | s.readRawBytes( str.data(), (uint)len ); |