1 /****************************************************************************
2 ** $Id: qt/qcstring.cpp   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Implementation of extended char array operations, and QByteArray and
5 ** QCString classes
6 **
7 ** Created : 920722
8 **
9 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
10 **
11 ** This file is part of the tools module of the Qt GUI Toolkit.
12 **
13 ** This file may be distributed under the terms of the Q Public License
14 ** as defined by Trolltech ASA of Norway and appearing in the file
15 ** LICENSE.QPL included in the packaging of this file.
16 **
17 ** This file may be distributed and/or modified under the terms of the
18 ** GNU General Public License version 2 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.GPL included in the
20 ** packaging of this file.
21 **
22 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
23 ** licenses may use this file in accordance with the Qt Commercial License
24 ** Agreement provided with the Software.
25 **
26 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
27 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 **
29 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
30 **   information about Qt Commercial License Agreements.
31 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
32 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
33 **
34 ** Contact info@trolltech.com if any conditions of this licensing are
35 ** not clear to you.
36 **
37 **********************************************************************/
38 
39 #include "qstring.h"
40 #include "qregexp.h"
41 #include "qdatastream.h"
42 
43 #ifdef QT_THREAD_SUPPORT
44 #  include <private/qmutexpool_p.h>
45 #endif // QT_THREAD_SUPPORT
46 
47 #include <stdio.h>
48 #include <stdarg.h>
49 #include <stdlib.h>
50 #include <ctype.h>
51 #include <limits.h>
52 #ifndef QT_NO_COMPRESS
53 #include "../3rdparty/zlib/zlib.h"
54 #endif
55 
56 /*****************************************************************************
57   Safe and portable C string functions; extensions to standard string.h
58  *****************************************************************************/
59 
60 /*!
61     \relates QCString
62 
63     This function is normally part of the C library. Qt implements
64     memmove() for platforms that do not provide it.
65 
66     memmove() copies \a len bytes from \a src into \a dst. The data
67     is copied correctly even if \a src and \a dst overlap.
68 */
69 
qmemmove(void * dst,const void * src,uint len)70 void *qmemmove( void *dst, const void *src, uint len )
71 {
72     register char *d;
73     register char *s;
74     if ( dst > src ) {
75 	d = (char *)dst + len - 1;
76 	s = (char *)src + len - 1;
77 	while ( len-- )
78 	    *d-- = *s--;
79     } else if ( dst < src ) {
80 	d = (char *)dst;
81 	s = (char *)src;
82 	while ( len-- )
83 	    *d++ = *s++;
84     }
85     return dst;
86 }
87 
88 
89 /*!
90     \relates QCString
91 
92     Returns a duplicate string.
93 
94     Allocates space for a copy of \a src, copies it, and returns a
95     pointer to the copy. If \a src is 0, it immediately returns 0.
96 
97     The returned string must be deleted using \c delete[].
98 */
99 
qstrdup(const char * src)100 char *qstrdup( const char *src )
101 {
102     if ( !src )
103 	return 0;
104     char *dst = new char[strlen(src)+1];
105     Q_CHECK_PTR( dst );
106     return strcpy( dst, src );
107 }
108 
109 /*!
110     \fn char *qstrcpy( char *dst, const char *src )
111 
112     \relates QCString
113 
114     A safe strcpy() function.
115 
116     Copies all characters up to and including the '\0' from \a src
117     into \a dst and returns a pointer to \a dst.
118 */
119 
120 /*!
121     \relates QCString
122 
123     A safe strncpy() function.
124 
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
127     pointer to \a dst. Guarantees that \a dst is '\0'-terminated. If
128     \a src or \a dst is 0, returns 0 immediately.
129 
130     \sa qstrcpy()
131 */
132 
qstrncpy(char * dst,const char * src,uint len)133 char *qstrncpy( char *dst, const char *src, uint len )
134 {
135     if ( !src || !dst )
136 	return 0;
137     strncpy( dst, src, len );
138     if ( len > 0 )
139 	dst[len-1] = '\0';
140     return dst;
141 }
142 
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 /*!
155     \fn int qstrcmp( const char *str1, const char *str2 );
156 
157     \relates QCString
158 
159     A safe strcmp() function.
160 
161     Compares \a str1 and \a str2. Returns a negative value if \a str1
162     is less than \a str2, 0 if \a str1 is equal to \a str2 or a
163     positive value if \a str1 is greater than \a str2.
164 
165     Special case I: Returns 0 if \a str1 and \a str2 are both 0.
166 
167     Special case II: Returns a random nonzero value if \a str1 is 0
168     or \a str2 is 0 (but not both).
169 
170     \sa qstrncmp() qstricmp() qstrnicmp()
171 	\link #asciinotion Note on character comparisons \endlink
172 */
173 
174 /*!
175     \fn int qstrncmp( const char *str1, const char *str2, uint len );
176 
177     \relates QCString
178 
179     A safe strncmp() function.
180 
181     Compares at most \a len bytes of \a str1 and \a str2.
182 
183     Returns a negative value if \a str1 is less than \a str2, 0 if \a
184     str1 is equal to \a str2 or a positive value if \a str1 is greater
185     than \a str2.
186 
187     Special case I: Returns 0 if \a str1 and \a str2 are both 0.
188 
189     Special case II: Returns a random nonzero value if \a str1 is 0
190     or \a str2 is 0 (but not both).
191 
192     \sa qstrcmp(), qstricmp(), qstrnicmp()
193 	\link #asciinotion Note on character comparisons \endlink
194 */
195 
196 /*!
197     \relates QCString
198 
199     A safe stricmp() function.
200 
201     Compares \a str1 and \a str2 ignoring the case.
202 
203     Returns a negative value if \a str1 is less than \a str2, 0 if \a
204     str1 is equal to \a str2 or a positive value if \a str1 is greater
205     than \a str2.
206 
207     Special case I: Returns 0 if \a str1 and \a str2 are both 0.
208 
209     Special case II: Returns a random nonzero value if \a str1 is 0
210     or \a str2 is 0 (but not both).
211 
212     \sa qstrcmp(), qstrncmp(), qstrnicmp()
213 	\link #asciinotion Note on character comparisons \endlink
214 */
215 
qstricmp(const char * str1,const char * str2)216 int qstricmp( const char *str1, const char *str2 )
217 {
218     register const uchar *s1 = (const uchar *)str1;
219     register const uchar *s2 = (const uchar *)str2;
220     int res;
221     uchar c;
222     if ( !s1 || !s2 )
223 	return s1 ? 1 : ( s2 ? -1 : 0 );
224     for ( ; !(res = (c=tolower(*s1)) - tolower(*s2)); s1++, s2++ )
225 	if ( !c )				// strings are equal
226 	    break;
227     return res;
228 }
229 
230 /*!
231     \relates QCString
232 
233     A safe strnicmp() function.
234 
235     Compares at most \a len bytes of \a str1 and \a str2 ignoring the case.
236 
237     Returns a negative value if \a str1 is less than \a str2, 0 if \a str1
238     is equal to \a str2 or a positive value if \a str1 is greater than \a
239     str2.
240 
241     Special case I: Returns 0 if \a str1 and \a str2 are both 0.
242 
243     Special case II: Returns a random nonzero value if \a str1 is 0
244     or \a str2 is 0 (but not both).
245 
246     \sa qstrcmp(), qstrncmp() qstricmp()
247 	\link #asciinotion Note on character comparisons \endlink
248 */
249 
qstrnicmp(const char * str1,const char * str2,uint len)250 int qstrnicmp( const char *str1, const char *str2, uint len )
251 {
252     register const uchar *s1 = (const uchar *)str1;
253     register const uchar *s2 = (const uchar *)str2;
254     int res;
255     uchar c;
256     if ( !s1 || !s2 )
257 	return s1 ? 1 : ( s2 ? -1 : 0 );
258     for ( ; len--; s1++, s2++ ) {
259 	if ( (res = (c=tolower(*s1)) - tolower(*s2)) )
260 	    return res;
261 	if ( !c )				// strings are equal
262 	    break;
263     }
264     return 0;
265 }
266 
267 
268 static Q_UINT16 crc_tbl[16];
269 static bool   crc_tbl_init = FALSE;
270 
createCRC16Table()271 static void createCRC16Table()			// build CRC16 lookup table
272 {
273     register uint i;
274     register uint j;
275     uint v0, v1, v2, v3;
276     for ( i = 0; i < 16; i++ ) {
277 	v0 = i & 1;
278 	v1 = ( i >> 1 ) & 1;
279 	v2 = ( i >> 2 ) & 1;
280 	v3 = ( i >> 3 ) & 1;
281 	j = 0;
282 #undef SET_BIT
283 #define SET_BIT(x, b, v) (x) |= (v) << (b)
284 	SET_BIT( j,  0, v0 );
285 	SET_BIT( j,  7, v0 );
286 	SET_BIT( j, 12, v0 );
287 	SET_BIT( j,  1, v1 );
288 	SET_BIT( j,  8, v1 );
289 	SET_BIT( j, 13, v1 );
290 	SET_BIT( j,  2, v2 );
291 	SET_BIT( j,  9, v2 );
292 	SET_BIT( j, 14, v2 );
293 	SET_BIT( j,  3, v3 );
294 	SET_BIT( j, 10, v3 );
295 	SET_BIT( j, 15, v3 );
296 	crc_tbl[i] = j;
297     }
298 }
299 
300 /*!
301     \relates QMemArray
302 
303     Returns the CRC-16 checksum of \a len bytes starting at \a data.
304 
305     The checksum is independent of the byte order (endianness).
306 */
307 
qChecksum(const char * data,uint len)308 Q_UINT16 qChecksum( const char *data, uint len )
309 {
310     if ( !crc_tbl_init ) {			// create lookup table
311 
312 #ifdef QT_THREAD_SUPPORT
313 	QMutexLocker locker( qt_global_mutexpool ?
314 			     qt_global_mutexpool->get( &crc_tbl_init ) : 0 );
315 #endif // QT_THREAD_SUPPORT
316 
317 	if ( !crc_tbl_init ) {
318 	    createCRC16Table();
319 	    crc_tbl_init = TRUE;
320 	}
321     }
322     register Q_UINT16 crc = 0xffff;
323     uchar c;
324     uchar *p = (uchar *)data;
325     while ( len-- ) {
326 	c = *p++;
327 	crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)];
328 	c >>= 4;
329 	crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)];
330     }
331     return ~crc & 0xffff;
332 }
333 
334 /*!
335     \fn QByteArray qCompress( const QByteArray& data )
336 
337     \relates QByteArray
338 
339     Compresses the array \a data and returns the compressed byte
340     array using zlib.
341 
342     \sa qUncompress()
343 */
344 
345 /*!
346     \relates QByteArray
347 
348     \overload
349 
350     Compresses the array \a data which is \a nbytes long and returns the
351     compressed byte array.
352 */
353 
354 #ifndef QT_NO_COMPRESS
qCompress(const uchar * data,int nbytes)355 QByteArray qCompress( const uchar* data, int nbytes )
356 {
357     if ( nbytes == 0 ) {
358 	QByteArray tmp( 4 );
359 	tmp.fill( 0 );
360 	return tmp;
361     }
362     if ( !data ) {
363 #if defined(QT_CHECK_RANGE)
364 	qWarning( "qCompress: data is NULL." );
365 #endif
366 	return QByteArray();
367     }
368 
369     ulong len = nbytes + nbytes / 100 + 13;
370     QByteArray bazip;
371     int res;
372     do {
373 	bazip.resize( len + 4 );
374 	res = ::compress(  (uchar*)bazip.data()+4, &len, (uchar*)data, nbytes );
375 
376 	switch ( res ) {
377 	case Z_OK:
378 	    bazip.resize( len + 4 );
379 	    bazip[0] = ( nbytes & 0xff000000 ) >> 24;
380 	    bazip[1] = ( nbytes & 0x00ff0000 ) >> 16;
381 	    bazip[2] = ( nbytes & 0x0000ff00 ) >> 8;
382 	    bazip[3] = ( nbytes & 0x000000ff );
383 	    break;
384 	case Z_MEM_ERROR:
385 #if defined(QT_CHECK_RANGE)
386 	    qWarning( "qCompress: Z_MEM_ERROR: Not enough memory." );
387 #endif
388 	    bazip.resize( 0 );
389 	    break;
390 	case Z_BUF_ERROR:
391 	    len *= 2;
392 	    break;
393 	}
394     } while ( res == Z_BUF_ERROR );
395 
396     return bazip;
397 }
398 #endif
399 
400 /*!
401     \fn QByteArray qUncompress( const QByteArray& data )
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()
417 */
418 
419 /*!
420     \relates QByteArray
421 
422     \overload
423 
424     Uncompresses the array \a data which is \a nbytes long and returns
425     the uncompressed byte array.
426 */
427 
428 #ifndef QT_NO_COMPRESS
qUncompress(const uchar * data,int nbytes)429 QByteArray qUncompress( const uchar* data, int nbytes )
430 {
431     if ( !data ) {
432 #if defined(QT_CHECK_RANGE)
433 	qWarning( "qUncompress: data is NULL." );
434 #endif
435 	return QByteArray();
436     }
437     if ( nbytes <= 4 ) {
438 #if defined(QT_CHECK_RANGE)
439 	if ( nbytes < 4 || ( data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0 ) )
440 	    qWarning( "qUncompress: Input data is corrupted." );
441 #endif
442 	return QByteArray();
443     }
444     ulong expectedSize = ( data[0] << 24 ) | ( data[1] << 16 ) | ( data[2] << 8 ) | data[3];
445     ulong len = QMAX( expectedSize,  1 );
446     QByteArray baunzip;
447     int res;
448     do {
449         if ( baunzip.resize( len ) ) {
450 	    res = ::uncompress( (uchar*)baunzip.data(), &len,
451 				    (uchar*)data+4, nbytes-4 );
452         } else {
453             res = Z_MEM_ERROR;
454         }
455 
456 	switch ( res ) {
457 	case Z_OK:
458 	    if ( len != baunzip.size() )
459 		baunzip.resize( len );
460 	    break;
461 	case Z_MEM_ERROR:
462 #if defined(QT_CHECK_RANGE)
463 	    qWarning( "qUncompress: Z_MEM_ERROR: Not enough memory." );
464 #endif
465 	    break;
466 	case Z_BUF_ERROR:
467 	    len *= 2;
468 	    break;
469 	case Z_DATA_ERROR:
470 #if defined(QT_CHECK_RANGE)
471 	    qWarning( "qUncompress: Z_DATA_ERROR: Input data is corrupted." );
472 #endif
473 	    break;
474 	}
475     } while ( res == Z_BUF_ERROR );
476 
477     if ( res != Z_OK )
478 	baunzip = QByteArray();
479 
480     return baunzip;
481 }
482 #endif
483 
484 /*****************************************************************************
485   QByteArray documentation
486  *****************************************************************************/
487 
488 /*!
489     \class QByteArray
490     \reentrant
491     \brief The QByteArray class provides an array of bytes.
492 
493     \ingroup collection
494     \ingroup tools
495 
496     The QByteArray class provides an explicitly shared array of bytes.
497     It is useful for manipulating memory areas with custom data.
498     QByteArray is implemented as a QMemArray\<char\>. See the \l
499     QMemArray documentation for further information.
500 */
501 
502 /*!
503     \fn QByteArray::QByteArray()
504 
505     Constructs an empty QByteArray.
506 */
507 
508 /*!
509     \fn QByteArray::QByteArray( int size )
510 
511     Constructs a QByteArray of size \a size.
512 */
513 
514 /*****************************************************************************
515   QByteArray stream functions
516  *****************************************************************************/
517 
518 /*!
519     \relates QMemArray
520 
521     Writes byte array \a a to the stream \a s and returns a reference
522     to the stream.
523 
524     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
525 */
526 #ifndef QT_NO_DATASTREAM
527 
operator <<(QDataStream & s,const QByteArray & a)528 QDataStream &operator<<( QDataStream &s, const QByteArray &a )
529 {
530     return s.writeBytes( a.data(), a.size() );
531 }
532 
533 /*!
534     \relates QMemArray
535 
536     Reads a byte array into \a a from the stream \a s and returns a
537     reference to the stream.
538 
539     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
540 */
541 
operator >>(QDataStream & s,QByteArray & a)542 QDataStream &operator>>( QDataStream &s, QByteArray &a )
543 {
544     Q_UINT32 len;
545     s >> len;					// read size of array
546     if ( len == 0 || s.eof() ) {		// end of file reached
547 	a.resize( 0 );
548 	return s;
549     }
550     if ( !a.resize( (uint)len ) ) {		// resize array
551 #if defined(QT_CHECK_NULL)
552 	qWarning( "QDataStream: Not enough memory to read QByteArray" );
553 #endif
554 	len = 0;
555     }
556     if ( len > 0 )				// not null array
557 	s.readRawBytes( a.data(), (uint)len );
558     return s;
559 }
560 
561 #endif //QT_NO_DATASTREAM
562 
563 /*****************************************************************************
564   QCString member functions
565  *****************************************************************************/
566 
567 /*!
568     \class QCString qcstring.h
569     \reentrant
570     \brief The QCString class provides an abstraction of the classic C
571     zero-terminated char array (char *).
572 
573     \ingroup text
574     \ingroup collection
575     \ingroup tools
576     \ingroup shared
577 
578     QCString inherits QByteArray, which is defined as
579     QMemArray\<char\>. Since QCString is a QMemArray, it uses \link
580     shclass.html explicit sharing\endlink with a reference count.
581 
582     QCString tries to behave like a more convenient \c{const char *}.
583     The price of doing this is that some algorithms will perform
584     badly. For example, append() is O(length()) since it scans for a
585     null terminator. Although you might use QCString for text that is
586     never exposed to the user, for most purposes, and especially for
587     user-visible text, you should use QString. QString provides
588     implicit sharing, Unicode and other internationalization support,
589     and is well optimized.
590 
591     Note that for the QCString methods that take a \c{const char *}
592     parameter the \c{const char *} must either be 0 (null) or not-null
593     and '\0' (NUL byte) terminated; otherwise the results are
594     undefined.
595 
596     A QCString that has not been assigned to anything is \e null, i.e.
597     both the length and the data pointer is 0. A QCString that
598     references the empty string ("", a single '\0' char) is \e empty.
599     Both null and empty QCStrings are legal parameters to the methods.
600     Assigning \c{const char *} 0 to QCString produces a null QCString.
601 
602     The length() function returns the length of the string; resize()
603     resizes the string and truncate() truncates the string. A string
604     can be filled with a character using fill(). Strings can be left
605     or right padded with characters using leftJustify() and
606     rightJustify(). Characters, strings and regular expressions can be
607     searched for using find() and findRev(), and counted using
608     contains().
609 
610     Strings and characters can be inserted with insert() and appended
611     with append(). A string can be prepended with prepend().
612     Characters can be removed from the string with remove() and
613     replaced with replace().
614 
615     Portions of a string can be extracted using left(), right() and
616     mid(). Whitespace can be removed using stripWhiteSpace() and
617     simplifyWhiteSpace(). Strings can be converted to uppercase or
618     lowercase with upper() and lower() respectively.
619 
620     Strings that contain numbers can be converted to numbers with
621     toShort(), toInt(), toLong(), toULong(), toFloat() and toDouble().
622     Numbers can be converted to strings with setNum().
623 
624     Many operators are overloaded to work with QCStrings. QCString
625     also supports some more obscure functions, e.g. sprintf(),
626     setStr() and setExpand().
627 
628     \target asciinotion
629     \sidebar Note on Character Comparisons
630 
631     In QCString the notion of uppercase and lowercase and of which
632     character is greater than or less than another character is locale
633     dependent. This affects functions which support a case insensitive
634     option or which compare or lowercase or uppercase their arguments.
635     Case insensitive operations and comparisons will be accurate if
636     both strings contain only ASCII characters. (If \c $LC_CTYPE is
637     set, most Unix systems do "the right thing".) Functions that this
638     affects include contains(), find(), findRev(), \l operator<(), \l
639     operator<=(), \l operator>(), \l operator>=(), lower() and
640     upper().
641 
642     This issue does not apply to \l{QString}s since they represent
643     characters using Unicode.
644     \endsidebar
645 
646     Performance note: The QCString methods for QRegExp searching are
647     implemented by converting the QCString to a QString and performing
648     the search on that. This implies a deep copy of the QCString data.
649     If you are going to perform many QRegExp searches on a large
650     QCString, you will get better performance by converting the
651     QCString to a QString yourself, and then searching in the QString.
652 */
653 
654 /*!
655     \fn QCString::QCString()
656 
657     Constructs a null string.
658 
659     \sa isNull()
660 */
661 
662 /*!
663     \fn QCString::QCString( const QCString &s )
664 
665     Constructs a shallow copy \a s.
666 
667     \sa assign()
668 */
669 
670 /*!
671     Constructs a string with room for \a size characters, including
672     the '\0'-terminator. Makes a null string if \a size == 0.
673 
674     If \a size \> 0, then the first and last characters in the string
675     are initialized to '\0'. All other characters are uninitialized.
676 
677     \sa resize(), isNull()
678 */
679 
QCString(int size)680 QCString::QCString( int size )
681     : QByteArray( size )
682 {
683     if ( size > 0 ) {
684 	*data() = '\0';				// set terminator
685 	*(data()+(size-1)) = '\0';
686     }
687 }
688 
689 /*!
690     Constructs a string that is a deep copy of \a str.
691 
692     If \a str is 0 a null string is created.
693 
694     \sa isNull()
695 */
696 
QCString(const char * str)697 QCString::QCString( const char *str )
698 {
699     duplicate( str, qstrlen(str) + 1 );
700 }
701 
702 
703 /*!
704     Constructs a string that is a deep copy of \a str. The copy will
705     be at most \a maxsize bytes long including the '\0'-terminator.
706 
707     Example:
708     \code
709     QCString str( "helloworld", 6 ); // assigns "hello" to str
710     \endcode
711 
712     If \a str contains a 0 byte within the first \a maxsize bytes, the
713     resulting QCString will be terminated by this 0. If \a str is 0 a
714     null string is created.
715 
716     \sa isNull()
717 */
718 
QCString(const char * str,uint maxsize)719 QCString::QCString( const char *str, uint maxsize )
720 {
721     if ( str == 0 )
722 	return;
723     uint len; // index of first '\0'
724     for ( len = 0; len < maxsize - 1; len++ ) {
725 	if ( str[len] == '\0' )
726 	    break;
727     }
728     QByteArray::resize( len + 1 );
729     memcpy( data(), str, len );
730     data()[len] = 0;
731 }
732 
733 /*!
734   \reimp
735 */
736 
~QCString()737 QCString::~QCString()
738 {
739 }
740 
741 /*!
742     \fn QCString &QCString::operator=( const QCString &s )
743 
744     Assigns a shallow copy of \a s to this string and returns a
745     reference to this string.
746 */
747 
748 /*!
749     \overload QCString &QCString::operator=( const char *str )
750 
751     Assigns a deep copy of \a str to this string and returns a
752     reference to this string.
753 
754     If \a str is 0 a null string is created.
755 
756     \sa isNull()
757 */
758 
759 /*!
760     \fn bool QCString::isNull() const
761 
762     Returns TRUE if the string is null, i.e. if data() == 0; otherwise
763     returns FALSE. A null string is also an empty string.
764 
765     Example:
766     \code
767     QCString a;		// a.data() == 0,  a.size() == 0, a.length() == 0
768     QCString b == "";	// b.data() == "", b.size() == 1, b.length() == 0
769     a.isNull();		// TRUE  because a.data() == 0
770     a.isEmpty();	// TRUE  because a.length() == 0
771     b.isNull();		// FALSE because b.data() == ""
772     b.isEmpty();	// TRUE  because b.length() == 0
773     \endcode
774 
775     \sa isEmpty(), length(), size()
776 */
777 
778 /*!
779     \fn bool QCString::isEmpty() const
780 
781     Returns TRUE if the string is empty, i.e. if length() == 0;
782     otherwise returns FALSE. An empty string is not always a null
783     string.
784 
785     See example in isNull().
786 
787     \sa isNull(), length(), size()
788 */
789 
790 /*!
791     \fn uint QCString::length() const
792 
793     Returns the length of the string, excluding the '\0'-terminator.
794     Equivalent to calling \c strlen(data()).
795 
796     Null strings and empty strings have zero length.
797 
798     \sa size(), isNull(), isEmpty()
799 */
800 
801 /*!
802     \fn bool QCString::truncate( uint pos )
803 
804     Truncates the string at position \a pos.
805 
806     Equivalent to calling \c resize(pos+1).
807 
808     Example:
809     \code
810     QCString s = "truncate this string";
811     s.truncate( 5 );                      // s == "trunc"
812     \endcode
813 
814     \sa resize()
815 */
816 
817 /*!
818     Extends or shrinks the string to \a len bytes, including the
819     '\0'-terminator.
820 
821     A '\0'-terminator is set at position \c{len - 1} unless
822     \c{len == 0}.
823 
824     Example:
825     \code
826     QCString s = "resize this string";
827     s.resize( 7 );                      // s == "resize"
828     \endcode
829 
830     \sa truncate()
831 */
832 
resize(uint len)833 bool QCString::resize( uint len )
834 {
835     detach();
836     uint wasNull = isNull();
837     if ( !QByteArray::resize(len) )
838 	return FALSE;
839     if ( len )
840 	data()[len - 1] = '\0';
841     if ( len > 0 && wasNull )
842 	data()[0] = '\0';
843     return TRUE;
844 }
845 
846 
847 /*!
848     Implemented as a call to the native vsprintf() (see the manual for
849     your C library).
850 
851     If the string is shorter than 256 characters, this sprintf() calls
852     resize(256) to decrease the chance of memory corruption. The
853     string is resized back to its actual length before sprintf()
854     returns.
855 
856     Example:
857     \code
858     QCString s;
859     s.sprintf( "%d - %s", 1, "first" );		// result < 256 chars
860 
861     QCString big( 25000 );			// very long string
862     big.sprintf( "%d - %s", 2, longString );	// result < 25000 chars
863     \endcode
864 
865     \warning All vsprintf() implementations will write past the end of
866     the target string (*this) if the \a format specification and
867     arguments happen to be longer than the target string, and some
868     will also fail if the target string is longer than some arbitrary
869     implementation limit.
870 
871     Giving user-supplied arguments to sprintf() is risky: Sooner or
872     later someone will paste a huge line into your application.
873 */
874 
sprintf(const char * format,...)875 QCString &QCString::sprintf( const char *format, ... )
876 {
877     detach();
878     va_list ap;
879     va_start( ap, format );
880     if ( size() < 256 )
881 	QByteArray::resize( 256 );		// make string big enough
882 #ifdef QT_VSNPRINTF
883     QT_VSNPRINTF( data(), size(), format, ap );
884 #else
885     vsprintf( data(), format, ap );
886 #endif
887     resize( qstrlen(data()) + 1 );		// truncate
888     va_end( ap );
889     return *this;
890 }
891 
892 
893 /*!
894     Fills the string with \a len bytes of character \a c, followed by
895     a '\0'-terminator.
896 
897     If \a len is negative, then the current string length is used.
898 
899     Returns FALSE is \a len is nonnegative and there is not enough
900     memory to resize the string; otherwise returns TRUE.
901 */
902 
fill(char c,int len)903 bool QCString::fill( char c, int len )
904 {
905     detach();
906     if ( len < 0 )
907 	len = length();
908     if ( !QByteArray::fill(c,len+1) )
909 	return FALSE;
910     *(data()+len) = '\0';
911     return TRUE;
912 }
913 
914 
915 /*!
916     \fn QCString QCString::copy() const
917 
918     Returns a deep copy of this string.
919 
920     \sa detach()
921 */
922 
923 
924 /*!
925     Finds the first occurrence of the character \a c, starting at
926     position \a index.
927 
928     The search is case sensitive if \a cs is TRUE, or case insensitive
929     if \a cs is FALSE.
930 
931     Returns the position of \a c, or -1 if \a c could not be found.
932 
933     \sa \link #asciinotion Note on character comparisons \endlink
934 */
935 
find(char c,int index,bool cs) const936 int QCString::find( char c, int index, bool cs ) const
937 {
938     if ( (uint)index >= size() )		// index outside string
939 	return -1;
940     register const char *d;
941     if ( cs ) {					// case sensitive
942 	d = strchr( data()+index, c );
943     } else {
944 	d = data()+index;
945 	c = tolower( (uchar) c );
946 	while ( *d && tolower((uchar) *d) != c )
947 	    d++;
948 	if ( !*d && c )				// not found
949 	    d = 0;
950     }
951     return d ? (int)(d - data()) : -1;
952 }
953 
954 #define REHASH( a ) \
955     if ( sl_minus_1 < sizeof(uint) * CHAR_BIT ) \
956 	hashHaystack -= (a) << sl_minus_1; \
957     hashHaystack <<= 1
958 
959 /*!
960     \overload
961 
962     Finds the first occurrence of the string \a str, starting at
963     position \a index.
964 
965     The search is case sensitive if \a cs is TRUE, or case insensitive
966     if \a cs is FALSE.
967 
968     Returns the position of \a str, or -1 if \a str could not be
969     found.
970 
971     \sa \link #asciinotion Note on character comparisons \endlink
972 */
973 
find(const char * str,int index,bool cs) const974 int QCString::find( const char *str, int index, bool cs ) const
975 {
976     return find( str, index, cs, length() );
977 }
978 
find(const char * str,int index,bool cs,uint l) const979 int QCString::find( const char *str, int index, bool cs, uint l ) const
980 {
981     if ( (uint)index >= size() )
982 	return -1;
983     if ( !str )
984 	return -1;
985     if ( !*str )
986 	return index;
987     const uint sl = qstrlen( str );
988     if ( sl + index > l )
989 	return -1;
990 
991     if ( sl == 1 )
992 	return find( *str, index, cs );
993 
994     /*
995       See QString::find() for details.
996     */
997     const char* needle = str;
998     const char* haystack = data() + index;
999     const char* end = data() + (l-sl);
1000     const uint sl_minus_1 = sl-1;
1001     uint hashNeedle = 0, hashHaystack = 0,i;
1002 
1003     if ( cs ) {
1004 	for ( i = 0; i < sl; ++i ) {
1005 	    hashNeedle = ((hashNeedle<<1) + needle[i] );
1006 	    hashHaystack = ((hashHaystack<<1) + haystack[i] );
1007 	}
1008 	hashHaystack -= *(haystack+sl_minus_1);
1009 
1010 	while ( haystack <= end ) {
1011 	    hashHaystack += *(haystack+sl_minus_1);
1012  	    if ( hashHaystack == hashNeedle  && *needle == *haystack
1013 		 && qstrncmp( needle, haystack, sl ) == 0 )
1014 		return haystack - data();
1015 
1016 	    REHASH( *haystack );
1017 	    ++haystack;
1018 	}
1019     } else {
1020 	for ( i = 0; i < sl; ++i ) {
1021 	    hashNeedle = ((hashNeedle<<1) +
1022 			  tolower( needle[i] ) );
1023 	    hashHaystack = ((hashHaystack<<1) +
1024 			    tolower( haystack[i] ) );
1025 	}
1026 	hashHaystack -= tolower(*(haystack+sl_minus_1));
1027 
1028 	while ( haystack <= end ) {
1029 	    hashHaystack += tolower(*(haystack+sl_minus_1));
1030 	    if ( hashHaystack == hashNeedle
1031 		 && qstrnicmp( needle, haystack, sl ) == 0 )
1032 		return haystack - data();
1033 
1034 	    REHASH( tolower(*haystack) );
1035 	    ++haystack;
1036 	}
1037     }
1038     return -1;
1039 }
1040 
1041 
1042 /*!
1043     Finds the first occurrence of the character \a c, starting at
1044     position \a index and searching backwards.
1045 
1046     The search is case sensitive if \a cs is TRUE, or case insensitive
1047     if \a cs is FALSE.
1048 
1049     Returns the position of \a c, or -1 if \a c could not be found.
1050 
1051     \sa \link #asciinotion Note on character comparisons \endlink
1052 */
1053 
findRev(char c,int index,bool cs) const1054 int QCString::findRev( char c, int index, bool cs ) const
1055 {
1056     register const char *b = data();
1057     register const char *d;
1058     if ( index < 0 )
1059 	index = length();
1060     if ( (uint)index >= size() )
1061 	return -1;
1062     d = b + index;
1063     if ( cs ) {
1064 	while ( d >= b && *d != c )
1065 	    d--;
1066     } else {
1067 	c = tolower( (uchar) c );
1068 	while ( d >= b && tolower((uchar) *d) != c )
1069 	    d--;
1070     }
1071     return d >= b ? (int)(d - b) : -1;
1072 }
1073 
1074 /*!
1075     \overload
1076 
1077     Finds the first occurrence of the string \a str, starting at
1078     position \a index and searching backwards.
1079 
1080     The search is case sensitive if \a cs is TRUE, or case insensitive
1081     if \a cs is FALSE.
1082 
1083     Returns the position of \a str, or -1 if \a str could not be
1084     found.
1085 
1086     \sa \link #asciinotion Note on character comparisons \endlink
1087 */
1088 
findRev(const char * str,int index,bool cs) const1089 int QCString::findRev( const char *str, int index, bool cs ) const
1090 {
1091     /*
1092       See QString::find() for explanations.
1093     */
1094     const uint sl = qstrlen( str );
1095     const uint l = length();
1096     int delta = l-sl;
1097     if ( index < 0 )
1098 	index = delta;
1099     if ( index < 0 || index > (int)l )
1100 	return -1;
1101     if ( index > delta )
1102 	index = delta;
1103 
1104     if ( sl == 1 )
1105 	return findRev( *str, index, cs );
1106 
1107     const char* needle = str;
1108     const char* haystack = data() + index;
1109     const char* end = data();
1110     const uint sl_minus_1 = sl-1;
1111     const char* n = needle+sl_minus_1;
1112     const char* h = haystack+sl_minus_1;
1113     uint hashNeedle = 0, hashHaystack = 0, i;
1114 
1115     if ( cs ) {
1116 	for ( i = 0; i < sl; ++i ) {
1117 	    hashNeedle = ((hashNeedle<<1) + *(n-i) );
1118 	    hashHaystack = ((hashHaystack<<1) + *(h-i) );
1119 	}
1120 	hashHaystack -= *haystack;
1121 	while ( haystack >= end ) {
1122 	    hashHaystack += *haystack;
1123  	    if ( hashHaystack == hashNeedle  && qstrncmp( needle, haystack, sl ) == 0 )
1124 		return haystack-data();
1125 	    --haystack;
1126 	    REHASH( *(haystack+sl) );
1127 	}
1128     } else {
1129 	for ( i = 0; i < sl; ++i ) {
1130 	    hashNeedle = ((hashNeedle<<1) + tolower( *(n-i) ) );
1131 	    hashHaystack = ((hashHaystack<<1) + tolower( *(h-i) ) );
1132 	}
1133 	hashHaystack -= tolower(*haystack);
1134 	while ( haystack >= end ) {
1135 	    hashHaystack += tolower(*haystack);
1136 	    if ( hashHaystack == hashNeedle && qstrnicmp( needle, haystack, sl ) == 0 )
1137 		return haystack-data();
1138 	    --haystack;
1139 	    REHASH( tolower(*(haystack+sl)) );
1140 	}
1141     }
1142     return -1;
1143 }
1144 
1145 
1146 /*!
1147     Returns the number of times the character \a c occurs in the
1148     string.
1149 
1150     The match is case sensitive if \a cs is TRUE, or case insensitive
1151     if \a cs if FALSE.
1152 
1153     \sa \link #asciinotion Note on character comparisons \endlink
1154 */
1155 
contains(char c,bool cs) const1156 int QCString::contains( char c, bool cs ) const
1157 {
1158     int count = 0;
1159     char *d = data();
1160     if ( !d )
1161 	return 0;
1162     if ( cs ) {					// case sensitive
1163 	while ( *d )
1164 	    if ( *d++ == c )
1165 		count++;
1166     } else {					// case insensitive
1167 	c = tolower( (uchar) c );
1168 	while ( *d ) {
1169 	    if ( tolower((uchar) *d) == c )
1170 		count++;
1171 	    d++;
1172 	}
1173     }
1174     return count;
1175 }
1176 
1177 /*!
1178     \overload
1179 
1180     Returns the number of times \a str occurs in the string.
1181 
1182     The match is case sensitive if \a cs is TRUE, or case insensitive
1183     if \a cs if FALSE.
1184 
1185     This function counts overlapping substrings, for example, "banana"
1186     contains two occurrences of "ana".
1187 
1188     \sa findRev()
1189 	\link #asciinotion Note on character comparisons \endlink
1190 */
1191 
contains(const char * str,bool cs) const1192 int QCString::contains( const char *str, bool cs ) const
1193 {
1194     int count = 0;
1195     int i = -1;
1196     uint l = length();
1197     // use find for the faster hashing algorithm
1198     while ( ( i = find ( str, i+1, cs, l ) ) != -1 )
1199 	count++;
1200     return count;
1201 }
1202 
1203 /*!
1204     Returns a substring that contains the \a len leftmost characters
1205     of the string.
1206 
1207     The whole string is returned if \a len exceeds the length of the
1208     string.
1209 
1210     Example:
1211     \code
1212     QCString s = "Pineapple";
1213     QCString t = s.left( 4 );  // t == "Pine"
1214     \endcode
1215 
1216     \sa right(), mid()
1217 */
left(uint len) const1218 QCString QCString::left( uint len ) const
1219 {
1220     if ( isEmpty() ) {
1221 	QCString empty;
1222 	return empty;
1223     } else if ( len >= size() ) {
1224 	QCString same( data() );
1225 	return same;
1226     } else {
1227 	QCString s( len+1 );
1228 	strncpy( s.data(), data(), len );
1229 	*(s.data()+len) = '\0';
1230 	return s;
1231     }
1232 }
1233 
1234 /*!
1235     Returns a substring that contains the \a len rightmost characters
1236     of the string.
1237 
1238     The whole string is returned if \a len exceeds the length of the
1239     string.
1240 
1241     Example:
1242     \code
1243     QCString s = "Pineapple";
1244     QCString t = s.right( 5 );  // t == "apple"
1245     \endcode
1246 
1247     \sa left(), mid()
1248 */
1249 
right(uint len) const1250 QCString QCString::right( uint len ) const
1251 {
1252     if ( isEmpty() ) {
1253 	QCString empty;
1254 	return empty;
1255     } else {
1256 	uint l = length();
1257 	if ( len > l )
1258 	    len = l;
1259 	char *p = data() + (l - len);
1260 	return QCString( p );
1261     }
1262 }
1263 
1264 /*!
1265     Returns a substring that contains at most \a len characters from
1266     this string, starting at position \a index.
1267 
1268     Returns a null string if the string is empty or if \a index is out
1269     of range. Returns the whole string from \a index if \a index+len
1270     exceeds the length of the string.
1271 
1272     Example:
1273     \code
1274     QCString s = "Two pineapples";
1275     QCString t = s.mid( 4, 3 );     // t == "pin"
1276     \endcode
1277 
1278     \sa left(), right()
1279 */
1280 
mid(uint index,uint len) const1281 QCString QCString::mid( uint index, uint len ) const
1282 {
1283     uint slen = qstrlen( data() );
1284     if ( isEmpty() || index >= slen ) {
1285 	QCString empty;
1286 	return empty;
1287     } else {
1288 	if ( len > slen-index )
1289 	    len = slen - index;
1290 	register char *p = data()+index;
1291 	QCString s( len+1 );
1292 	strncpy( s.data(), p, len );
1293 	*(s.data()+len) = '\0';
1294 	return s;
1295     }
1296 }
1297 
1298 /*!
1299     Returns a string of length \a width (plus one for the terminating
1300     '\0') that contains this string padded with the \a fill character.
1301 
1302     If the length of the string exceeds \a width and \a truncate is
1303     FALSE (the default), then the returned string is a copy of the
1304     string. If the length of the string exceeds \a width and \a
1305     truncate is TRUE, then the returned string is a left(\a width).
1306 
1307     Example:
1308     \code
1309     QCString s("apple");
1310     QCString t = s.leftJustify(8, '.');  // t == "apple..."
1311     \endcode
1312 
1313     \sa rightJustify()
1314 */
1315 
leftJustify(uint width,char fill,bool truncate) const1316 QCString QCString::leftJustify( uint width, char fill, bool truncate ) const
1317 {
1318     QCString result;
1319     int len = qstrlen(data());
1320     int padlen = width - len;
1321     if ( padlen > 0 ) {
1322 	result.QByteArray::resize( len+padlen+1 );
1323 	memcpy( result.data(), data(), len );
1324 	memset( result.data()+len, fill, padlen );
1325 	result[len+padlen] = '\0';
1326     } else {
1327 	if ( truncate )
1328 	    result = left( width );
1329 	else
1330 	    result = copy();
1331     }
1332     return result;
1333 }
1334 
1335 /*!
1336     Returns a string of length \a width (plus one for the terminating
1337     '\0') that contains zero or more of the \a fill character followed
1338     by this string.
1339 
1340     If the length of the string exceeds \a width and \a truncate is
1341     FALSE (the default), then the returned string is a copy of the
1342     string. If the length of the string exceeds \a width and \a
1343     truncate is TRUE, then the returned string is a left(\a width).
1344 
1345     Example:
1346     \code
1347     QCString s("pie");
1348     QCString t = s.rightJustify(8, '.');  // t == ".....pie"
1349     \endcode
1350 
1351     \sa leftJustify()
1352 */
1353 
rightJustify(uint width,char fill,bool truncate) const1354 QCString QCString::rightJustify( uint width, char fill, bool truncate ) const
1355 {
1356     QCString result;
1357     int len = qstrlen(data());
1358     int padlen = width - len;
1359     if ( padlen > 0 ) {
1360 	result.QByteArray::resize( len+padlen+1 );
1361 	memset( result.data(), fill, padlen );
1362 	memcpy( result.data()+padlen, data(), len );
1363 	result[len+padlen] = '\0';
1364     } else {
1365 	if ( truncate )
1366 	    result = left( width );
1367 	else
1368 	    result = copy();
1369     }
1370     return result;
1371 }
1372 
1373 /*!
1374     Returns a new string that is a copy of this string converted to lower
1375     case.
1376 
1377     Example:
1378     \code
1379     QCString s("Credit");
1380     QCString t = s.lower();  // t == "credit"
1381     \endcode
1382 
1383     \sa upper()
1384       \link #asciinotion Note on character comparisons \endlink
1385 */
1386 
lower() const1387 QCString QCString::lower() const
1388 {
1389     QCString s( data() );
1390     register char *p = s.data();
1391     if ( p ) {
1392 	while ( *p ) {
1393 	    *p = tolower( (uchar) *p );
1394 	    p++;
1395 	}
1396     }
1397     return s;
1398 }
1399 
1400 /*!
1401     Returns a new string that is a copy of this string converted to upper case.
1402 
1403     Example:
1404     \code
1405     QCString s( "Debit" );
1406     QCString t = s.upper();  // t == "DEBIT"
1407     \endcode
1408 
1409     \sa lower()
1410       \link #asciinotion Note on character comparisons \endlink
1411 */
1412 
upper() const1413 QCString QCString::upper() const
1414 {
1415     QCString s( data() );
1416     register char *p = s.data();
1417     if ( p ) {
1418 	while ( *p ) {
1419 	    *p = toupper(*p);
1420 	    p++;
1421 	}
1422     }
1423     return s;
1424 }
1425 
1426 
1427 /*!
1428     Returns a new string that has white space removed from the start
1429     and the end.
1430 
1431     White space means the decimal ASCII codes 9, 10, 11, 12, 13 and
1432     32.
1433 
1434     Example:
1435     \code
1436     QCString s = " space ";
1437     QCString t = s.stripWhiteSpace();		// t == "space"
1438     \endcode
1439 
1440     \sa simplifyWhiteSpace()
1441 */
1442 
stripWhiteSpace() const1443 QCString QCString::stripWhiteSpace() const
1444 {
1445     if ( isEmpty() )				// nothing to do
1446 	return copy();
1447 
1448     register char *s = data();
1449     QCString result = s;
1450     int reslen = result.length();
1451     if ( !isspace((uchar) s[0]) && !isspace((uchar) s[reslen-1]) )
1452 	return result;				// returns a copy
1453 
1454     s = result.data();
1455     int start = 0;
1456     int end = reslen - 1;
1457     while ( isspace((uchar) s[start]) )		// skip white space from start
1458 	start++;
1459     if ( s[start] == '\0' ) {			// only white space
1460 	result.resize( 1 );
1461 	return result;
1462     }
1463     while ( end && isspace((uchar) s[end]) )	// skip white space from end
1464 	end--;
1465     end -= start - 1;
1466     memmove( result.data(), &s[start], end );
1467     result.resize( end + 1 );
1468     return result;
1469 }
1470 
1471 
1472 /*!
1473     Returns a new string that has white space removed from the start
1474     and the end, plus any sequence of internal white space replaced
1475     with a single space (ASCII 32).
1476 
1477     White space means the decimal ASCII codes 9, 10, 11, 12, 13 and
1478     32.
1479 
1480     \code
1481     QCString s = "  lots\t of\nwhite    space ";
1482     QCString t = s.simplifyWhiteSpace(); // t == "lots of white space"
1483     \endcode
1484 
1485     \sa stripWhiteSpace()
1486 */
1487 
simplifyWhiteSpace() const1488 QCString QCString::simplifyWhiteSpace() const
1489 {
1490     if ( isEmpty() )				// nothing to do
1491 	return copy();
1492     QCString result( size() );
1493     char *from	= data();
1494     char *to	= result.data();
1495     char *first = to;
1496     for ( ;; ) {
1497 	while ( isspace((uchar) *from) )
1498 	    from++;
1499 	while ( *from && !isspace((uchar) *from) )
1500 	    *to++ = *from++;
1501 	if ( *from )
1502 	    *to++ = 0x20;			// ' '
1503 	else
1504 	    break;
1505     }
1506     if ( to > first && *(to-1) == 0x20 )
1507 	to--;
1508     *to = '\0';
1509     result.resize( (int)(to - result.data()) + 1 );
1510     return result;
1511 }
1512 
1513 
1514 /*!
1515     \overload
1516 
1517     Inserts string \a s into the string at position \a index.
1518 
1519     If \a index is beyond the end of the string, the string is
1520     padded with spaces (ASCII 32) to length \a index and then \a s
1521     is appended.
1522 
1523     \code
1524     QCString s = "I like fish";
1525     s.insert( 2, "don't ");     // s == "I don't like fish"
1526 
1527     s = "x";                    // index 01234
1528     s.insert( 3, "yz" );        // s == "x  yz"
1529     \endcode
1530 */
1531 
insert(uint index,const char * s)1532 QCString &QCString::insert( uint index, const char *s )
1533 {
1534     int len = qstrlen(s);
1535     if ( len == 0 )
1536 	return *this;
1537     uint olen = length();
1538     int nlen = olen + len;
1539     if ( index >= olen ) {			// insert after end of string
1540 	detach();
1541 	if ( QByteArray::resize(nlen+index-olen+1, QByteArray::SpeedOptim ) ) {
1542 	    memset( data()+olen, ' ', index-olen );
1543 	    memcpy( data()+index, s, len+1 );
1544 	}
1545     } else {
1546 	detach();
1547 	if ( QByteArray::resize(nlen+1, QByteArray::SpeedOptim ) ) {	// normal insert
1548 	    memmove( data()+index+len, data()+index, olen-index+1 );
1549 	    memcpy( data()+index, s, len );
1550 	}
1551     }
1552     return *this;
1553 }
1554 
1555 /*!
1556     Inserts character \a c into the string at position \a index and
1557     returns a reference to the string.
1558 
1559     If \a index is beyond the end of the string, the string is
1560     padded with spaces (ASCII 32) to length \a index and then \a c
1561     is appended.
1562 
1563     Example:
1564     \code
1565     QCString s = "Yes";
1566     s.insert( 3, '!');   // s == "Yes!"
1567     \endcode
1568 
1569     \sa remove(), replace()
1570 */
1571 
insert(uint index,char c)1572 QCString &QCString::insert( uint index, char c )	// insert char
1573 {
1574     char buf[2];
1575     buf[0] = c;
1576     buf[1] = '\0';
1577     return insert( index, buf );
1578 }
1579 
1580 /*!
1581     \fn QCString &QCString::prepend( const char *s )
1582 
1583     Prepend \a s to the string. Equivalent to insert(0, s).
1584 
1585     \sa insert()
1586 */
1587 
1588 /*!
1589     Removes \a len characters from the string, starting at position \a
1590     index, and returns a reference to the string.
1591 
1592     If \a index is out of range, nothing happens. If \a index is
1593     valid, but \a index + \a len is larger than the length of the
1594     string, the string is truncated at position \a index.
1595 
1596     \code
1597     QCString s = "Montreal";
1598     s.remove( 1, 4 );         // s == "Meal"
1599     \endcode
1600 
1601     \sa insert(), replace()
1602 */
1603 
remove(uint index,uint len)1604 QCString &QCString::remove( uint index, uint len )
1605 {
1606     uint olen = length();
1607     if ( index + len >= olen ) {		// range problems
1608 	if ( index < olen ) {			// index ok
1609 	    detach();
1610 	    resize( index+1 );
1611 	}
1612     } else if ( len != 0 ) {
1613 	detach();
1614 	memmove( data()+index, data()+index+len, olen-index-len+1 );
1615 	QByteArray::resize(olen-len+1, QByteArray::SpeedOptim );
1616     }
1617     return *this;
1618 }
1619 
1620 /*!
1621     Replaces \a len characters from the string, starting at position
1622     \a index, with \a str, and returns a reference to the string.
1623 
1624     If \a index is out of range, nothing is removed and \a str is
1625     appended at the end of the string. If \a index is valid, but \a
1626     index + \a len is larger than the length of the string, \a str
1627     replaces the rest of the string from position \a index.
1628 
1629     \code
1630     QCString s = "Say yes!";
1631     s.replace( 4, 3, "NO" );  // s == "Say NO!"
1632     \endcode
1633 
1634     \sa insert(), remove()
1635 */
1636 
replace(uint index,uint len,const char * str)1637 QCString &QCString::replace( uint index, uint len, const char *str )
1638 {
1639     remove( index, len );
1640     insert( index, str );
1641     return *this;
1642 }
1643 
1644 
1645 /*! \overload
1646 
1647     Replaces every occurrence of the character \a c in the string
1648     with \a after. Returns a reference to the string.
1649 
1650     Example:
1651     \code
1652     QCString s = "a,b,c";
1653     s.replace( ',', " or " );
1654     // s == "a or b or c"
1655     \endcode
1656 */
replace(char c,const char * after)1657 QCString &QCString::replace( char c, const char *after )
1658 {
1659     char str[2];
1660     str[0] = c;
1661     str[1] = '\0';
1662     return replace( str, after );
1663 }
1664 
1665 /*! \overload
1666 
1667     Replaces every occurrence of the string \a before in the string
1668     with the string \a after. Returns a reference to the string.
1669 
1670     Example:
1671     \code
1672     QCString s = "Greek is Greek";
1673     s.replace( "Greek", "English" );
1674     // s == "English is English"
1675     \endcode
1676 */
1677 
replace(const char * before,const char * after)1678 QCString &QCString::replace( const char *before, const char *after )
1679 {
1680     if ( before == after || isNull() )
1681 	return *this;
1682 
1683     detach();
1684 
1685     int index = 0;
1686     const int bl = before ? int(strlen( before )) : 0;
1687     const int al = after ? int(strlen( after )) : 0;
1688     char *d = data();
1689     uint len = length();
1690 
1691     if ( bl == al ) {
1692 	if ( bl ) {
1693 	    while( (index = find( before, index, TRUE, len ) ) != -1 ) {
1694 		memcpy( d+index, after, al );
1695 		index += bl;
1696 	    }
1697 	}
1698     } else if ( al < bl ) {
1699 	uint to = 0;
1700 	uint movestart = 0;
1701 	uint num = 0;
1702 	while( (index = find( before, index, TRUE, len ) ) != -1 ) {
1703 	    if ( num ) {
1704 		int msize = index - movestart;
1705 		if ( msize > 0 ) {
1706 		    memmove( d + to, d + movestart, msize );
1707 		    to += msize;
1708 		}
1709 	    } else {
1710 		to = index;
1711 	    }
1712 	    if ( al ) {
1713 		memcpy( d + to, after, al );
1714 		to += al;
1715 	    }
1716 	    index += bl;
1717 	    movestart = index;
1718 	    num++;
1719 	}
1720 	if ( num ) {
1721 	    int msize = len - movestart;
1722 	    if ( msize > 0 )
1723 		memmove( d + to, d + movestart, msize );
1724 	    resize( len - num*(bl-al) + 1 );
1725 	}
1726     } else {
1727 	// the most complex case. We don't want to loose performance by doing repeated
1728 	// copies and reallocs of the string.
1729 	while( index != -1 ) {
1730 	    uint indices[4096];
1731 	    uint pos = 0;
1732 	    while( pos < 4095 ) {
1733 		index = find(before, index, TRUE, len);
1734 		if ( index == -1 )
1735 		    break;
1736 		indices[pos++] = index;
1737 		index += bl;
1738 		// avoid infinite loop
1739 		if ( !bl )
1740 		    index++;
1741 	    }
1742 	    if ( !pos )
1743 		break;
1744 
1745 	    // we have a table of replacement positions, use them for fast replacing
1746 	    int adjust = pos*(al-bl);
1747 	    // index has to be adjusted in case we get back into the loop above.
1748 	    if ( index != -1 )
1749 		index += adjust;
1750 	    uint newlen = len + adjust;
1751 	    int moveend = len;
1752 	    if ( newlen > len ) {
1753 		resize( newlen + 1 );
1754 		len = newlen;
1755 	    }
1756 	    d = data();
1757 
1758 	    while( pos ) {
1759 		pos--;
1760 		int movestart = indices[pos] + bl;
1761 		int insertstart = indices[pos] + pos*(al-bl);
1762 		int moveto = insertstart + al;
1763 		memmove( d + moveto, d + movestart, (moveend - movestart) );
1764 		if ( after )
1765 		    memcpy( d + insertstart, after, al );
1766 		moveend = movestart - bl;
1767 	    }
1768 	}
1769     }
1770     return *this;
1771 }
1772 
1773 /*! \overload
1774 
1775   Replaces every occurrence of \a c1 with the char \a c2.
1776   Returns a reference to the string.
1777 */
replace(char c1,char c2)1778 QCString &QCString::replace( char c1, char c2 )
1779 {
1780     detach();
1781     uint i = 0;
1782     char *d = data();
1783     uint len = length();
1784     while ( i < len ) {
1785 	if ( d[i] == c1 )
1786 	    d[i] = c2;
1787 	i++;
1788     }
1789     return *this;
1790 }
1791 
1792 
1793 #ifndef QT_NO_REGEXP_CAPTURE
1794 /*!
1795     \overload
1796 
1797     Finds the first occurrence of the regular expression \a rx,
1798     starting at position \a index.
1799 
1800     Returns the position of the next match, or -1 if \a rx was not
1801     found.
1802 
1803     \warning If you want to apply this function repeatedly to the same
1804     string it is more efficient to convert the string to a QString and
1805     apply the function to that.
1806 */
1807 
find(const QRegExp & rx,int index) const1808 int QCString::find( const QRegExp& rx, int index ) const
1809 {
1810     QString d = QString::fromAscii( data() );
1811     return d.find( rx, index );
1812 }
1813 
1814 /*!
1815     \overload
1816 
1817     Finds the first occurrence of the regular expression \a rx,
1818     starting at position \a index and searching backwards.
1819 
1820     Returns the position of the next match (backwards), or -1 if \a rx
1821     was not found.
1822 
1823     \warning If you want to apply this function repeatedly to the same
1824     string it is more efficient to convert the string to a QString and
1825     apply the function to that.
1826 */
1827 
findRev(const QRegExp & rx,int index) const1828 int QCString::findRev( const QRegExp& rx, int index ) const
1829 {
1830     QString d = QString::fromAscii( data() );
1831     return d.findRev( rx, index );
1832 }
1833 
1834 /*!
1835     \overload
1836 
1837     Counts the number of overlapping occurrences of \a rx in the string.
1838 
1839     Example:
1840     \code
1841     QString s = "banana and panama";
1842     QRegExp r = QRegExp( "a[nm]a", TRUE, FALSE );
1843     s.contains( r ); // 4 matches
1844     \endcode
1845 
1846     \sa find(), findRev()
1847 
1848     \warning If you want to apply this function repeatedly to the same
1849     string it is more efficient to convert the string to a QString and
1850     apply the function to that.
1851 */
1852 
contains(const QRegExp & rx) const1853 int QCString::contains( const QRegExp &rx ) const
1854 {
1855     QString d = QString::fromAscii( data() );
1856     return d.contains( rx );
1857 }
1858 
1859 
1860 /*!
1861     \overload
1862 
1863     Replaces every occurrence of \a rx in the string with \a str.
1864     Returns a reference to the string.
1865 
1866     Example:
1867     \code
1868     QString s = "banana";
1869     s.replace( QRegExp("a.*a"), "" );     // becomes "b"
1870 
1871     s = "banana";
1872     s.replace( QRegExp("^[bn]a"), "X" );  // becomes "Xnana"
1873 
1874     s = "banana";
1875     s.replace( QRegExp("^[bn]a"), "" );   // becomes "nana"
1876     \endcode
1877 
1878     \warning If you want to apply this function repeatedly to the same
1879     string it is more efficient to convert the string to a QString and
1880     apply the function to that.
1881 */
1882 
replace(const QRegExp & rx,const char * str)1883 QCString &QCString::replace( const QRegExp &rx, const char *str )
1884 {
1885     QString d = QString::fromAscii( data() );
1886     QString r = QString::fromAscii( str );
1887     d.replace( rx, r );
1888     setStr( d.ascii() );
1889     return *this;
1890 }
1891 #endif //QT_NO_REGEXP
1892 
1893 /*!
1894     Returns the string converted to a \c long value.
1895 
1896     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
1897     number, or if it has trailing garbage; otherwise \a *ok is set to
1898     TRUE.
1899 */
1900 
toLong(bool * ok) const1901 long QCString::toLong( bool *ok ) const
1902 {
1903     char *p = data();
1904     long val=0;
1905     const long max_mult = LONG_MAX / 10;
1906     bool is_ok = FALSE;
1907     int neg = 0;
1908     if ( !p )
1909 	goto bye;
1910     while ( isspace((uchar) *p) )		// skip leading space
1911 	p++;
1912     if ( *p == '-' ) {
1913 	p++;
1914 	neg = 1;
1915     } else if ( *p == '+' ) {
1916 	p++;
1917     }
1918     if ( !isdigit((uchar) *p) )
1919 	goto bye;
1920     while ( isdigit((uchar) *p) ) {
1921 	if ( val > max_mult || (val == max_mult && (*p-'0') > 7+neg) )
1922 	    goto bye;
1923 	val = 10*val + (*p++ - '0');
1924     }
1925     if ( neg )
1926 	val = -val;
1927     while ( isspace((uchar) *p) )		// skip trailing space
1928 	p++;
1929     if ( *p == '\0' )
1930 	is_ok = TRUE;
1931 bye:
1932     if ( ok )
1933 	*ok = is_ok;
1934     return is_ok ? val : 0;
1935 }
1936 
1937 /*!
1938     Returns the string converted to an \c{unsigned long} value.
1939 
1940     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
1941     number, or if it has trailing garbage; otherwise \a *ok is set to
1942     TRUE.
1943 */
1944 
toULong(bool * ok) const1945 ulong QCString::toULong( bool *ok ) const
1946 {
1947     char *p = data();
1948     ulong val=0;
1949     const ulong max_mult = ULONG_MAX / 10;
1950     bool is_ok = FALSE;
1951     if ( !p )
1952 	goto bye;
1953     while ( isspace((uchar) *p) )		// skip leading space
1954 	p++;
1955     if ( *p == '+' )
1956 	p++;
1957     if ( !isdigit((uchar) *p) )
1958 	goto bye;
1959     while ( isdigit((uchar) *p) ) {
1960 	if ( val > max_mult || (val == max_mult && (*p-'0') > 5) )
1961 	    goto bye;
1962 	val = 10*val + (*p++ - '0');
1963     }
1964     while ( isspace((uchar) *p) )		// skip trailing space
1965 	p++;
1966     if ( *p == '\0' )
1967 	is_ok = TRUE;
1968 bye:
1969     if ( ok )
1970 	*ok = is_ok;
1971     return is_ok ? val : 0;
1972 }
1973 
1974 /*!
1975     Returns the string converted to a \c{short} value.
1976 
1977     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
1978     number, is out of range, or if it has trailing garbage; otherwise
1979     \a *ok is set to TRUE.
1980 */
1981 
toShort(bool * ok) const1982 short QCString::toShort( bool *ok ) const
1983 {
1984     long v = toLong( ok );
1985     if ( v < SHRT_MIN || v > SHRT_MAX ) {
1986 	if ( ok )
1987 	    *ok = FALSE;
1988 	v = 0;
1989     }
1990     return (short)v;
1991 }
1992 
1993 /*!
1994     Returns the string converted to an \c{unsigned short} value.
1995 
1996     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
1997     number, is out of range, or if it has trailing garbage; otherwise
1998     \a *ok is set to TRUE.
1999 */
2000 
toUShort(bool * ok) const2001 ushort QCString::toUShort( bool *ok ) const
2002 {
2003     ulong v = toULong( ok );
2004     if ( v > USHRT_MAX ) {
2005 	if ( ok )
2006 	    *ok = FALSE;
2007 	v = 0;
2008     }
2009     return (ushort)v;
2010 }
2011 
2012 
2013 /*!
2014     Returns the string converted to a \c{int} value.
2015 
2016     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
2017     number, or if it has trailing garbage; otherwise \a *ok is set to
2018     TRUE.
2019 */
2020 
toInt(bool * ok) const2021 int QCString::toInt( bool *ok ) const
2022 {
2023     long v = toLong( ok );
2024     if ( v < INT_MIN || v > INT_MAX ) {
2025 	if ( ok )
2026 	    *ok = FALSE;
2027 	v = 0;
2028     }
2029     return (int)v;
2030 }
2031 
2032 /*!
2033     Returns the string converted to an \c{unsigned int} value.
2034 
2035     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
2036     number, or if it has trailing garbage; otherwise \a *ok is set to
2037     TRUE.
2038 */
2039 
toUInt(bool * ok) const2040 uint QCString::toUInt( bool *ok ) const
2041 {
2042     ulong v = toULong( ok );
2043     if ( v > UINT_MAX ) {
2044 	if ( ok )
2045 	    *ok = FALSE;
2046 	v = 0;
2047     }
2048     return (uint)v;
2049 }
2050 
2051 /*!
2052     Returns the string converted to a \c{double} value.
2053 
2054     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
2055     number, or if it has trailing garbage; otherwise \a *ok is set to
2056     TRUE.
2057 */
2058 
toDouble(bool * ok) const2059 double QCString::toDouble( bool *ok ) const
2060 {
2061     char *end;
2062     double val = strtod( data() ? data() : "", &end );
2063     if ( ok )
2064 	*ok = ( data() && *data() && ( end == 0 || *end == '\0' ) );
2065     return val;
2066 }
2067 
2068 /*!
2069     Returns the string converted to a \c{float} value.
2070 
2071     If \a ok is not 0: \a *ok is set to FALSE if the string is not a
2072     number, or if it has trailing garbage; otherwise \a *ok is set to
2073     TRUE.
2074 */
2075 
toFloat(bool * ok) const2076 float QCString::toFloat( bool *ok ) const
2077 {
2078     return (float)toDouble( ok );
2079 }
2080 
2081 
2082 /*!
2083     Makes a deep copy of \a str. Returns a reference to the string.
2084 */
2085 
setStr(const char * str)2086 QCString &QCString::setStr( const char *str )
2087 {
2088     detach();
2089     if ( str )					// valid string
2090 	store( str, qstrlen(str)+1 );
2091     else					// empty
2092 	resize( 0 );
2093     return *this;
2094 }
2095 
2096 /*!
2097     \overload
2098 
2099     Sets the string to the string representation of the number \a n
2100     and returns a reference to the string.
2101 */
2102 
setNum(long n)2103 QCString &QCString::setNum( long n )
2104 {
2105     detach();
2106     char buf[20];
2107     register char *p = &buf[19];
2108     bool neg;
2109     if ( n < 0 ) {
2110 	neg = TRUE;
2111 	n = -n;
2112     } else {
2113 	neg = FALSE;
2114     }
2115     *p = '\0';
2116     do {
2117 	*--p = ((int)(n%10)) + '0';
2118 	n /= 10;
2119     } while ( n );
2120     if ( neg )
2121 	*--p = '-';
2122     store( p, qstrlen(p)+1 );
2123     return *this;
2124 }
2125 
2126 /*!
2127     \overload
2128 
2129     Sets the string to the string representation of the number \a n
2130     and returns a reference to the string.
2131 */
2132 
setNum(ulong n)2133 QCString &QCString::setNum( ulong n )
2134 {
2135     detach();
2136     char buf[20];
2137     register char *p = &buf[19];
2138     *p = '\0';
2139     do {
2140 	*--p = ((int)(n%10)) + '0';
2141 	n /= 10;
2142     } while ( n );
2143     store( p, qstrlen(p)+1 );
2144     return *this;
2145 }
2146 
2147 /*!
2148     \overload QCString &QCString::setNum( int n )
2149 
2150     Sets the string to the string representation of the number \a n
2151     and returns a reference to the string.
2152 */
2153 
2154 /*!
2155     \overload QCString &QCString::setNum( uint n )
2156 
2157     Sets the string to the string representation of the number \a n
2158     and returns a reference to the string.
2159 */
2160 
2161 /*!
2162     \overload QCString &QCString::setNum( short n )
2163 
2164     Sets the string to the string representation of the number \a n
2165     and returns a reference to the string.
2166 */
2167 
2168 /*!
2169     \overload QCString &QCString::setNum( ushort n )
2170 
2171     Sets the string to the string representation of the number \a n
2172     and returns a reference to the string.
2173 */
2174 
2175 /*!
2176     Sets the string to the string representation of the number \a n
2177     and returns a reference to the string.
2178 
2179     The format of the string representation is specified by the format
2180     character \a f, and the precision (number of digits after the
2181     decimal point) is specified with \a prec.
2182 
2183     The valid formats for \a f are 'e', 'E', 'f', 'g' and 'G'. The
2184     formats are the same as for sprintf(); they are explained in \l
2185     QString::arg().
2186 */
2187 
setNum(double n,char f,int prec)2188 QCString &QCString::setNum( double n, char f, int prec )
2189 {
2190 #if defined(QT_CHECK_RANGE)
2191     if ( !(f=='f' || f=='F' || f=='e' || f=='E' || f=='g' || f=='G') )
2192 	qWarning( "QCString::setNum: Invalid format char '%c'", f );
2193 #endif
2194     char format[20];
2195     register char *fs = format;			// generate format string
2196     *fs++ = '%';				//   "%.<prec>l<f>"
2197     if ( prec > 99 )
2198 	prec = 99;
2199     *fs++ = '.';
2200     if ( prec >= 10 ) {
2201 	*fs++ = prec / 10 + '0';
2202 	*fs++ = prec % 10 + '0';
2203     } else {
2204 	*fs++ = prec + '0';
2205     }
2206     *fs++ = 'l';
2207     *fs++ = f;
2208     *fs = '\0';
2209     return sprintf( format, n );
2210 }
2211 
2212 /*! \overload QCString &QCString::setNum( float n, char f, int prec ) */
2213 
2214 
2215 /*!
2216     Sets the character at position \a index to \a c and expands the
2217     string if necessary, padding with spaces.
2218 
2219     Returns FALSE if \a index was out of range and the string could
2220     not be expanded; otherwise returns TRUE.
2221 */
2222 
setExpand(uint index,char c)2223 bool QCString::setExpand( uint index, char c )
2224 {
2225     detach();
2226     uint oldlen = length();
2227     if ( index >= oldlen ) {
2228 	if ( !QByteArray::resize( index+2 ) )	// no memory
2229 	    return FALSE;
2230 	if ( index > oldlen )
2231 	    memset( data() + oldlen, ' ', index - oldlen );
2232 	*(data() + index+1) = '\0';		// terminate padded string
2233     }
2234     *(data() + index) = c;
2235     return TRUE;
2236 }
2237 
2238 
2239 /*!
2240     \fn QCString::operator const char *() const
2241 
2242     Returns the string data.
2243 */
2244 
2245 
2246 /*!
2247     \fn QCString& QCString::append( const char *str )
2248 
2249     Appends string \a str to the string and returns a reference to the
2250     string. Equivalent to operator+=().
2251 */
2252 
2253 /*!
2254     Appends string \a str to the string and returns a reference to the string.
2255 */
2256 
operator +=(const char * str)2257 QCString& QCString::operator+=( const char *str )
2258 {
2259     if ( !str )
2260 	return *this;				// nothing to append
2261     detach();
2262     uint len1 = length();
2263     uint len2 = qstrlen(str);
2264     if ( !QByteArray::resize( len1 + len2 + 1, QByteArray::SpeedOptim ) )
2265 	return *this;				// no memory
2266     memcpy( data() + len1, str, len2 + 1 );
2267     return *this;
2268 }
2269 
2270 /*!
2271     \overload
2272 
2273     Appends character \a c to the string and returns a reference to the string.
2274 */
2275 
operator +=(char c)2276 QCString &QCString::operator+=( char c )
2277 {
2278     detach();
2279     uint len = length();
2280     if ( !QByteArray::resize( len + 2, QByteArray::SpeedOptim  ) )
2281 	return *this;				// no memory
2282     *(data() + len) = c;
2283     *(data() + len+1) = '\0';
2284     return *this;
2285 }
2286 
2287 
2288 /*****************************************************************************
2289   QCString stream functions
2290  *****************************************************************************/
2291 #ifndef QT_NO_DATASTREAM
2292 /*!
2293     \relates QCString
2294 
2295     Writes string \a str to the stream \a s.
2296 
2297     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
2298 */
operator <<(QDataStream & s,const QCString & str)2299 QDataStream &operator<<( QDataStream &s, const QCString &str )
2300 {
2301     return s.writeBytes( str.data(), str.size() );
2302 }
2303 
2304 /*!
2305     \relates QCString
2306 
2307     Reads a string into \a str from the stream \a s.
2308 
2309     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
2310 */
2311 
operator >>(QDataStream & s,QCString & str)2312 QDataStream &operator>>( QDataStream &s, QCString &str )
2313 {
2314     str.detach();
2315     Q_UINT32 len;
2316     s >> len;					// read size of string
2317     if ( len == 0 || s.eof() ) {		// end of file reached
2318 	str.resize( 0 );
2319 	return s;
2320     }
2321     if ( !str.QByteArray::resize( (uint)len )) {// resize string
2322 #if defined(QT_CHECK_NULL)
2323 	qWarning( "QDataStream: Not enough memory to read QCString" );
2324 #endif
2325 	len = 0;
2326     }
2327     if ( len > 0 )				// not null array
2328 	s.readRawBytes( str.data(), (uint)len );
2329     return s;
2330 }
2331 #endif //QT_NO_DATASTREAM
2332 
2333 /*****************************************************************************
2334   Documentation for related functions
2335  *****************************************************************************/
2336 
2337 /*!
2338     \fn bool operator==( const QCString &s1, const QCString &s2 )
2339 
2340     \relates QCString
2341 
2342     Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE.
2343 
2344     Equivalent to qstrcmp(\a s1, \a s2) == 0.
2345 */
2346 
2347 /*!
2348     \overload bool operator==( const QCString &s1, const char *s2 )
2349 
2350     \relates QCString
2351 
2352     Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE.
2353 
2354     Equivalent to qstrcmp(\a s1, \a s2) == 0.
2355 */
2356 
2357 /*!
2358     \overload bool operator==( const char *s1, const QCString &s2 )
2359 
2360     \relates QCString
2361 
2362     Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE.
2363 
2364     Equivalent to qstrcmp(\a s1, \a s2) == 0.
2365 */
2366 
2367 /*!
2368     \fn bool operator!=( const QCString &s1, const QCString &s2 )
2369 
2370     \relates QCString
2371 
2372     Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE.
2373 
2374     Equivalent to qstrcmp(\a s1, \a s2) != 0.
2375 */
2376 
2377 /*!
2378     \overload bool operator!=( const QCString &s1, const char *s2 )
2379 
2380     \relates QCString
2381 
2382     Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE.
2383 
2384     Equivalent to qstrcmp(\a s1, \a s2) != 0.
2385 */
2386 
2387 /*!
2388     \overload bool operator!=( const char *s1, const QCString &s2 )
2389 
2390     \relates QCString
2391 
2392     Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE.
2393 
2394     Equivalent to qstrcmp(\a s1, \a s2) != 0.
2395 */
2396 
2397 /*!
2398     \fn bool operator<( const QCString &s1, const char *s2 )
2399 
2400     \relates QCString
2401 
2402     Returns TRUE if \a s1 is less than \a s2; otherwise returns FALSE.
2403 
2404     Equivalent to qstrcmp(\a s1, \a s2) \< 0.
2405 
2406     \sa \link #asciinotion Note on character comparisons \endlink
2407 */
2408 
2409 /*!
2410     \overload bool operator<( const char *s1, const QCString &s2 )
2411 
2412     \relates QCString
2413 
2414     Returns TRUE if \a s1 is less than \a s2; otherwise returns FALSE.
2415 
2416     Equivalent to qstrcmp(\a s1, \a s2) \< 0.
2417 
2418     \sa \link #asciinotion Note on character comparisons \endlink
2419 */
2420 
2421 /*!
2422     \fn bool operator<=( const QCString &s1, const char *s2 )
2423 
2424     \relates QCString
2425 
2426     Returns TRUE if \a s1 is less than or equal to \a s2; otherwise
2427     returns FALSE.
2428 
2429     Equivalent to qstrcmp(\a s1, \a s2) \<= 0.
2430 
2431     \sa \link #asciinotion Note on character comparisons \endlink
2432 */
2433 
2434 /*!
2435     \overload bool operator<=( const char *s1, const QCString &s2 )
2436 
2437     \relates QCString
2438 
2439     Returns TRUE if \a s1 is less than or equal to \a s2; otherwise
2440     returns FALSE.
2441 
2442     Equivalent to qstrcmp(\a s1, \a s2) \<= 0.
2443 
2444     \sa \link #asciinotion Note on character comparisons \endlink
2445 */
2446 
2447 /*!
2448     \fn bool operator>( const QCString &s1, const char *s2 )
2449 
2450     \relates QCString
2451 
2452     Returns TRUE if \a s1 is greater than \a s2; otherwise returns FALSE.
2453 
2454     Equivalent to qstrcmp(\a s1, \a s2) \> 0.
2455 
2456     \sa \link #asciinotion Note on character comparisons \endlink
2457 */
2458 
2459 /*!
2460     \overload bool operator>( const char *s1, const QCString &s2 )
2461 
2462     \relates QCString
2463 
2464     Returns TRUE if \a s1 is greater than \a s2; otherwise returns FALSE.
2465 
2466     Equivalent to qstrcmp(\a s1, \a s2) \> 0.
2467 
2468     \sa \link #asciinotion Note on character comparisons \endlink
2469 */
2470 
2471 /*!
2472     \fn bool operator>=( const QCString &s1, const char *s2 )
2473 
2474     \relates QCString
2475 
2476     Returns TRUE if \a s1 is greater than or equal to \a s2; otherwise
2477     returns FALSE.
2478 
2479     Equivalent to qstrcmp(\a s1, \a s2) \>= 0.
2480 
2481     \sa \link #asciinotion Note on character comparisons \endlink
2482 */
2483 
2484 /*!
2485     \overload bool operator>=( const char *s1, const QCString &s2 )
2486 
2487     \relates QCString
2488 
2489     Returns TRUE if \a s1 is greater than or equal to \a s2; otherwise
2490     returns FALSE.
2491 
2492     Equivalent to qstrcmp(\a s1, \a s2) \>= 0.
2493 
2494     \sa \link #asciinotion Note on character comparisons \endlink
2495 */
2496 
2497 /*!
2498     \fn const QCString operator+( const QCString &s1, const QCString &s2 )
2499 
2500     \relates QCString
2501 
2502     Returns a string which consists of the concatenation of \a s1 and
2503     \a s2.
2504 */
2505 
2506 /*!
2507     \overload const QCString operator+( const QCString &s1, const char *s2 )
2508 
2509     \relates QCString
2510 
2511     Returns a string which consists of the concatenation of \a s1 and \a s2.
2512 */
2513 
2514 /*!
2515     \overload const QCString operator+( const char *s1, const QCString &s2 )
2516 
2517     \relates QCString
2518 
2519     Returns a string which consists of the concatenation of \a s1 and \a s2.
2520 */
2521 
2522 /*!
2523     \overload const QCString operator+( const QCString &s, char c )
2524 
2525     \relates QCString
2526 
2527     Returns a string which consists of the concatenation of \a s and \a c.
2528 */
2529 
2530 /*!
2531     \overload const QCString operator+( char c, const QCString &s )
2532 
2533     \relates QCString
2534 
2535     Returns a string which consists of the concatenation of \a c and \a s.
2536 */
2537