[Interest] QTextStream, QIODevice::Text and line endings convertation
Igor Mironchik
igor.mironchik at gmail.com
Tue Nov 17 21:46:49 CET 2015
Hi,
Here is modified source:
#include <QCoreApplication>
#include <QTextStream>
#include <QDebug>
#include <QBuffer>
static const QChar c_n = QLatin1Char( '\n' );
QString readWord( QTextStream & stream )
{
QChar ch;
QString res;
while( !stream.atEnd() )
{
stream >> ch;
if( ch == c_n )
break;
else
res.append( ch );
}
return res;
}
int main( int argc, char ** argv )
{
QCoreApplication app( argc, argv );
QString data = QLatin1String( "/*** Program Name ***/\r\n"
"TEST PROGRAM TEST_00;\r\n"
"BEGIN\r\n"
"LOGIC\r\n"
"NAME :\r"
"ACTUAL_NAME\r\n"
"OPTION ENABLE : " );
QByteArray array = data.toLatin1();
QBuffer buffer( &array );
buffer.open( QIODevice::ReadOnly | QIODevice::Text );
QTextStream stream( &buffer );
while( !stream.atEnd() )
{
qDebug() << readWord( stream );
}
return 0;
}
And output is:
"/*** Program Name ***/"
"TEST PROGRAM TEST_00;"
"BEGIN"
"LOGIC"
"NAME :ACTUAL_NAME"
"OPTION ENABLE : "
Look here "NAME :ACTUAL_NAME" '\r' wasn't converted to '\n'...
Looks like a bug
On 17.11.2015 23:24, Thiago Macieira wrote:
> On Tuesday 17 November 2015 23:17:14 Igor Mironchik wrote:
>> Line endings doesn't convert to \n as should be. On Windows with MSVC
>> 2013 if read that data from file then "NAME :\r" even doesn't recognize
>> as line ending at all...
> Line ending conversion only applies when read from a QIODevice. It assumes
> you've already done the conversion by the time you got the data into a
> QString.
>
--
Best Regards,
Igor Mironchik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151117/7336d0ef/attachment.html>
More information about the Interest
mailing list