#include "stdafx.h"
#include "LiteHTMLReader.h"
#include
#include "LiteHTMLEntityResolver.h"
#include "UnicodeTextFile.h"
#pragma warning(push, 4)
// helper - delete specific tag from html string
void CLiteHTMLReader::DeleteComments (CString &sHtml)
{
int iCommentStart (0);
while (true)
{
iCommentStart = sHtml.Find (_T(""), iCommentStart + 4); // length of "'
}
else
{
sHtml.Delete (iCommentStart, sHtml.GetLength() - iCommentStart); // delete to end of file
}
}
}
void CLiteHTMLReader::DeleteTags (CString &sHtml, CString sTagName)
{
const int sTagLength = sTagName.GetLength();
CString sTagPrefixOpened = _T("<");
sTagPrefixOpened += sTagName; // "");
int iScriptStart = 0;
// delete script
while (true)
{
iScriptStart = sHtml.Find (sTagPrefixOpened, iScriptStart);
if (-1 == iScriptStart)
break;
const int iScriptEnd = sHtml.Find (sTagClosed, iScriptStart + sTagLength + 1); // length of "<" + tagLenth
if (-1 == iScriptEnd)
{
const int iScriptPrefixEnd = sHtml.Find (_T(">"), iScriptStart + sTagLength + 1);
if (-1 != iScriptPrefixEnd)
{
sHtml.Delete (iScriptStart, iScriptPrefixEnd - iScriptStart);
}
else
{
sHtml.Delete (iScriptStart, sTagLength + 1); // end of a doc ?
}
}
else
{
sHtml.Delete (iScriptStart, iScriptEnd - iScriptStart + sTagLength + 2 + 1); // length of "" + tagLenth + ">"
}
}
}
UINT CLiteHTMLReader::parseDocument(void)
{
ATLASSERT(m_lpszBuffer != NULL);
bool bAbort = false; // continue parsing or abort?
bool bIsClosingTag = false; // tag parsed is a closing tag?
bool bIsOpeningTag = false; // tag parsed is an opening tag?
bool bInsideScript = false;
CString strCharacters; // character data
CString strComment; // comment data
CString strT; // temporary storage
DWORD dwCharDataStart = 0L; // starting position of character data
DWORD dwCharDataLen = 0L; // length of character data
LONG lTemp = 0L; // temporary storage
TCHAR ch = 0; // character at current buffer position
CLiteHTMLTag oTag; // tag information
if ( (!m_lpszBuffer) || (!m_dwBufLen) )
return (0U);
// reset seek pointer to beginning
ResetSeekPointer();
// notify event handler about parsing startup
if (getEventNotify(notifyStartStop))
{
bAbort = false;
m_pEventHandler->BeginParse(m_dwAppData, bAbort);
if (bAbort) goto LEndParse;
}
// skip leading white-space characters
while (isWhiteSpace(ReadChar()))
;
TTagParsingMode aTagParsingMode = TPM_NORMAL;
ch = UngetChar();
while ((ch = ReadChar()) != NULL)
{
switch (ch)
{
// tag starting delimeter?
case _T('<'):
{
UngetChar();
strComment.Empty();
if (!parseComment(strComment))
{
bIsOpeningTag = false;
bIsClosingTag = false;
if (!parseTag(oTag, bIsOpeningTag, bIsClosingTag, aTagParsingMode))
{
++dwCharDataLen;
// manually advance buffer position
// because the last call to UngetChar()
// moved it back one character
ch = ReadChar();
break;
}
else
{
// check