[Scummvm-devel] Questions about the new readLine functions

Ori Avtalion ori at avtalion.name
Sat Sep 6 19:55:58 CEST 2008


On 09/06/2008 06:46 PM, Max Horn wrote:
>
> Am 06.09.2008 um 16:47 schrieb Ori Avtalion:
>
>> Hi,
>>
>> While adjusting my code to the new readLine changes, I noticed some
>> inconsistencies and problems:
>>
>> 1) readLine_NEW retains the newline in the returned buffer, while
>> readLine drops the newline from the returned String.
>>
>> What's the reasoning behind this difference? Isn't the string-returning
>> readLine supposed to be nothing but a helpful wrapper around
>> readLine_NEW?
>>
>> 2) There's no efficient way (i.e. by not scanning the whole buffer) of
>> dropping the newline from the result of readLine_NEW. Seems like the
>> only way to drop the newline is to use Common::String -- why should that
>> be mandatory? How about adding a retainNewLine boolean (defaults to
>> 'true') to readLine_NEW?
>
> No. Have you read the doxygen comment for the funcs? Esp. for
> readLine_OLD vs. readLine_NEW?

YUP, and they don't give a good reason to the inclusion or exclusion of
newlines.

> 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?

This breaks in the case where I'm reading the last line of the file,
which doesn't end with a newline.

>
> 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.

-Ori




More information about the Scummvm-devel mailing list