Orb/Doxygen/qtools/qcstring.cpp
changeset 3 d8fccb2cd802
parent 0 42188c7ea2d9
equal deleted inserted replaced
2:932c358ece3e 3:d8fccb2cd802
       
     1 /******************************************************************************
       
     2  *
       
     3  * Copyright (C) 1997-2004 by Dimitri van Heesch.
       
     4  *
       
     5  * Permission to use, copy, modify, and distribute this software and its
       
     6  * documentation under the terms of the GNU General Public License is hereby 
       
     7  * granted. No representations are made about the suitability of this software 
       
     8  * for any purpose. It is provided "as is" without express or implied warranty.
       
     9  * See the GNU General Public License for more details.
       
    10  *
       
    11  * Documents produced by Doxygen are derivative works derived from the
       
    12  * input used in their production; they are not affected by this license.
       
    13  *
       
    14  */
       
    15 
       
    16 #include "qcstring.h"
       
    17 #include "qgstring.h"
       
    18 
       
    19 #include <qstring.h>
       
    20 #include <stdlib.h>
       
    21 #include <stdio.h>
       
    22 #include <stdarg.h>
       
    23 #include <ctype.h>
       
    24 #include <qregexp.h>
       
    25 #include <qdatastream.h>
       
    26 
       
    27 
       
    28 QCString::QCString(int size)
       
    29 {
       
    30   if (size>0)
       
    31   {
       
    32     m_data = (char *)malloc(size);
       
    33     if (m_data)
       
    34     {
       
    35       if (size>1) memset(m_data,' ',size-1);
       
    36       m_data[size-1]='\0';
       
    37     }
       
    38   }
       
    39   else
       
    40   {
       
    41     m_data=0;
       
    42   }
       
    43 }
       
    44 
       
    45 QCString::QCString( const QCString &s ) 
       
    46 { 
       
    47   duplicate(s);
       
    48 }
       
    49 
       
    50 QCString::QCString( const char *str )
       
    51 { 
       
    52   duplicate(str);
       
    53 }
       
    54 
       
    55 QCString::QCString( const char *str, uint maxlen )
       
    56 { 
       
    57   uint l;
       
    58   if (str && ( l = QMIN(qstrlen(str),maxlen) )) 
       
    59   { 
       
    60     m_data=(char *)malloc(l+1);
       
    61     strncpy(m_data,str,l+1);
       
    62     m_data[l]='\0';
       
    63   } 
       
    64   else
       
    65   {
       
    66     m_data=0;
       
    67   }
       
    68 }
       
    69 
       
    70 QCString::~QCString()
       
    71 {
       
    72   if (m_data) free(m_data);
       
    73   m_data=0;
       
    74 }
       
    75 
       
    76 QCString &QCString::assign( const char *str )
       
    77 {
       
    78   if (m_data) free(m_data);
       
    79   duplicate(str);
       
    80   return *this;
       
    81 }
       
    82 
       
    83 bool QCString::resize( uint newlen )
       
    84 {
       
    85   if (newlen==0)
       
    86   {
       
    87     if (m_data) { free(m_data); m_data=0; }
       
    88     return TRUE;
       
    89   }
       
    90   if (m_data==0) // newlen>0
       
    91   {
       
    92     m_data = (char *)malloc(newlen);
       
    93   }
       
    94   else
       
    95   {
       
    96     m_data = (char *)realloc(m_data,newlen);
       
    97   }
       
    98   if (m_data==0) return FALSE;
       
    99   m_data[newlen-1]='\0';
       
   100   return TRUE;
       
   101 }
       
   102 
       
   103 bool QCString::fill( char c, int len )
       
   104 {
       
   105   uint l=length();
       
   106   if (len<0) len=l;
       
   107   if ((uint)len!=l) 
       
   108   {
       
   109     if (m_data) free(m_data);
       
   110     if (len>0)
       
   111     {
       
   112       m_data=(char *)malloc(len+1);
       
   113       if (m_data==0) return FALSE;
       
   114       m_data[len]='\0';
       
   115     }
       
   116     else
       
   117     {
       
   118       m_data=0;
       
   119     }
       
   120   }
       
   121   if (len>0)
       
   122   {
       
   123     uint i;
       
   124     for (i=0;i<(uint)len;i++) m_data[i]=c;
       
   125   }
       
   126   return TRUE;
       
   127 }
       
   128 
       
   129 QCString &QCString::sprintf( const char *format, ... )
       
   130 {
       
   131   va_list ap;
       
   132   va_start( ap, format );
       
   133   uint l = length();
       
   134   const uint minlen=256;
       
   135   if (l<minlen)
       
   136   {
       
   137     if (m_data) 
       
   138       m_data = (char *)realloc(m_data,minlen);
       
   139     else
       
   140       m_data = (char *)malloc(minlen);
       
   141   }
       
   142   vsprintf( m_data, format, ap );
       
   143   resize( qstrlen(m_data) + 1 );              // truncate
       
   144   va_end( ap );
       
   145   return *this;
       
   146 }
       
   147 
       
   148 
       
   149 int QCString::find( char c, int index, bool cs ) const
       
   150 {
       
   151   uint len = length();
       
   152   if ( m_data==0 || (uint)index>len )               // index outside string
       
   153     return -1;
       
   154   register const char *d;
       
   155   if ( cs ) // case sensitive
       
   156   {  
       
   157     d = strchr( m_data+index, c );
       
   158   } 
       
   159   else 
       
   160   {
       
   161     d = m_data+index;
       
   162     c = tolower( (uchar) c );
       
   163     while ( *d && tolower((uchar) *d) != c )
       
   164       d++;
       
   165     if ( !*d && c )                         // not found
       
   166       d = 0;
       
   167   }
       
   168   return d ? (int)(d - m_data) : -1;
       
   169 }
       
   170 
       
   171 int QCString::find( const char *str, int index, bool cs ) const
       
   172 {
       
   173   uint l = length();
       
   174   if ( m_data==0 || (uint)index > l )         // index outside string
       
   175     return -1;
       
   176   if ( !str )                                 // no search string
       
   177     return -1;
       
   178   if ( !*str )                                // zero-length search string
       
   179     return index;
       
   180   register const char *d;
       
   181   if ( cs )                                   // case sensitive
       
   182   {              
       
   183     d = strstr( m_data+index, str );
       
   184   } 
       
   185   else                                        // case insensitive
       
   186   {
       
   187     d = m_data+index;
       
   188     int len = qstrlen( str );
       
   189     while ( *d ) 
       
   190     {
       
   191       if ( qstrnicmp(d, str, len) == 0 )
       
   192         break;
       
   193       d++;
       
   194     }
       
   195     if ( !*d )                              // not found
       
   196       d = 0;
       
   197   }
       
   198   return d ? (int)(d - m_data) : -1;
       
   199 }
       
   200 
       
   201 int QCString::find( const QRegExp &rx, int index ) const
       
   202 {
       
   203   QString d = QString::fromLatin1( m_data );
       
   204   return d.find( rx, index );
       
   205 }
       
   206 
       
   207 int QCString::findRev( char c, int index, bool cs) const
       
   208 {
       
   209   const char *b = m_data;
       
   210   const char *d;
       
   211   uint len = length();
       
   212   if ( b == 0 ) return -1;  // empty string
       
   213   if ( index < 0 )          // neg index ==> start from end
       
   214   {
       
   215     if ( len == 0 ) return -1;
       
   216     if ( cs ) 
       
   217     {
       
   218       d = strrchr( b, c );
       
   219       return d ? (int)(d - b) : -1;
       
   220     }
       
   221     index = len;
       
   222   } 
       
   223   else if ( (uint)index > len )  // bad index
       
   224   {      
       
   225     return -1;
       
   226   }
       
   227   d = b+index;
       
   228   if ( cs )   // case sensitive
       
   229   {
       
   230     while ( d >= b && *d != c )
       
   231       d--;
       
   232   } 
       
   233   else  // case insensitive
       
   234   {
       
   235     c = tolower( (uchar) c );
       
   236     while ( d >= b && tolower((uchar) *d) != c )
       
   237       d--;
       
   238   }
       
   239   return d >= b ? (int)(d - b) : -1;
       
   240 }
       
   241 
       
   242 int QCString::findRev( const char *str, int index, bool cs) const
       
   243 {
       
   244   int slen = qstrlen(str);
       
   245   uint len = length();
       
   246   if ( index < 0 )                           // neg index ==> start from end
       
   247     index = len-slen;
       
   248   else if ( (uint)index > len )              // bad index
       
   249     return -1;
       
   250   else if ( (uint)(index + slen) > len )     // str would be too long
       
   251     index = len - slen;
       
   252   if ( index < 0 )
       
   253     return -1;
       
   254 
       
   255   register char *d = m_data + index;
       
   256   if ( cs )                     // case sensitive 
       
   257   {      
       
   258     for ( int i=index; i>=0; i-- )
       
   259       if ( qstrncmp(d--,str,slen)==0 )
       
   260         return i;
       
   261   } 
       
   262   else                          // case insensitive
       
   263   {           
       
   264     for ( int i=index; i>=0; i-- )
       
   265       if ( qstrnicmp(d--,str,slen)==0 )
       
   266         return i;
       
   267   }
       
   268   return -1;
       
   269 
       
   270 }
       
   271 
       
   272 int QCString::findRev( const QRegExp &rx, int index ) const
       
   273 {
       
   274   QString d = QString::fromLatin1( m_data );
       
   275   return d.findRev( rx, index );
       
   276 }
       
   277 
       
   278 int QCString::contains( char c, bool cs ) const
       
   279 {
       
   280   int count = 0;
       
   281   char *d = m_data;
       
   282   if ( !d )
       
   283     return 0;                               
       
   284   if ( cs )                                // case sensitive
       
   285   {
       
   286     while ( *d )
       
   287       if ( *d++ == c )
       
   288         count++;                        
       
   289   } 
       
   290   else                                     // case insensitive
       
   291   {
       
   292     c = tolower( (uchar) c );
       
   293     while ( *d ) {
       
   294       if ( tolower((uchar) *d) == c )
       
   295         count++;
       
   296       d++;
       
   297     }
       
   298   }
       
   299   return count;
       
   300 }
       
   301 
       
   302 int QCString::contains( const char *str, bool cs ) const
       
   303 {
       
   304   int count = 0;
       
   305   char *d = data();
       
   306   if ( !d )
       
   307     return 0;
       
   308   int len = qstrlen( str );
       
   309   while ( *d )   // counts overlapping strings
       
   310   {
       
   311     if ( cs ) 
       
   312     {
       
   313       if ( qstrncmp( d, str, len ) == 0 )
       
   314         count++;
       
   315     } 
       
   316     else 
       
   317     {
       
   318       if ( qstrnicmp(d, str, len) == 0 )
       
   319         count++;
       
   320     }
       
   321     d++;
       
   322   }
       
   323   return count;
       
   324 }
       
   325 
       
   326 int QCString::contains( const QRegExp &rx ) const
       
   327 { 
       
   328   QString d = QString::fromLatin1( m_data );
       
   329   return d.contains( rx );
       
   330 }
       
   331 
       
   332 QCString QCString::left( uint len )  const
       
   333 {
       
   334   if ( isEmpty() ) 
       
   335   {
       
   336     return QCString();
       
   337   } 
       
   338   else if ( len >= length() ) 
       
   339   {
       
   340     return *this;
       
   341   } 
       
   342   else 
       
   343   {
       
   344     QCString s( len+1 );
       
   345     strncpy( s.data(), m_data, len );
       
   346     *(s.data()+len) = '\0';
       
   347     return s;
       
   348   }
       
   349 }
       
   350 
       
   351 QCString QCString::right( uint len ) const
       
   352 {
       
   353   if ( isEmpty() ) 
       
   354   {
       
   355     return QCString();
       
   356   } 
       
   357   else 
       
   358   {
       
   359     uint l = length();
       
   360     if ( len > l ) len = l;
       
   361     char *p = m_data + (l - len); 
       
   362     return QCString( p ); 
       
   363   }       
       
   364 }
       
   365 
       
   366 QCString QCString::mid( uint index, uint len) const
       
   367 {
       
   368   uint slen = length();
       
   369   if ( len == 0xffffffff ) len = slen-index;
       
   370   if ( isEmpty() || index >= slen ) 
       
   371   {
       
   372     return QCString();
       
   373   } 
       
   374   else 
       
   375   {
       
   376     register char *p = data()+index;
       
   377     QCString s( len+1 );
       
   378     strncpy( s.data(), p, len );
       
   379     *(s.data()+len) = '\0';
       
   380     return s;
       
   381   }
       
   382 }
       
   383 
       
   384 QCString QCString::lower() const
       
   385 {
       
   386   QCString s( m_data );
       
   387   register char *p = s.data();
       
   388   if ( p ) 
       
   389   {
       
   390     while ( *p ) 
       
   391     {
       
   392       *p = tolower((uchar) *p);
       
   393       p++;
       
   394     }
       
   395   }
       
   396   return s;
       
   397 }
       
   398 
       
   399 QCString QCString::upper() const
       
   400 {
       
   401   QCString s( m_data );
       
   402   register char *p = s.data();
       
   403   if ( p ) {
       
   404     while ( *p ) {
       
   405       *p = toupper((uchar)*p);
       
   406       p++;
       
   407     }
       
   408   }
       
   409   return s;
       
   410 }
       
   411 
       
   412 QCString QCString::stripWhiteSpace()	const
       
   413 {
       
   414   if ( isEmpty() )                            // nothing to do
       
   415     return *this;
       
   416 
       
   417   register char *s = m_data;
       
   418   int reslen = length();
       
   419   if ( !isspace((uchar) s[0]) && !isspace((uchar) s[reslen-1]) )
       
   420     return *this;                           // returns a copy
       
   421 
       
   422   QCString result(s);
       
   423   s = result.data(); 
       
   424   int start = 0;
       
   425   int end = reslen - 1;
       
   426   while ( isspace((uchar) s[start]) )                 // skip white space from start
       
   427     start++; 
       
   428   if ( s[start] == '\0' ) 
       
   429   {                                                   // only white space
       
   430     return QCString();
       
   431   }
       
   432   while ( end && isspace((uchar) s[end]) )            // skip white space from end
       
   433     end--;
       
   434   end -= start - 1;
       
   435   memmove( result.data(), &s[start], end );
       
   436   result.resize( end + 1 );
       
   437   return result;
       
   438 }
       
   439 
       
   440 QCString QCString::simplifyWhiteSpace() const
       
   441 {
       
   442   if ( isEmpty() )                            // nothing to do
       
   443     return *this;
       
   444 
       
   445   QCString result( length()+1 );
       
   446   char *from  = data();
       
   447   char *to    = result.data();
       
   448   char *first = to;
       
   449   while ( TRUE ) 
       
   450   {
       
   451     while ( *from && isspace((uchar) *from) )
       
   452       from++;
       
   453     while ( *from && !isspace((uchar)*from) )
       
   454       *to++ = *from++;
       
   455     if ( *from )
       
   456       *to++ = 0x20;                       // ' '
       
   457     else
       
   458       break;
       
   459   }
       
   460   if ( to > first && *(to-1) == 0x20 )
       
   461     to--;
       
   462   *to = '\0';
       
   463   result.resize( (int)((long)to - (long)result.data()) + 1 );
       
   464   return result;
       
   465 }
       
   466 
       
   467 QCString &QCString::insert( uint index, const char *s )
       
   468 {   
       
   469   int len = s ? qstrlen(s) : 0;
       
   470   if ( len == 0 )
       
   471     return *this;
       
   472   uint olen = length();
       
   473   int nlen = olen + len;                      
       
   474   if ( index >= olen )  // insert after end of string
       
   475   {                     
       
   476     m_data = (char *)realloc(m_data,nlen+index-olen+1);
       
   477     if ( m_data ) 
       
   478     {
       
   479       memset( m_data+olen, ' ', index-olen );
       
   480       memcpy( m_data+index, s, len+1 );
       
   481     }
       
   482   } 
       
   483   else if ( (m_data = (char *)realloc(m_data,nlen+1)) )  // normal insert
       
   484   { 
       
   485     memmove( m_data+index+len, m_data+index, olen-index+1 );
       
   486     memcpy( m_data+index, s, len );
       
   487   }
       
   488   return *this;
       
   489 }
       
   490 
       
   491 QCString &QCString::insert( uint index, char c )        // insert char
       
   492 {
       
   493   char buf[2];
       
   494   buf[0] = c;
       
   495   buf[1] = '\0';
       
   496   return insert( index, buf );
       
   497 }
       
   498 
       
   499 QCString& QCString::operator+=( const char *str )
       
   500 {
       
   501   if ( !str ) return *this;  // nothing to append
       
   502   uint len1 = length();
       
   503   uint len2 = qstrlen(str);
       
   504   char *newData = (char *)realloc( m_data, len1 + len2 + 1 );
       
   505   if (newData)
       
   506   {
       
   507     m_data = newData;
       
   508     memcpy( m_data + len1, str, len2 + 1 );
       
   509   }
       
   510   return *this;      
       
   511 }
       
   512 
       
   513 QCString &QCString::operator+=( char c )
       
   514 {
       
   515   uint len = length();
       
   516   char *newData = (char *)realloc( m_data, length()+2 );
       
   517   if (newData)
       
   518   {
       
   519     m_data = newData;
       
   520     m_data[len] = c;
       
   521     m_data[len+1] = '\0';
       
   522   }
       
   523   return *this;
       
   524 }
       
   525 
       
   526 QCString &QCString::remove( uint index, uint len )
       
   527 {
       
   528   uint olen = length();
       
   529   if ( index + len >= olen ) // range problems
       
   530   {             
       
   531     if ( index < olen )  // index ok
       
   532     {                  
       
   533       resize( index+1 );
       
   534     }
       
   535   } 
       
   536   else if ( len != 0 ) 
       
   537   {
       
   538     memmove( m_data+index, m_data+index+len, olen-index-len+1 );
       
   539     resize( olen-len+1 );
       
   540   }
       
   541   return *this;
       
   542 }
       
   543 
       
   544 QCString &QCString::replace( uint index, uint len, const char *s )
       
   545 {
       
   546   remove( index, len );
       
   547   insert( index, s );
       
   548   return *this;
       
   549 }
       
   550 
       
   551 QCString &QCString::replace( const QRegExp &rx, const char *str )
       
   552 {
       
   553   QString d = QString::fromLatin1( m_data );
       
   554   QString r = QString::fromLatin1( str );
       
   555   d.replace( rx, r );
       
   556   operator=( d.ascii() );
       
   557   return *this;
       
   558 }
       
   559 
       
   560 long  QCString::toLong( bool *ok ) const
       
   561 {
       
   562   QString s(m_data);
       
   563   return s.toLong(ok);
       
   564 }
       
   565 
       
   566 ulong QCString::toULong( bool *ok ) const
       
   567 {
       
   568   QString s(m_data);
       
   569   return s.toULong(ok);
       
   570 }
       
   571 
       
   572 short QCString::toShort( bool *ok )	const
       
   573 {
       
   574   QString s(m_data);
       
   575   return s.toShort(ok);
       
   576 }
       
   577 
       
   578 ushort QCString::toUShort( bool *ok ) const
       
   579 {
       
   580   QString s(m_data);
       
   581   return s.toUShort(ok);
       
   582 }
       
   583 
       
   584 int QCString::toInt( bool *ok ) const
       
   585 {
       
   586   QString s(m_data);
       
   587   return s.toInt(ok);
       
   588 }
       
   589 
       
   590 uint QCString::toUInt( bool *ok ) const
       
   591 {
       
   592   QString s(m_data);
       
   593   return s.toUInt(ok);
       
   594 }
       
   595 
       
   596 QCString &QCString::setNum( long n )
       
   597 {
       
   598   char buf[20];
       
   599   register char *p = &buf[19];
       
   600   bool neg;
       
   601   if ( n < 0 ) 
       
   602   {
       
   603     neg = TRUE;
       
   604     n = -n;
       
   605   } 
       
   606   else 
       
   607   {
       
   608     neg = FALSE;
       
   609   }
       
   610   *p = '\0';
       
   611   do 
       
   612   {
       
   613     *--p = ((int)(n%10)) + '0';
       
   614     n /= 10;
       
   615   } while ( n );
       
   616   if ( neg ) *--p = '-';
       
   617   operator=( p );
       
   618   return *this;
       
   619 }
       
   620 
       
   621 QCString &QCString::setNum( ulong n )
       
   622 {
       
   623   char buf[20];
       
   624   register char *p = &buf[19];
       
   625   *p = '\0';
       
   626   do 
       
   627   {
       
   628     *--p = ((int)(n%10)) + '0';
       
   629     n /= 10;
       
   630   } while ( n );
       
   631   operator=( p );
       
   632   return *this;
       
   633 }
       
   634 
       
   635 void QCString::msg_index( uint index )
       
   636 {
       
   637 #if defined(CHECK_RANGE)
       
   638     qWarning( "QCString::at: Absolute index %d out of range", index );
       
   639 #else
       
   640     Q_UNUSED( index )
       
   641 #endif
       
   642 }
       
   643 
       
   644 bool QCString::stripPrefix(const char *prefix)
       
   645 {
       
   646   if (prefix==0) return FALSE;
       
   647   uint plen   = qstrlen(prefix);
       
   648   if (m_data && qstrncmp(prefix,m_data,plen)==0) // prefix matches
       
   649   {
       
   650     uint len    = qstrlen(m_data);
       
   651     uint newlen = len-plen+1;
       
   652     qmemmove(m_data,m_data+plen,newlen);
       
   653     resize(newlen);
       
   654     return TRUE;
       
   655   }
       
   656   return FALSE;
       
   657 }
       
   658 
       
   659 //---------------------------------------------------------------------------
       
   660 
       
   661 void *qmemmove( void *dst, const void *src, uint len )
       
   662 {
       
   663     register char *d;
       
   664     register char *s;
       
   665     if ( dst > src ) {
       
   666 	d = (char *)dst + len - 1;
       
   667 	s = (char *)src + len - 1;
       
   668 	while ( len-- )
       
   669 	    *d-- = *s--;
       
   670     } else if ( dst < src ) {
       
   671 	d = (char *)dst;
       
   672 	s = (char *)src;
       
   673 	while ( len-- )
       
   674 	    *d++ = *s++;
       
   675     }
       
   676     return dst;
       
   677 }
       
   678 
       
   679 char *qstrdup( const char *str )
       
   680 {
       
   681     if ( !str )
       
   682 	return 0;
       
   683     char *dst = new char[strlen(str)+1];
       
   684     CHECK_PTR( dst );
       
   685     return strcpy( dst, str );
       
   686 }
       
   687 
       
   688 char *qstrncpy( char *dst, const char *src, uint len )
       
   689 {
       
   690     if ( !src )
       
   691 	return 0;
       
   692     strncpy( dst, src, len );
       
   693     if ( len > 0 )
       
   694 	dst[len-1] = '\0';
       
   695     return dst;
       
   696 }
       
   697 
       
   698 int qstricmp( const char *str1, const char *str2 )
       
   699 {
       
   700     register const uchar *s1 = (const uchar *)str1;
       
   701     register const uchar *s2 = (const uchar *)str2;
       
   702     int res;
       
   703     uchar c;
       
   704     if ( !s1 || !s2 )
       
   705 	return s1 == s2 ? 0 : (int)((long)s2 - (long)s1);
       
   706     for ( ; !(res = (c=tolower(*s1)) - tolower(*s2)); s1++, s2++ )
       
   707 	if ( !c )				// strings are equal
       
   708 	    break;
       
   709     return res;
       
   710 }
       
   711 
       
   712 int qstrnicmp( const char *str1, const char *str2, uint len )
       
   713 {
       
   714     register const uchar *s1 = (const uchar *)str1;
       
   715     register const uchar *s2 = (const uchar *)str2;
       
   716     int res;
       
   717     uchar c;
       
   718     if ( !s1 || !s2 )
       
   719 	return (int)((long)s2 - (long)s1);
       
   720     for ( ; len--; s1++, s2++ ) {
       
   721 	if ( (res = (c=tolower(*s1)) - tolower(*s2)) )
       
   722 	    return res;
       
   723 	if ( !c )				// strings are equal
       
   724 	    break;
       
   725     }
       
   726     return 0;
       
   727 }
       
   728 
       
   729 #ifndef QT_NO_DATASTREAM
       
   730 
       
   731 QDataStream &operator<<( QDataStream &s, const QByteArray &a )
       
   732 {
       
   733     return s.writeBytes( a.data(), a.size() );
       
   734 }
       
   735 
       
   736 QDataStream &operator>>( QDataStream &s, QByteArray &a )
       
   737 {
       
   738     Q_UINT32 len;
       
   739     s >> len;					// read size of array
       
   740     if ( len == 0 || s.eof() ) {		// end of file reached
       
   741 	a.resize( 0 );
       
   742 	return s;
       
   743     }
       
   744     if ( !a.resize( (uint)len ) ) {		// resize array
       
   745 #if defined(CHECK_NULL)
       
   746 	qWarning( "QDataStream: Not enough memory to read QByteArray" );
       
   747 #endif
       
   748 	len = 0;
       
   749     }
       
   750     if ( len > 0 )				// not null array
       
   751 	s.readRawBytes( a.data(), (uint)len );
       
   752     return s;
       
   753 }
       
   754 
       
   755 QDataStream &operator<<( QDataStream &s, const QCString &str )
       
   756 {
       
   757     return s.writeBytes( str.data(), str.size() );
       
   758 }
       
   759 
       
   760 QDataStream &operator>>( QDataStream &s, QCString &str )
       
   761 {
       
   762     Q_UINT32 len;
       
   763     s >> len;					// read size of string
       
   764     if ( len == 0 || s.eof() ) {		// end of file reached
       
   765 	str.resize( 0 );
       
   766 	return s;
       
   767     }
       
   768     if ( !str.resize( (uint)len )) {// resize string
       
   769 #if defined(CHECK_NULL)
       
   770 	qWarning( "QDataStream: Not enough memory to read QCString" );
       
   771 #endif
       
   772 	len = 0;
       
   773     }
       
   774     if ( len > 0 )				// not null array
       
   775 	s.readRawBytes( str.data(), (uint)len );
       
   776     return s;
       
   777 }
       
   778 
       
   779 #endif //QT_NO_DATASTREAM
       
   780 
       
   781 inline QCString operator+( const QCString &s1, const QGString &s2 )
       
   782 {
       
   783     QCString tmp(s1);
       
   784     tmp += s2.data();
       
   785     return tmp;
       
   786 }
       
   787 
       
   788 inline QCString operator+( const QGString &s1, const QCString &s2 )
       
   789 {
       
   790     QCString tmp(s1.data());
       
   791     tmp += s2;
       
   792     return tmp;
       
   793 }
       
   794