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

📄 q3textstream.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	    if ( padlen <= 0 ) {		// no padding required		writeBlock( p, len );	    } else if ( padlen < (int)(p-buf) ) { // speeds up padding		memset( p-padlen, (char)fillchar, padlen );		writeBlock( p-padlen, padlen+len );	    }	    else				// standard padding		*this << (const char*)p;	}	else	    *this << (const char*)p;	fwidth = 0;				// reset field width    }    else {	writeBlock( p, qstrlen(p) );    }    return *this;}/*!    \overload    \since 4.2    Writes a \c short integer \a i to the stream and returns a    reference to the stream.*/Q3TextStream &Q3TextStream::operator<<( signed short i ){    return output_int( I_SHORT | I_SIGNED, i, i < 0 );}/*!    \overload    \since 4.2    Writes an \c unsigned \c short integer \a i to the stream and    returns a reference to the stream.*/Q3TextStream &Q3TextStream::operator<<( unsigned short i ){    return output_int( I_SHORT | I_UNSIGNED, i, FALSE );}/*!    \overload    \since 4.2    Writes an \c int \a i to the stream and returns a reference to the    stream.*/Q3TextStream &Q3TextStream::operator<<( signed int i ){    return output_int( I_INT | I_SIGNED, i, i < 0 );}/*!    \overload    \since 4.2    Writes an \c unsigned \c int \a i to the stream and returns a    reference to the stream.*/Q3TextStream &Q3TextStream::operator<<( unsigned int i ){    return output_int( I_INT | I_UNSIGNED, i, FALSE );}/*!    \overload    \since 4.2    Writes a \c long \c int \a i to the stream and returns a reference    to the stream.*/Q3TextStream &Q3TextStream::operator<<( signed long i ){    return output_int( I_LONG | I_SIGNED, i, i < 0 );}/*!    \overload    \since 4.2    Writes an \c unsigned \c long \c int \a i to the stream and    returns a reference to the stream.*/Q3TextStream &Q3TextStream::operator<<( unsigned long i ){    return output_int( I_LONG | I_UNSIGNED, i, FALSE );}/*!    \overload    \since 4.2    Writes a \c float \a f to the stream and returns a reference to    the stream.*/Q3TextStream &Q3TextStream::operator<<( float f ){    return *this << (double)f;}/*!    \overload    \since 4.2    Writes a \c double \a f to the stream and returns a reference to    the stream.*/Q3TextStream &Q3TextStream::operator<<( double f ){    CHECK_STREAM_PRECOND    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';    QString num;    num.sprintf(format, f);			// convert to text    if ( fwidth )				// padding	*this << num.latin1();    else					// just write it	writeBlock(num.latin1(), num.length());    return *this;}/*!    \overload    \since 4.2    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 Q3TextStream.*/Q3TextStream &Q3TextStream::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];		Q_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;}/*!    \overload    \since 4.2    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 Q3TextStream.*/Q3TextStream &Q3TextStream::operator<<( const Q3CString & s ){    return operator<<(s.data());}/*!    \overload    \since 4.2    Writes \a s to the stream and returns a reference to the stream.*/Q3TextStream &Q3TextStream::operator<<( const QString& s ){    if ( !mapper && latin1 )	return operator<<(s.latin1());    CHECK_STREAM_PRECOND    QString s1 = s;    if ( fwidth ) {				// field width set	if ( !(flags() & left) ) {	    s1 = s.rightJustify(fwidth, QLatin1Char((char)fillchar));	} else {	    s1 = s.leftJustify(fwidth, QLatin1Char((char)fillchar));	}	fwidth = 0;				// reset width    }    writeBlock( s1.unicode(), s1.length() );    return *this;}/*!    \overload    \since 4.2    Writes a pointer to the stream and returns a reference to the    stream.    The \a ptr is output as an unsigned long hexadecimal integer.*/Q3TextStream &Q3TextStream::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 Q3TextStream::flags() const    \since 4.2    Returns the current stream flags. The default value is 0.    \table    \header \i Flag \i Meaning    \row \i \c skipws \i Not currently used; whitespace always skipped    \row \i \c left \i Numeric fields are left-aligned    \row \i \c right	 \i Not currently used (by default, numerics are right-aligned)    \row \i \c internal \i Puts any padding spaces between +/- and value    \row \i \c bin \i Output \e and input only in binary    \row \i \c oct \i Output \e and input only in octal    \row \i \c dec \i Output \e and input only in decimal    \row \i \c hex \i Output \e and input only in hexadecimal    \row \i \c showbase	 \i Annotates numeric outputs with 0b, 0, or 0x if in \c bin,	 \c oct, or \c hex format    \row \i \c showpoint \i Not currently used    \row \i \c uppercase \i Uses 0B and 0X rather than 0b and 0x    \row \i \c showpos \i Shows + for positive numeric values    \row \i \c scientific \i Uses scientific notation for floating point values    \row \i \c fixed \i Uses fixed-point notation for floating point values    \endtable    Note that unless \c bin, \c oct, \c dec, or \c hex is set, the    input base is octal if the value starts with 0, hexadecimal if it    starts with 0x, binary if it starts with 0b, and decimal    otherwise.    \sa setf(), unsetf()*//*!    \fn int Q3TextStream::flags( int f )    \overload    Sets the stream flags to \a f. Returns the previous stream flags.    \sa setf(), unsetf(), flags()*//*!    \fn int Q3TextStream::setf( int bits )    \since 4.2    Sets the stream flag bits \a bits. Returns the previous stream    flags.    Equivalent to \c{flags( flags() | bits )}.    \sa unsetf()*//*!    \fn int Q3TextStream::setf( int bits, int mask )    \overload    Sets the stream flag bits \a bits with a bit mask \a mask. Returns    the previous stream flags.    Equivalent to \c{flags( (flags() & ~mask) | (bits & mask) )}.    \sa setf(), unsetf()*//*!    \fn int Q3TextStream::unsetf( int bits )    \since 4.2    Clears the stream flag bits \a bits. Returns the previous stream    flags.    Equivalent to \c{flags( flags() & ~mask )}.    \sa setf()*//*!    \fn int Q3TextStream::width() const    \since 4.2    Returns the field width. The default value is 0.*//*!    \fn int Q3TextStream::width( int w )    \overload    Sets the field width to \a w. Returns the previous field width.*//*!    \fn int Q3TextStream::fill() const    \since 4.2    Returns the fill character. The default value is ' ' (space).*//*!    \fn int Q3TextStream::fill( int f )    \overload    Sets the fill character to \a f. Returns the previous fill character.*//*!    \fn int Q3TextStream::precision() const    \since 4.2    Returns the precision. The default value is 6.*//*!    \fn int Q3TextStream::precision( int p )    \overload    Sets the precision to \a p. Returns the previous precision setting.*/Q3TextStream &bin( Q3TextStream &s ){    s.setf(Q3TextStream::bin,Q3TextStream::basefield);    return s;}Q3TextStream &oct( Q3TextStream &s ){    s.setf(Q3TextStream::oct,Q3TextStream::basefield);    return s;}Q3TextStream &dec( Q3TextStream &s ){    s.setf(Q3TextStream::dec,Q3TextStream::basefield);    return s;}Q3TextStream &hex( Q3TextStream &s ){    s.setf(Q3TextStream::hex,Q3TextStream::basefield);    return s;}Q3TextStream &endl( Q3TextStream &s ){    return s << '\n';}Q3TextStream &flush( Q3TextStream &s ){    return s;}Q3TextStream &ws( Q3TextStream &s ){    s.skipWhiteSpace();    return s;}Q3TextStream &reset( Q3TextStream &s ){    s.reset();    return s;}/*!  \since 4.2  Sets the encoding of this stream to \a e, where \a e is one of the  following values:  \table  \header \i Encoding \i Meaning  \row \i Locale       \i Uses local file format (Latin1 if locale is not set), but       autodetecting Unicode(utf16) on input.  \row \i Unicode       \i Uses 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).  \row \i UnicodeUTF8       \i Using Unicode(utf8) for input and output. If you use it for       input it will autodetect utf16 and use it instead of utf8.  \row \i Latin1       \i ISO-8859-1. Will not autodetect utf16.  \row \i UnicodeNetworkOrder       \i Uses network order Unicode(utf16) for input and output.       Useful when reading Unicode data that does not start with the       byte order marker.  \row \i UnicodeReverse       \i Uses reverse network order Unicode(utf16) for input and       output. Useful when reading Unicode data that does not start       with the byte order marker or when writing data that should be       read by buggy Windows applications.  \row \i RawUnicode       \i Like Unicode, but does not write the byte order marker nor       does it auto-detect the byte order. Useful only when writing to       non-persistent storage used by a single process.  \endtable  \c Locale and all Unicode encodings, except \c RawUnicode, will look  at the first two bytes in an 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  or written from the stream.  \sa setCodec()*/void Q3TextStream::setEncoding( Encoding e ){    ::resetCodecConverterState(&mapperReadState);    ::resetCodecConverterState(&mapperWriteState);    if ( d->sourceType == Q3TextStreamPrivate::String )	return;    switch ( e ) {    case Unicode:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = TRUE;	networkOrder = QChar::networkOrdered();	break;    case UnicodeUTF8:#ifndef QT_NO_TEXTCODEC	mapper = QTextCodec::codecForMib( 106 );        mapperWriteState.flags |= QTextCodec::IgnoreHeader;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = TRUE;	networkOrder = QChar::networkOrdered();#else	mapper = 0;	latin1 = TRUE;	doUnicodeHeader = TRUE;#endif	break;    case UnicodeNetworkOrder:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = QChar::networkOrdered();	networkOrder = TRUE;	break;    case UnicodeReverse:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = TRUE;	internalOrder = !QChar::networkOrdered();	networkOrder = FALSE;	break;    case RawUnicode:	mapper = 0;	latin1 = FALSE;	doUnicodeHeader = FALSE;	internalOrder = TRUE;	networkOrder = QChar::networkOrdered();	break;    case Locale:	latin1 = TRUE; // fallback to Latin-1#ifndef QT_NO_TEXTCODEC	mapper = QTextCodec::codecForLocale();        mapperReadState.flags |= QTextCodec::IgnoreHeader;        mapperWriteState.flags |= QTextCodec::IgnoreHeader;	// optimized Latin-1 processing#if defined(Q_OS_WIN32)	if ( GetACP() == 1252 )	    mapper = 0;#endif	if ( mapper && mapper->mibEnum() == 4 )#endif	    mapper = 0;	doUnicodeHeader = TRUE; // If it reads as Unicode, accept it	break;    case Latin1:	mapper = 0;	doUnicodeHeader = FALSE;	latin1 = TRUE;	break;    }}#ifndef QT_NO_TEXTCODEC/*!    \since 4.2    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(), codec()*/void Q3TextStream::setCodec( QTextCodec *codec ){    if ( d->sourceType == Q3TextStreamPrivate::String )	return; // QString does not need any codec    mapper = codec;    latin1 = ( codec->mibEnum() == 4 );    if ( latin1 )	mapper = 0;    doUnicodeHeader = FALSE;}/*!  Returns the codec actually used for this stream.  \since 4.2  If Unicode is automatically detected in input, a codec with \link  QTextCodec::name() name() \endlink "ISO-10646-UCS-2" is returned.  \sa setCodec()*/QTextCodec *Q3TextStream::codec(){    if ( mapper ) {	return mapper;    } else {	// 4 is "ISO 8859-1", 1000 is "ISO-10646-UCS-2"	return QTextCodec::codecForMib( latin1 ? 4 : 1000 );    }}#endif#endif // QT_NO_TEXTSTREAM

⌨️ 快捷键说明

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