Hello!

Gilles Detillieux wrote:

[skipped]

> > int
> > String::readLine(FILE *in)
> > {
> >     Length = 0;
> >     allocate_fix_space(2048);
> >
> >     while (fgets(Data + Length, Allocated - Length, in))
> >     {
> >       Length += strlen(Data + Length);
> >       if (Length == 0)
> >           continue;
> >       if (Data[Length - 1] == '\n')
> >       {
> >           //
> >           // A full line has been read.  Return it.
> >           //
> >           chop('\n');
> >           return 1;
> 
> I think instead of the chop() and return above, you just want a "break;",
> to be consistent with the >> operator below.

If there will be 'break' then line consiting of only '\n' will return 0
to calling function. I tried to make this function as close to
ExternalParser::readLine as possible to remove readLine from
ExternalParser.

> >       }
> >       if (Allocated > Length + 1)
> >       {
> >           //
> >           // Not all available space filled. Probably EOF?
> >           //
> >
> >           continue;
> >       }
> >       //
> >       // Only a partial line was read. Increase available space in
> >       // string and read some more.
> >       //
> >
> >       reallocate_space(Allocated << 1);
> >     }
> >     chop('\n');
> 
> I guess the chop() is a judgement call - some may prefer to leave the '\n'
> in the string, while some would prefer it taken out.  I guess for our
> purposes, we always want it out, and it's easy to add it if we want.

See above for my reason to remove '\n'.

> 
> >
> >     return Length > 0;
> 
> Should an empty line return 1 or 0?  This code will return 0 on any empty
> line, not just at EOF.

No it will not. Because of return 1 above on empty line will be returned
1.

> > }
> >
> > istream &
> > operator >> (istream &in, String &line)
> > {
> >     line.Length = 0;
> >     line.allocate_fix_space(2048);
> >
> >     while (in.get(line.Data + line.Length, line.Allocated - line.Length))
> >     {
> >       line.Length += strlen(line.Data + line.Length);
> >       int c = in.get();
> 
> I'm not clear on the semantics of ifstream::get() above, and why you need
> two calls to it.  Wouldn't it make more sense to use in.getline() instead,
> and keep the logic of this operator as close to the readLine() method
> above as possible?  I believe ifstream::getline()'s semantics are identical

IIRC getline will remove '\n' from buffer as well as from input stream. 
So I won't be able to find out whether '\n' was read or just maximum
number of bytes read. istream::get(char *, int maxlen) reads input
stream
until '\n' or maxbytes read leaving '\n' in input stream.

> to fgets(), except that is works on an ifstream instead of a FILE.  BTW,
> I think it's ifstream, and not istream.

IIRC ifstream is a subclass of istream. (I don't have GNU implementation
at hand, but it is so in Borland).

> 
> >       if (c == '\n')
> >       {
> >           //
> >           // A full line has been read.  Return it.
> >           //
> >           break;
> >       }
> >       if (line.Allocated > line.Length + 2)
> >       {
> >           //
> >           // Not all available space filled. Probably EOF?
> >           //
> >
> 
> Will this code add EOF to the Data?

Oops. It can. In case if there is a 2048 bytes in input stream
exactly (or 4096 or ...). In other cases 'while' will exit by
condition. So condition above instead of 'if (c == '\n')'
should be 'if (c == '\n' || c == EOF)'.

Alexis

------------------------------------
To unsubscribe from the htdig3-dev mailing list, send a message to
[EMAIL PROTECTED] 
You will receive a message to confirm this. 

Reply via email to