Bug 5630. Use nsRandomAccessInputStream to read a line at a time (vs. a character at a time). Tip o' the hat to jim_nance@yahoo.com.

This commit is contained in:
waterson%netscape.com 1999-05-19 05:53:14 +00:00
Родитель 1b5675ff9f
Коммит 53141d021e
1 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -254,14 +254,30 @@ BookmarkParser::Parse(nsIRDFResource* aContainer, nsIRDFResource *nodeType)
{
// tokenize the input stream.
// XXX this needs to handle quotes, etc. it'd be nice to use the real parser for this...
nsRandomAccessInputStream in(*mStream);
nsresult rv = NS_OK;
nsAutoString line;
while (NS_SUCCEEDED(rv) && !mStream->eof() && !mStream->failed()) {
char c = mStream->get();
line.Append(c);
while (NS_SUCCEEDED(rv) && !in.eof() && !in.failed()) {
line.Truncate();
if (line.Last() != '\n' && line.Last() != '\r' && !mStream->eof())
continue; // keep building the string
while (1) {
char buf[256];
PRBool untruncated = in.readline(buf, sizeof(buf));
// in.readline() return PR_FALSE if there was buffer overflow,
// or there was a catastrophe. Check to see if we're here
// because of the latter...
NS_ASSERTION (! in.failed(), "error reading file");
if (in.failed()) return NS_ERROR_FAILURE;
// XXX Bug 5871. What charset conversion should we be
// applying here?
line.Append(buf);
if (untruncated)
break;
}
PRInt32 offset;
@ -291,7 +307,6 @@ BookmarkParser::Parse(nsIRDFResource* aContainer, nsIRDFResource *nodeType)
// XXX Discard the line. We should be treating this as the
// description.
}
line.Truncate();
}
return rv;
}