[Scummvm-devel] Questions about the new readLine functions

Willem Jan Palenstijn wjp at usecode.org
Sat Sep 6 20:06:21 CEST 2008


On Sat, Sep 06, 2008 at 08:55:58PM +0300, Ori Avtalion wrote:
> On 09/06/2008 06:46 PM, Max Horn wrote:
> > In short:
> >
> > The "String readLine()" method just gives you a complete line from the
> > input file. No input buffer limit. Since you normally are not interested
> > in the trailing newline, it is removed.
> >
> > The method readLine_NEW (which eventually will be renamed to just
> > "readline", too), however, is used on a fixed size buffer. If a line is
> > longer than that buffer, it has to signal the caller that this is the
> > case. The caller can determine whether the line was completely read or
> > not by looking at the last char and testing whether it is a newline.
> 
> So the 'signal' to whether or not the read succeeded is the last
> character of the string? Shouldn't I use ioFailed() for that?

No, it signals whether or not it completed reading a line. The problem it
handles is that the buffer may not be large enough for a full line, not
IO errors.

> > And *of course* you can manipulate strings without using Common::String,
> > C coder have been doing that for decades ;). Just overwrite the \n by a
> > 0 char, done.
> 
> But that's not as efficient as it could be, because I don't know the
> length of the string, and thus, the position of the newline.
> readLine_NEW does. Out of practical reasons, I'd want it to do the hard
> work for me. That may be ugly design, though.

That's true, but sounds like premature optimization. This is, IMO,
unlikely to be a bottleneck as the string has been read entirely from
file before, and will probably be scanned again at some later point too.

(Note that the String-returning readLine() does remove it efficiently.)


-Willem Jan




More information about the Scummvm-devel mailing list