[Interest] QFile::size() and QTextStream::pos()

Thiago Macieira thiago.macieira at intel.com
Fri Oct 30 00:08:38 CET 2015


On Friday 30 October 2015 01:43:22 Igor Mironchik wrote:
> > 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.

By the way, peek() and unget() are complementary. If you have one, you won't 
need the other.

For various reasons, unget/unread is difficult to implement. The most 
important one is what happens if your last read operation crossed a buffer 
chunk boundary? That means we don't have the previous character anymore to be 
unread and the device may not be seekable at all (think of QTextStream on 
stdin).

Peeking is easier to implement. It will suffer from the same problem (peeking 
past a buffer boundary), but in most cases, reading the next 16kB might be 
enough.

I will accept a contribution adding QTextStream::peek().
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list