40 #ifndef QT_NO_TEXTSTREAM 49 #if defined(_OS_WIN32_) 158 #if defined(CHECK_STATE) 159 #undef CHECK_STREAM_PRECOND 160 #define CHECK_STREAM_PRECOND if ( !dev ) { \ 161 qWarning( "QTextStream: No device" ); \ 164 #define CHECK_STREAM_PRECOND 168 #define I_SHORT 0x0010 170 #define I_LONG 0x0030 171 #define I_TYPE_MASK 0x00f0 173 #define I_BASE_2 QTS::bin 174 #define I_BASE_8 QTS::oct 175 #define I_BASE_10 QTS::dec 176 #define I_BASE_16 QTS::hex 177 #define I_BASE_MASK (QTS::bin | QTS::oct | QTS::dec | QTS::hex) 179 #define I_SIGNED 0x0100 180 #define I_UNSIGNED 0x0200 181 #define I_SIGN_MASK 0x0f00 196 #ifndef QT_NO_TEXTCODEC 215 do { c = ts_getc(); }
while ( c != QEOF && ts_isspace(c) );
223 fstrm = owndev =
FALSE;
226 doUnicodeHeader =
TRUE;
238 setEncoding( Locale );
250 setEncoding( Locale );
268 int readBlock(
char *
p,
uint len );
269 int writeBlock(
const char *p,
uint len );
272 int ungetch(
int ch );
295 #if defined(CHECK_STATE) 296 qWarning(
"QStringBuffer::open: No string" );
301 #if defined(CHECK_STATE) 302 qWarning(
"QStringBuffer::open: Buffer already open" );
344 #if defined(CHECK_STATE) 346 qWarning(
"QStringBuffer::at: Buffer is not open" );
351 #if defined(CHECK_RANGE) 352 qWarning(
"QStringBuffer::at: Index %d out of range", pos );
363 #if defined(CHECK_STATE) 366 qWarning(
"QStringBuffer::readBlock: Buffer not open" );
369 if ( !isReadable() ) {
370 qWarning(
"QStringBuffer::readBlock: Read operation not permitted" );
383 memcpy( p, ((
const char*)(
s->unicode()))+ioIndex, len );
390 #if defined(CHECK_NULL) 391 if ( p == 0 && len != 0 )
392 qWarning(
"QStringBuffer::writeBlock: Null pointer error" );
394 #if defined(CHECK_STATE) 396 qWarning(
"QStringBuffer::writeBlock: Buffer not open" );
399 if ( !isWritable() ) {
400 qWarning(
"QStringBuffer::writeBlock: Write operation not permitted" );
404 qWarning(
"QStringBuffer::writeBlock: non-even index - non Unicode" );
408 qWarning(
"QStringBuffer::writeBlock: non-even length - non Unicode" );
419 #if defined(CHECK_STATE) 421 qWarning(
"QStringBuffer::getch: Buffer not open" );
424 if ( !isReadable() ) {
425 qWarning(
"QStringBuffer::getch: Read operation not permitted" );
433 return *((
char*)
s->unicode() + ioIndex++);
439 if ( writeBlock(&c,1) < 0 )
447 #if defined(CHECK_STATE) 449 qWarning(
"QStringBuffer::ungetch: Buffer not open" );
452 if ( !isReadable() ) {
453 qWarning(
"QStringBuffer::ungetch: Read operation not permitted" );
502 setEncoding(RawUnicode);
519 setEncoding(RawUnicode);
554 ((
QBuffer *)dev)->open( mode );
556 setEncoding( Locale );
576 setEncoding( Locale );
579 fstrm = owndev =
TRUE;
602 ts_ungetc( eat_ws() );
627 if (
d &&
d->ungetcBuf.length() ) {
629 buf[rnum] =
d->ungetcBuf.constref(rnum);
632 d->ungetcBuf =
d->ungetcBuf.mid( rnum );
641 if ( doUnicodeHeader ) {
642 doUnicodeHeader =
FALSE;
643 int c1 = dev->getch();
646 int c2 = dev->getch();
647 if ( c1 == 0xfe && c2 == 0xff ) {
651 }
else if ( c1 == 0xff && c2 == 0xfe ) {
671 #ifndef QT_NO_TEXTCODEC 673 bool shortRead =
FALSE;
675 d->decoder = mapper->makeDecoder();
676 while( rnum < len ) {
678 bool readBlock = !( len == 1+rnum );
689 uint rlen = len - rnum;
690 char *cbuf =
new char[ rlen ];
691 if ( ungetHack != EOF ) {
692 rlen = 1+dev->readBlock( cbuf+1, rlen-1 );
693 cbuf[0] = (char)ungetHack;
696 rlen = dev->readBlock( cbuf, rlen );
698 s +=
d->decoder->toUnicode( cbuf, rlen );
707 if ( ungetHack == EOF ) {
719 s +=
d->decoder->toUnicode( &b, 1 );
720 if ( s.
length() > lengthBefore )
724 while( rnum < len && i < s.
length() )
728 d->ungetcBuf.append( s.
mid( i ) );
735 if ( len == 1+rnum ) {
738 int c = (ungetHack == EOF) ? dev->getch() : ungetHack;
740 buf[rnum++] = (char)c;
742 if ( ungetHack != EOF ) {
743 buf[rnum++] = (char)ungetHack;
746 char *cbuf =
new char[len - rnum];
747 while ( !dev->atEnd() && rnum < len ) {
748 uint rlen = len - rnum;
749 rlen = dev->readBlock( cbuf, rlen );
752 buf[rnum++] = cbuf[i++];
757 if ( len == 1+rnum ) {
758 int c1 = (ungetHack == EOF) ? dev->getch() : ungetHack;
761 int c2 = dev->getch();
764 if ( isNetworkOrder() )
765 buf[rnum++] =
QChar( c2, c1 );
767 buf[rnum++] =
QChar( c1, c2 );
769 char *cbuf =
new char[ 2*( len - rnum ) ];
770 while ( !dev->atEnd() && rnum < len ) {
771 uint rlen = 2 * ( len-rnum );
772 if ( ungetHack != EOF ) {
773 rlen = 1+dev->readBlock( cbuf+1, rlen-1 );
774 cbuf[0] = (char)ungetHack;
777 rlen = dev->readBlock( cbuf, rlen );
783 if ( (rlen & 1) == 1 )
785 dev->ungetch( cbuf[--rlen] );
787 if ( isNetworkOrder() ) {
789 buf[rnum++] =
QChar( cbuf[i+1], cbuf[i] );
794 buf[rnum++] =
QChar( cbuf[i], cbuf[i+1] );
811 #ifndef QT_NO_TEXTCODEC 815 QCString block = mapper->fromUnicode( s, len );
816 dev->writeBlock( block, len );
823 dev->putch( c.
cell() );
825 if ( doUnicodeHeader ) {
826 doUnicodeHeader =
FALSE;
829 if ( internalOrder ) {
830 dev->writeBlock( (
char*)&c,
sizeof(
QChar) );
831 }
else if ( isNetworkOrder() ) {
833 dev->putch(c.
cell());
835 dev->putch(c.
cell());
864 d->ungetcBuf.prepend( c );
885 dev->readBlock( s, len );
907 if ( doUnicodeHeader ) {
908 doUnicodeHeader =
FALSE;
909 if ( !mapper && !latin1 )
913 if ( !mapper && latin1 ) {
914 dev->writeBlock( p, len );
915 }
else if ( !mapper && internalOrder ) {
917 for (
uint i=0; i<len; i++)
919 dev->writeBlock( (
char*)u, len*(
int)
sizeof(
QChar) );
922 for (
uint i=0; i<len; i++)
923 ts_putc( (
uchar)p[i] );
930 if ( !mapper && !latin1 && internalOrder ) {
931 if ( doUnicodeHeader ) {
932 doUnicodeHeader =
FALSE;
935 dev->writeBlock( (
char*)p, (
int)
sizeof(
QChar)*len );
937 for (
uint i=0; i<len; i++)
1052 QChar ch = eat_ws();
1054 while ( dv == 0 || dv == 1 ) {
1055 val = ( val << 1 ) + dv;
1067 QChar ch = eat_ws();
1069 while ( dv >= 0 && dv <= 7 ) {
1070 val = ( val << 3 ) + dv;
1074 if ( dv == 8 || dv == 9 ) {
1075 while ( ts_isdigit(ch) )
1086 QChar ch = eat_ws();
1088 while ( ts_isdigit(ch) ) {
1089 val = val * 10 + dv;
1101 QChar ch = eat_ws();
1103 while ( isxdigit(c) ) {
1105 if ( ts_isdigit(c) )
1108 val += 10 + tolower(c) -
'a';
1121 switch ( flags() & basefield ) {
1123 val = (long)input_bin();
1126 val = (long)input_oct();
1133 if ( !(c ==
'-' || c ==
'+') )
1136 ulong v = input_dec();
1139 val = -((long)v) - 1;
1144 val = (long)input_dec();
1149 val = (long)input_hex();
1156 if ( tolower(c) ==
'x' )
1157 val = (long)input_hex();
1158 else if ( tolower(c) ==
'b' )
1159 val = (
long)input_bin();
1162 if ( c >=
'0' && c <=
'7' ) {
1163 val = (long)input_oct();
1168 }
else if ( ts_isdigit(ch) ) {
1170 val = (long)input_dec();
1171 }
else if ( c ==
'-' || c ==
'+' ) {
1172 ulong v = input_dec();
1176 val = -((long)v) - 1;
1197 const int Mantissa = 2;
1199 const int Abscissa = 4;
1200 const int ExpMark = 5;
1201 const int ExpSign = 6;
1202 const int Exponent = 7;
1205 const int InputSign = 1;
1206 const int InputDigit = 2;
1207 const int InputDot = 3;
1208 const int InputExp = 4;
1210 static uchar table[8][5] = {
1212 { 0, Sign, Mantissa, Dot, 0, },
1213 { 0, 0, Mantissa, Dot, 0, },
1214 { Done, Done, Mantissa, Dot, ExpMark,},
1215 { 0, 0, Abscissa, 0, 0, },
1216 { Done, Done, Abscissa, Done, ExpMark,},
1217 { 0, ExpSign, Exponent, 0, 0, },
1218 { 0, 0, Exponent, 0, 0, },
1219 { Done, Done, Exponent, Done, Done }
1236 case '0':
case '1':
case '2':
case '3':
case '4':
1237 case '5':
case '6':
case '7':
case '8':
case '9':
1252 state = table[state][
input];
1254 if ( state == 0 || state == Done || i > 250 ) {
1256 do { c = ts_getc(); }
while ( c != QEOF && ts_isdigit(c) );
1262 return strtod( buf, &end );
1269 #if !defined(_CC_EGG_) 1283 i = (
signed short)input_int();
1296 i = (
unsigned short)input_int();
1309 i = (
signed int)input_int();
1322 i = (
unsigned int)input_int();
1335 i = (
signed long)input_int();
1348 i = (
unsigned long)input_int();
1361 f = (
float)input_double();
1390 while ( c != QEOF ) {
1391 if ( ts_isspace(c) || maxlen-- == 0 ) {
1413 while ( c != QEOF ) {
1414 if ( ts_isspace(c) ) {
1432 const int buflen = 256;
1433 char buffer[buflen];
1438 while ( c != QEOF ) {
1439 if ( ts_isspace(c) ) {
1443 if ( i >= buflen-1 ) {
1446 memcpy( dynbuf->rawData(),
s, i );
1447 }
else if ( i >= (
int)dynbuf->size()-1 ) {
1448 dynbuf->resize( dynbuf->size()*2 );
1450 s = dynbuf->rawData();
1477 #if defined(CHECK_STATE) 1479 qWarning(
"QTextStream::readLine: No device" );
1484 const int buf_size = 256;
1489 if ( c[pos] == QEOF )
1492 while ( c[pos] != QEOF && c[pos] !=
'\n' ) {
1494 if ( pos >= buf_size ) {
1503 if ( len && result[len-1] ==
'\r' )
1518 #if defined(CHECK_STATE) 1520 qWarning(
"QTextStream::read: No device" );
1525 const uint bufsize = 512;
1528 bool skipped_cr =
FALSE;
1531 num = ts_getbuf(buf,bufsize);
1534 for ( i=0; i<
num; i++ ) {
1535 if ( buf[i] ==
'\r' ) {
1541 result +=
QString( &buf[start], i-start );
1547 if ( buf[i] !=
'\n' ) {
1556 result +=
QString( &buf[start], i-start );
1557 if ( num != bufsize )
1588 unsigned char uc = (
unsigned char) c;
1595 static char hexdigits_lower[] =
"0123456789abcdef";
1596 static char hexdigits_upper[] =
"0123456789ABCDEF";
1608 case I_INT: len=
sizeof(
int)*8;
break;
1609 case I_LONG: len=32;
break;
1615 *--p = (char)(n&1) +
'0';
1620 if ( flags() & showbase ) {
1621 *--p = (flags() & uppercase) ?
'B' :
'b';
1630 *--p = (char)(n&7) +
'0';
1633 if ( flags() & showbase )
1640 hexdigits = (flags() & uppercase) ?
1641 hexdigits_upper : hexdigits_lower;
1643 *--p = hexdigits[(
int)n&0xf];
1646 if ( flags() & showbase ) {
1647 *--p = (flags() & uppercase) ?
'X' :
'x';
1658 *--p = ((
int)(n%10)) +
'0';
1663 else if ( flags() & showpos )
1665 if ( (flags() &
internal) && fwidth && !ts_isdigit(*p) ) {
1669 return *
this << (
const char*)p;
1673 if ( !(flags() &
left) ) {
1675 int padlen = fwidth - len;
1676 if ( padlen <= 0 ) {
1677 writeBlock( p, len );
1678 }
else if ( padlen < (
int)(p-buf) ) {
1679 memset( p-padlen, (
char)fillchar, padlen );
1680 writeBlock( p-padlen, padlen+len );
1683 *
this << (
const char*)p;
1686 *
this << (
const char*)p;
1767 return *
this << (double)f;
1781 if ( (flags()&floatfield) == fixed )
1783 else if ( (flags()&floatfield) == scientific )
1784 f_char = (flags() & uppercase) ?
'E' :
'e';
1786 f_char = (flags() & uppercase) ?
'G' :
'g';
1794 *fs++ = prec / 10 +
'0';
1795 *fs++ = prec % 10 +
'0';
1802 sprintf( buf, format, f );
1804 *
this << (
const char*)buf;
1806 writeBlock( buf,
qstrlen(buf) );
1824 int padlen = fwidth - len;
1828 if ( padlen > 46 ) {
1829 ppad =
new char[padlen];
1834 memset( ppad, (
char)fillchar, padlen );
1835 if ( !(flags() &
left) ) {
1836 writeBlock( ppad, padlen );
1839 writeBlock( s, len );
1841 writeBlock( ppad, padlen );
1842 if ( ppad != padbuf )
1847 writeBlock( s, len );
1873 if ( !(flags() &
left) ) {
1880 writeBlock( s1.
unicode(), len );
1894 setf(
hex, basefield );
1896 unsetf( uppercase );
2163 doUnicodeHeader =
TRUE;
2164 internalOrder =
TRUE;
2167 #ifndef QT_NO_CODECS 2170 doUnicodeHeader =
TRUE;
2171 internalOrder =
TRUE;
2175 doUnicodeHeader =
TRUE;
2178 case UnicodeNetworkOrder:
2181 doUnicodeHeader =
TRUE;
2184 case UnicodeReverse:
2187 doUnicodeHeader =
TRUE;
2193 doUnicodeHeader =
FALSE;
2194 internalOrder =
TRUE;
2198 #ifndef QT_NO_TEXTCODEC 2200 #if defined(_OS_WIN32_) 2201 if ( GetACP() == 1252 )
2204 if ( mapper && mapper->mibEnum() == 4 )
2207 doUnicodeHeader =
TRUE;
2211 doUnicodeHeader =
FALSE;
2218 #ifndef QT_NO_TEXTCODEC 2233 doUnicodeHeader =
FALSE;
2237 #endif // QT_NO_TEXTSTREAM static QTextCodec * codecForLocale()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
QTextStream & operator>>(QChar &)
const QChar * unicode() const
QString leftJustify(uint width, QChar fill=' ', bool trunc=FALSE) const
void setCodec(QTextCodec *)
QString rightJustify(uint width, QChar fill=' ', bool trunc=FALSE) const
QTextStream & writeBlock(const char *p, uint len)
QString mid(uint index, uint len=0xffffffff) const
uint ts_getbuf(QChar *, uint)
void setEncoding(Encoding)
int open(const char *, int)
Opens a file descriptor.
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
#define CHECK_STREAM_PRECOND
static constexpr double fs
The QBuffer class is an I/O device that operates on a QByteArray.
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
void qWarning(const char *msg,...)
QTextStream & hex(QTextStream &s)
static QString fromLatin1(const char *, int len=-1)
The QChar class provides a light-weight Unicode character.
QTextStream & oct(QTextStream &s)
QChar constref(uint i) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
QTextStream & writeRawBytes(const char *, uint len)
int close(int)
Closes the file descriptor fd.
QTextStream & reset(QTextStream &s)
Q_EXPORT uint qstrlen(const char *str)
static bool networkOrdered()
QTextStream & ws(QTextStream &s)
static QTextCodec * codecForMib(int mib)
QTextStream & flush(QTextStream &s)
const char * data() const
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
QT_STATIC_CONST QChar byteOrderMark
QTextStream & operator<<(QChar)
static const int adjustfield
QTextStream & dec(QTextStream &s)
The QFile class is an I/O device that operates on files.
static const int floatfield
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
QStringBuffer(QString *str)
int writeBlock(const char *p, uint len)
QTextStream & readRawBytes(char *, uint len)
void setDevice(QIODevice *)
static const int basefield
QTextStream & bin(QTextStream &s)
int readBlock(char *p, uint len)
QIODevice * device() const
Provides conversion between text encodings.
QTextStream & output_int(int, ulong, bool)
The QIODevice class is the base class of I/O devices.
QCString & replace(uint index, uint len, const char *s)
QTextStream & endl(QTextStream &s)