⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextstream.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	    }	    else				// standard padding		*this << (const char*)p;	}	else	    *this << (const char*)p;	fwidth = 0;				// reset field width    }    else	writeBlock( p, qstrlen(p) );    return *this;}/*!  Writes a \c short integer to the stream and returns a reference to  the stream.*/QTextStream &QTextStream::operator<<( signed short i ){    return output_int( I_SHORT | I_SIGNED, i, i < 0 );}/*!  Writes an \c unsigned \c short integer to the stream and returns a reference  to the stream.*/QTextStream &QTextStream::operator<<( unsigned short i ){    return output_int( I_SHORT | I_UNSIGNED, i, FALSE );}/*!  Writes an \c int to the stream and returns a reference to  the stream.*/QTextStream &QTextStream::operator<<( signed int i ){    return output_int( I_INT | I_SIGNED, i, i < 0 );}/*!  Writes an \c unsigned \c int to the stream and returns a reference to  the stream.*/QTextStream &QTextStream::operator<<( unsigned int i ){    return output_int( I_INT | I_UNSIGNED, i, FALSE );}/*!  Writes a \c long \c int to the stream and returns a reference to  the stream.*/QTextStream &QTextStream::operator<<( signed long i ){    return output_int( I_LONG | I_SIGNED, i, i < 0 );}/*!  Writes an \c unsigned \c long \c int to the stream and returns a reference to  the stream.*/QTextStream &QTextStream::operator<<( unsigned long i ){    return output_int( I_LONG | I_UNSIGNED, i, FALSE );}/*!  Writes a \c float to the stream and returns a reference to the stream.*/QTextStream &QTextStream::operator<<( float f ){    return *this << (double)f;}/*!  Writes a \c double to the stream and returns a reference to the stream.*/QTextStream &QTextStream::operator<<( double f ){    CHECK_STREAM_PRECOND    char buf[64];    char f_char;    char format[16];    if ( (flags()&floatfield) == fixed )	f_char = 'f';    else if ( (flags()&floatfield) == scientific )	f_char = (flags() & uppercase) ? 'E' : 'e';    else	f_char = (flags() & uppercase) ? 'G' : 'g';    register char *fs = format;			// generate format string    *fs++ = '%';				//   "%.<prec>l<f_char>"    *fs++ = '.';    int prec = precision();    if ( prec > 99 )	prec = 99;    if ( prec >= 10 ) {	*fs++ = prec / 10 + '0';	*fs++ = prec % 10 + '0';    } else {	*fs++ = prec + '0';    }    *fs++ = 'l';    *fs++ = f_char;    *fs = '\0';    sprintf( buf, format, f );			// convert to text    if ( fwidth )				// padding	*this << (const char*)buf;    else					// just write it	writeBlock( buf, qstrlen(buf) );    return *this;}/*!  Writes a string to the stream and returns a reference to the stream.  The string \a s is assumed to be Latin1 encoded independent of the Encoding set  for the QTextStream.*/QTextStream &QTextStream::operator<<( const char* s ){    CHECK_STREAM_PRECOND    char padbuf[48];    uint len = qstrlen( s );			// don't write null terminator    if ( fwidth ) {				// field width set	int padlen = fwidth - len;	fwidth = 0;				// reset width	if ( padlen > 0 ) {	    char *ppad;	    if ( padlen > 46 ) {		// create extra big fill buffer		ppad = new char[padlen];		CHECK_PTR( ppad );	    } else {		ppad = padbuf;	    }	    memset( ppad, (char)fillchar, padlen );	// fill with fillchar	    if ( !(flags() & left) ) {		writeBlock( ppad, padlen );		padlen = 0;	    }	    writeBlock( s, len );	    if ( padlen )		writeBlock( ppad, padlen );	    if ( ppad != padbuf )		// delete extra big fill buf		delete[] ppad;	    return *this;	}    }    writeBlock( s, len );    return *this;}/*!  Writes \a s to the stream and returns a reference to the stream.  The string \a s is assumed to be Latin1 encoded independent of the Encoding set  for the QTextStream.*/QTextStream &QTextStream::operator<<( const QCString & s ){    return operator<<(s.data());}/*!  Writes \a s to the stream and returns a reference to the stream.*/QTextStream &QTextStream::operator<<( const QString& s ){    CHECK_STREAM_PRECOND    uint len = s.length();    QString s1 = s;    if ( fwidth ) {				// field width set	if ( !(flags() & left) ) {	    s1 = s.rightJustify(fwidth, (char)fillchar);	} else {	    s1 = s.leftJustify(fwidth, (char)fillchar);	}	fwidth = 0;				// reset width    }    writeBlock( s1.unicode(), len );    return *this;}/*!  Writes a pointer to the stream and returns a reference to the stream.  The \e ptr is output as an unsigned long hexadecimal integer.*/QTextStream &QTextStream::operator<<( void *ptr ){    int f = flags();    setf( hex, basefield );    setf( showbase );    unsetf( uppercase );    output_int( I_LONG | I_UNSIGNED, (ulong)ptr, FALSE );    flags( f );    return *this;}/*!  \fn int QTextStream::flags() const  Returns the current stream flags. The default value is 0.  The meaning of the flags are:  <ul>    <li> \e skipws - Not currently used - whitespace always skipped    <li> \e left - Numeric fields are left-aligned    <li> \e right - Not currently used (by default numerics are right aligned)    <li> \e internal - Put any padding spaces between +/- and value    <li> \e bin - Output \e and input only in binary    <li> \e oct - Output \e and input only in octal    <li> \e dec - Output \e and input only in decimal    <li> \e hex - Output \e and input only in hexadecimal    <li> \e showbase - Annotate numeric outputs with 0b, 0, or 0x if in		\e bin, \e oct, or \e hex format    <li> \e showpoint - Not currently used    <li> \e uppercase - Use 0B and 0X rather than 0b and 0x    <li> \e showpos - Show + for positive numeric values    <li> \e scientific - Use scientific notation for floating point values    <li> \e fixed - Use fixed-point notation for floating point values  </ul>  Note that unless \e bin, \e oct, \e dec, or \e hex is set, the input base is    octal if the value starts with 0, hexadecimal if it starts with 0x, binary    if the value starts with 0b, and decimal otherwise.  \sa setf(), unsetf()*//*!  \fn int QTextStream::flags( int f )  Sets the stream flags to \e f.  Returns the previous stream flags.  \sa setf(), unsetf(), flags()*//*!  \fn int QTextStream::setf( int bits )  Sets the stream flag bits \e bits.  Returns the previous stream flags.  Equivalent to <code>flags( flags() | bits )</code>.  \sa setf(), unsetf()*//*!  \fn int QTextStream::setf( int bits, int mask )  Sets the stream flag bits \e bits with a bit mask \e mask.  Returns the previous stream flags.  Equivalent to <code>flags( (flags() & ~mask) | (bits & mask) )</code>.  \sa setf(), unsetf()*//*!  \fn int QTextStream::unsetf( int bits )  Clears the stream flag bits \e bits.  Returns the previous stream flags.  Equivalent to <code>flags( flags() & ~mask )</code>.  \sa setf()*//*!  \fn int QTextStream::width() const  Returns the field width. The default value is 0.*//*!  \fn int QTextStream::width( int w )  Sets the field width to \e w. Returns the previous field width.*//*!  \fn int QTextStream::fill() const  Returns the fill character. The default value is ' ' (space).*//*!  \fn int QTextStream::fill( int f )  Sets the fill character to \e f. Returns the previous fill character.*//*!  \fn int QTextStream::precision() const  Returns the precision. The default value is 6.*//*!  \fn int QTextStream::precision( int p )  Sets the precision to \e p. Returns the previous precision setting.*/ /*****************************************************************************  QTextStream manipulators *****************************************************************************/QTextStream &bin( QTextStream &s ){    s.setf(QTS::bin,QTS::basefield);    return s;}QTextStream &oct( QTextStream &s ){    s.setf(QTS::oct,QTS::basefield);    return s;}QTextStream &dec( QTextStream &s ){    s.setf(QTS::dec,QTS::basefield);    return s;}QTextStream &hex( QTextStream &s ){    s.setf(QTS::hex,QTS::basefield);    return s;}QTextStream &endl( QTextStream &s ){    return s << '\n';}QTextStream &flush( QTextStream &s ){    if ( s.device() )	s.device()->flush();    return s;}QTextStream &ws( QTextStream &s ){    s.skipWhiteSpace();    return s;}QTextStream &reset( QTextStream &s ){    s.reset();    return s;}/*!  \class QTextIStream qtextstream.h  \brief A convenience class for input streams.  For simple tasks, code should be simple.  Hence this  class is a shorthand to avoid passing the \e mode argument  to the normal QTextStream constructors.  This makes it easy for example, to write things like this:\code    QString data = "123 456";    int a, b;    QTextIStream(&data) >> a >> b;\endcode  \sa QTextOStream*//*!  \fn QTextIStream::QTextIStream( QString *s )  Constructs a stream to read from string \a s.*//*!  \fn QTextIStream::QTextIStream( QByteArray ba )  Constructs a stream to read from the array \a ba.*//*!  \fn QTextIStream::QTextIStream( FILE *f )  Constructs a stream to read from the file \a f.*//*!  \class QTextOStream qtextstream.h  \brief A convenience class for output streams.  For simple tasks, code should be simple.  Hence this  class is a shorthand to avoid passing the \e mode argument  to the normal QTextStream constructors.  This makes it easy for example, to write things like this:\code    QString result;    QTextOStream(&result) << "pi = " << 3.14;\endcode*//*!  \fn QTextOStream::QTextOStream( QString *s )  Constructs a stream to write to string \a s.*//*!  \fn QTextOStream::QTextOStream( QByteArray ba )  Constructs a stream to write to the array \a ba.*//*!  \fn QTextOStream::QTextOStream( FILE *f )  Constructs a stream to write to the file \a f.*//*!  Sets the encoding of this stream to \a e, where \a e is one of:  <ul>  <li> \c Locale Using local file format (Latin1 if locale is not  set), but autodetecting Unicode(utf16) on input.  <li> \c Unicode Using Unicode(utf16) for input and output. Output  will be written in the order most efficient for the current platform  (i.e. the order used internally in QString).  <li> \c UnicodeUTF8 Using Unicode(utf8) for input and output. If you use it  for input it will autodetect utf16 and use it instead of utf8.  <li> \c Latin1  ISO-8859-1. Will not autodetect utf16.  <li> \c UnicodeNetworkOrder Using network order Unicode(utf16) for  input and output. Useful when reading Unicode data that does not  start with the byte order marker.  <li> \c UnicodeReverse Using reverse network order Unicode(utf16)  for input and output. Useful when reading Unicode data that does not  start with the byte order marker, or writing data that should be  read by buggy Windows applications.  <li> \c RawUnicode Like Unicode, but does not write the byte order  marker, nor does it autodetect the byte order. Only useful when  writing to non-persistent storage used by a single process.  </ul>  \c Locale and all Unicode encodings, except \c RawUnicode, will look at  the first two bytes in a input stream to determine the byte order. The  initial byte order marker will be stripped off before data is read.  Note that this function should be called before any data is read  to/written from the stream.  \sa setCodec()*/void QTextStream::setEncoding( Encoding e ){    if ( d->sourceType == QTextStreamPrivate::String )	return; // QString does not need any encoding    switch ( e ) {    case Unicode:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = TRUE;	break;    case UnicodeUTF8:#ifndef QT_NO_CODECS	mapper = QTextCodec::codecForMib( 106 );	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = TRUE;#else	mapper = 0;	latin1 = TRUE;	doUnicodeHeader = TRUE;#endif	break;    case UnicodeNetworkOrder:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = QChar::networkOrdered();	break;    case UnicodeReverse:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = !QChar::networkOrdered();   //reverse network ordered	break;    case RawUnicode:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = FALSE;	internalOrder = TRUE;	break;    case Locale:	latin1 = TRUE; 				// fallback to Latin 1#ifndef QT_NO_TEXTCODEC	mapper = QTextCodec::codecForLocale();#if defined(_OS_WIN32_)	if ( GetACP() == 1252 )	    mapper = 0;				// Optimized latin1 processing#endif	if ( mapper && mapper->mibEnum() == 4 )#endif	    mapper = 0;				// Optimized latin1 processing	doUnicodeHeader = TRUE; // If it reads as Unicode, accept it	break;    case Latin1:	mapper = 0;	doUnicodeHeader = FALSE;	latin1 = TRUE;	break;    }}#ifndef QT_NO_TEXTCODEC/*!  Sets the codec for this stream to \a codec. Will not try to  autodetect Unicode.  Note that this function should be called before any data is read  to/written from the stream.  \sa setEncoding()*/void QTextStream::setCodec( QTextCodec *codec ){    if ( d->sourceType == QTextStreamPrivate::String )	return; // QString does not need any codec    mapper = codec;    doUnicodeHeader = FALSE;}#endif#endif // QT_NO_TEXTSTREAM

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -