|
/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich, and is bound by the */
/* MIT open source license (www.opensource.org/licenses/mit-license.html). */
/* See License.txt for more information. */
/***************************************************************************/
#include "stdafx.h"
#include "LineViewOfFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CLineViewOfFile::CLineViewOfFile(LPCTSTR pszFileName) :
CReadOnlyMemMappedFile(pszFileName), m_iFilePtr(0)
{
}
bool CLineViewOfFile::GetNextLine(const char *& outLine, int& outLen)
{
const BYTE * const ptrStart = m_pBuf + GetFilePointer();
const BYTE * const ptrLast = m_pBuf + GetFileSize() - 1;
if (ptrStart > ptrLast) return false;
const BYTE *p = ptrStart;
while ( p <= ptrLast &&
*p != '\n' &&
*p != '\r')
{
++p;
}
outLine = (const char *)ptrStart;
outLen = p - ptrStart;
if (p < ptrLast)
{
const char ch = *p;
const char ch_next = *(p + 1);
if ((ch == '\r' && ch_next == '\n') ||
(ch == '\n' && ch_next == '\r'))
{
++p;
}
}
if (p > ptrLast) --p;
SetFilePointer(p - m_pBuf + 1);
return true;
}
void CLineViewOfFile::SetFilePointer(DWORD val)
{
ASSERT(val <= GetFileSize() && val > 0);
m_iFilePtr = val;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here