[Scummvm-devel] Questions about the new readLine functions

Max Horn max at quendi.de
Sat Sep 6 17:46:31 CEST 2008


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?

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.

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.


Bye,
Max





More information about the Scummvm-devel mailing list