Mozilla How To Readline
时间:2006-03-23 来源:wolfssss
在xpcom/obsolete/nsFileStream.cpp文件中定义了这个方法,也许会有用。
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
// This will truncate if the buffer is too small. Result will always be null-terminated.
//----------------------------------------------------------------------------------------
{
PRBool bufferLargeEnough = PR_TRUE; // result
if (!s || !n)
return PR_TRUE;
PRIntn position = tell();
if (position < 0)
return PR_FALSE;
PRInt32 bytesRead = read(s, n - 1);
if (failed())
return PR_FALSE;
s[bytesRead] = '
char* tp = strpbrk(s, "\n\r");
if (tp)
{
TidyEndOfLine(tp);
bytesRead = (tp - s);
}
else if (!eof() && n-1 == bytesRead)
bufferLargeEnough = PR_FALSE;
position += bytesRead;
seek(position);
return bufferLargeEnough;
} // nsRandomAccessInputStream::readline
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
// This will truncate if the buffer is too small. Result will always be null-terminated.
//----------------------------------------------------------------------------------------
{
PRBool bufferLargeEnough = PR_TRUE; // result
if (!s || !n)
return PR_TRUE;
PRIntn position = tell();
if (position < 0)
return PR_FALSE;
PRInt32 bytesRead = read(s, n - 1);
if (failed())
return PR_FALSE;
s[bytesRead] = '
char* tp = strpbrk(s, "\n\r");
if (tp)
{
TidyEndOfLine(tp);
bytesRead = (tp - s);
}
else if (!eof() && n-1 == bytesRead)
bufferLargeEnough = PR_FALSE;
position += bytesRead;
seek(position);
return bufferLargeEnough;
} // nsRandomAccessInputStream::readline
相关阅读 更多 +