📄 qcstring.cpp
字号:
If \a ok is not 0: \a *ok is set to FALSE if the string is not a number, or if it has trailing garbage; otherwise \a *ok is set to TRUE.*/uint QCString::toUInt( bool *ok ) const{ ulong v = toULong( ok ); if ( v > UINT_MAX ) { if ( ok ) *ok = FALSE; v = 0; } return (uint)v;}/*! Returns the string converted to a \c{double} value. If \a ok is not 0: \a *ok is set to FALSE if the string is not a number, or if it has trailing garbage; otherwise \a *ok is set to TRUE.*/double QCString::toDouble( bool *ok ) const{ char *end; double val = strtod( data() ? data() : "", &end ); if ( ok ) *ok = ( data() && *data() && ( end == 0 || *end == '\0' ) ); return val;}/*! Returns the string converted to a \c{float} value. If \a ok is not 0: \a *ok is set to FALSE if the string is not a number, or if it has trailing garbage; otherwise \a *ok is set to TRUE.*/float QCString::toFloat( bool *ok ) const{ return (float)toDouble( ok );}/*! Makes a deep copy of \a str. Returns a reference to the string.*/QCString &QCString::setStr( const char *str ){ detach(); if ( str ) // valid string store( str, qstrlen(str)+1 ); else // empty resize( 0 ); return *this;}/*! \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*/QCString &QCString::setNum( long n ){ detach(); char buf[20]; register char *p = &buf[19]; bool neg; if ( n < 0 ) { neg = TRUE; n = -n; } else { neg = FALSE; } *p = '\0'; do { *--p = ((int)(n%10)) + '0'; n /= 10; } while ( n ); if ( neg ) *--p = '-'; store( p, qstrlen(p)+1 ); return *this;}/*! \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*/QCString &QCString::setNum( ulong n ){ detach(); char buf[20]; register char *p = &buf[19]; *p = '\0'; do { *--p = ((int)(n%10)) + '0'; n /= 10; } while ( n ); store( p, qstrlen(p)+1 ); return *this;}/*! \overload QCString &QCString::setNum( int n ) Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \overload QCString &QCString::setNum( uint n ) Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \overload QCString &QCString::setNum( short n ) Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \overload QCString &QCString::setNum( ushort n ) Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! Sets the string to the string representation of the number \a n and returns a reference to the string. The format of the string representation is specified by the format character \a f, and the precision (number of digits after the decimal point) is specified with \a prec. The valid formats for \a f are 'e', 'E', 'f', 'g' and 'G'. The formats are the same as for sprintf(); they are explained in \l QString::arg().*/QCString &QCString::setNum( double n, char f, int prec ){#if defined(QT_CHECK_RANGE) if ( !(f=='f' || f=='F' || f=='e' || f=='E' || f=='g' || f=='G') ) qWarning( "QCString::setNum: Invalid format char '%c'", f );#endif char format[20]; register char *fs = format; // generate format string *fs++ = '%'; // "%.<prec>l<f>" if ( prec > 99 ) prec = 99; *fs++ = '.'; if ( prec >= 10 ) { *fs++ = prec / 10 + '0'; *fs++ = prec % 10 + '0'; } else { *fs++ = prec + '0'; } *fs++ = 'l'; *fs++ = f; *fs = '\0'; return sprintf( format, n );}/*! \overload QCString &QCString::setNum( float n, char f, int prec ) *//*! Sets the character at position \a index to \a c and expands the string if necessary, padding with spaces. Returns FALSE if \a index was out of range and the string could not be expanded; otherwise returns TRUE.*/bool QCString::setExpand( uint index, char c ){ detach(); uint oldlen = length(); if ( index >= oldlen ) { if ( !QByteArray::resize( index+2 ) ) // no memory return FALSE; if ( index > oldlen ) memset( data() + oldlen, ' ', index - oldlen ); *(data() + index+1) = '\0'; // terminate padded string } *(data() + index) = c; return TRUE;}/*! \fn QCString::operator const char *() const Returns the string data.*//*! \fn QCString& QCString::append( const char *str ) Appends string \a str to the string and returns a reference to the string. Equivalent to operator+=().*//*! Appends string \a str to the string and returns a reference to the string.*/QCString& QCString::operator+=( const char *str ){ if ( !str ) return *this; // nothing to append detach(); uint len1 = length(); uint len2 = qstrlen(str); if ( !QByteArray::resize( len1 + len2 + 1, QByteArray::SpeedOptim ) ) return *this; // no memory memcpy( data() + len1, str, len2 + 1 ); return *this;}/*! \overload Appends character \a c to the string and returns a reference to the string.*/QCString &QCString::operator+=( char c ){ detach(); uint len = length(); if ( !QByteArray::resize( len + 2, QByteArray::SpeedOptim ) ) return *this; // no memory *(data() + len) = c; *(data() + len+1) = '\0'; return *this;}/***************************************************************************** QCString stream functions *****************************************************************************/#ifndef QT_NO_DATASTREAM/*! \relates QCString Writes string \a str to the stream \a s. \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator<<( QDataStream &s, const QCString &str ){ return s.writeBytes( str.data(), str.size() );}/*! \relates QCString Reads a string into \a str from the stream \a s. \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator>>( QDataStream &s, QCString &str ){ str.detach(); Q_UINT32 len; s >> len; // read size of string if ( len == 0 || s.eof() ) { // end of file reached str.resize( 0 ); return s; } if ( !str.QByteArray::resize( (uint)len )) {// resize string#if defined(QT_CHECK_NULL) qWarning( "QDataStream: Not enough memory to read QCString" );#endif len = 0; } if ( len > 0 ) // not null array s.readRawBytes( str.data(), (uint)len ); return s;}#endif //QT_NO_DATASTREAM/***************************************************************************** Documentation for related functions *****************************************************************************//*! \fn bool operator==( const QCString &s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \overload bool operator==( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \overload bool operator==( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \fn bool operator!=( const QCString &s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \overload bool operator!=( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \overload bool operator!=( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \fn bool operator<( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 is less than \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \< 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \overload bool operator<( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 is less than \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \< 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \fn bool operator<=( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 is less than or equal to \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \<= 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \overload bool operator<=( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 is less than or equal to \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \<= 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \fn bool operator>( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 is greater than \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \> 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \overload bool operator>( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 is greater than \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \> 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \fn bool operator>=( const QCString &s1, const char *s2 ) \relates QCString Returns TRUE if \a s1 is greater than or equal to \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \>= 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \overload bool operator>=( const char *s1, const QCString &s2 ) \relates QCString Returns TRUE if \a s1 is greater than or equal to \a s2; otherwise returns FALSE. Equivalent to qstrcmp(\a s1, \a s2) \>= 0. \sa \link #asciinotion Note on character comparisons \endlink*//*! \fn const QCString operator+( const QCString &s1, const QCString &s2 ) \relates QCString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \overload const QCString operator+( const QCString &s1, const char *s2 ) \relates QCString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \overload const QCString operator+( const char *s1, const QCString &s2 ) \relates QCString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \overload const QCString operator+( const QCString &s, char c ) \relates QCString Returns a string which consists of the concatenation of \a s and \a c.*//*! \overload const QCString operator+( char c, const QCString &s ) \relates QCString Returns a string which consists of the concatenation of \a c and \a s.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -