[Interest] QFile::size() and QTextStream::pos()
Igor Mironchik
igor.mironchik at gmail.com
Thu Oct 29 23:43:22 CET 2015
On 30.10.2015 00:05, Thiago Macieira wrote:
> On Thursday 29 October 2015 21:49:40 Igor Mironchik wrote:
>> On 29.10.2015 06:51, Thiago Macieira wrote:
>>> On Thursday 29 October 2015 05:51:36 Igor Mironchik wrote:
>>>> P.S. Why QTextStream doesn't have something like get(), peek(), unget(),
>>>> putback()?
>>> Explain what you would want those functions to do.
>> The same like in std::istream, for example...
> The iostreams are, in my opinion, the worst part of the Standard Library. I
> don't consider them a good implementation, even if they have good ideas (<<
> and >>).
>
> istream QTextStream
> get read and readLine
Agree, read(), readLine(), and overloaded >> are completely cover get()
usage.
> the overload with a delimiter: there was a discussion about replacing
> readLine with that, but it hasn't happened
> peek <missing, no one has ever asked for it>
It can be useful in some cases, for example, when you implementing some
sort of parsers where very often you need to know what next character is
but don't really need to seek stream's position.
> unget seek(pos() - 1) (slow! can't be avoided)
Slow? This is not the main problem. The main problem is that that seek()
and pos() uses device's units. But I need to seek() one character back,
and what then just -1, or -2, or something else? unget() can't be
implemented with methods of QTextStream.
> putback <missing, really bad idea!>
>
> putback does the same as unget, plus adds a character that wasn't necessarily
> the last character that was read. Plus, the function has implementation-
> defined behaviour.
Agree. Without putback() I can live and be happy. And I really can't
imagine why I need to putback() something different from that that was
really read.
But peek() and unget() are very useful.
In my task I did parsing with just three functions like
skipWhiteSpace( QTextStream & stream, QList< QChar > & returned ),
skipComment( QTextStream & stream, QList< QChar > & returned ),
readWord( QTextStream & stream, QList< QChar > & returned )
where the main idea is that they read from "returned" if its not empty
and only then from stream, and they can prepend() to the "returned" what
equal to unget(). Such approach solved the problem with pos() and seek()
and parsing effectiveness doesn't depends on buffer implementation of
QTextStream...
--
Best Regards,
Igor Mironchik.
More information about the Interest
mailing list