xmlesc.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,586 行 · 第 1/4 页
CPP
1,586 行
else if ( *pPositionPointer == '[' )
{
pObj->bInDataSection = TRUE;
}
else if ( *pPositionPointer == '>' )
{
pObj->bPushChar = FALSE;
pQueue->EnQueue(m_pEscapeStrings[EndDTD]);
pQueue->EnQueue(m_pEscapeStrings[BeginTagMarkup]);
pQueue->EnQueue(">");
pQueue->EnQueue(m_pEscapeStrings[EndTagMarkup]);
pObj->state = IN_CONTENT;
}
if ( pObj->bPushChar )
{
if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
else if ( *pPositionPointer == '&' )
{
/* protect ourselves from markup */
pQueue->EnQueue("&");
pObj->bPushChar = FALSE;
}
}
}
break;
case IN_CDATA:
{
if ( !strncmp((char*)pPositionPointer, "]]>", 3) )
{
pQueue->EnQueue(m_pEscapeStrings[EndCDATA]);
pQueue->EnQueue(m_pEscapeStrings[BeginTagMarkup]);
pQueue->EnQueue(m_pEscapeStrings[BeginTagNameMarkup]);
pQueue->EnQueue("]]");
pQueue->EnQueue(m_pEscapeStrings[EndTagNameMarkup]);
pQueue->EnQueue(">");
pQueue->EnQueue(m_pEscapeStrings[EndTagMarkup]);
pPositionPointer += 2;
uPositionOffset += 2;
pObj->bPushChar = FALSE;
pObj->state = IN_CONTENT;
}
if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
else if ( *pPositionPointer == '&' )
{
/* protect ourselves from markup */
pQueue->EnQueue("&");
pObj->bPushChar = FALSE;
}
}
break;
case ABOUT_TO_BEGIN_TAG:
{
/* we have seen the first '<'
* once we see a non-whitespace character
* we will be in the tag identifier
*/
if ( *pPositionPointer == '>' )
{
pQueue->EnQueue(m_pEscapeStrings[EndTagNameMarkup]);
EndColorTag(pQueue, pObj);
}
else if ( !IS_SPACE(*pPositionPointer) )
{
pObj->state = IN_BEGIN_TAG;
pObj->tag_index = 0;
pObj->tag[pObj->tag_index++] = *pPositionPointer;
if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
pQueue->EnQueue("<");
}
}
}
break;
case IN_BEGIN_TAG:
{
/* go to the IN_TAG state when we see
* the first whitespace
*/
if ( IS_SPACE(*pPositionPointer) )
{
pQueue->EnQueue(m_pEscapeStrings[EndTagNameMarkup]);
pObj->bPushChar = TRUE; // we want to still push it
pObj->state = IN_TAG;
if (pObj->tag_index < MAXTAGLEN) pObj->tag[pObj->tag_index] = '\0';
if ( CheckTag(pObj) )
{
UINT32 pos = OnTag(pPositionPointer, ulLen - uPositionOffset, pObj, pQueue);
pPositionPointer += pos;
uPositionOffset += pos;
}
}
else if ( *pPositionPointer == '>' )
{
pQueue->EnQueue(m_pEscapeStrings[EndTagNameMarkup]);
EndColorTag(pQueue, pObj);
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
if ( !pObj->bInBrokenXML )
{
pObj->bInBrokenXML = TRUE;
pQueue->EnQueue(m_pEscapeStrings[BeginBrokenAttributeMarkup]);
pQueue->EnQueue("<");
}
else
{
pQueue->EnQueue("<");
}
}
else
{
if (pObj->tag_index < MAXTAGLEN)
{
pObj->tag[pObj->tag_index++] = *pPositionPointer;
}
}
}
break;
case IN_TAG:
{
/* do nothing until you find a opening '=' or end '>' */
if ( *pPositionPointer == '=' )
{
pObj->bPushChar = FALSE;
pQueue->EnQueue("=");
pQueue->EnQueue(m_pEscapeStrings[BeginAttributeValueMarkup]);
pObj->state = BEGIN_ATTRIBUTE_VALUE;
}
else if ( *pPositionPointer == '>' )
{
EndColorTag(pQueue, pObj);
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
}
break;
case BEGIN_ATTRIBUTE_VALUE:
{
/* when we reach the first non-whitespace
* we will enter the UNQUOTED or the QUOTED
* ATTRIBUTE state
*/
if ( !IS_SPACE(*pPositionPointer) )
{
if ( *pPositionPointer == '\"' || *pPositionPointer == '\'')
{
pObj->cQuote = *pPositionPointer;
pObj->state = IN_QUOTED_ATTRIBUTE_VALUE;
/* no need to jump to the quoted attr handler
* since this char can't be a dangerous char
*/
}
else
{
pObj->state = IN_UNQUOTED_ATTRIBUTE_VALUE;
/* need to jump to the unquoted attr handler
* since this char can be a dangerous character
*/
goto unquoted_attribute_jump_point;
}
}
else if ( *pPositionPointer == '>' )
{
pQueue->EnQueue(m_pEscapeStrings[EndAttributeValueMarkup]);
EndColorTag(pQueue, pObj);
}
else if ( *pPositionPointer == '<' )
{
/* protect ourselves from markup */
pObj->bPushChar = FALSE;
pQueue->EnQueue("<");
}
}
break;
case IN_UNQUOTED_ATTRIBUTE_VALUE:
{
unquoted_attribute_jump_point:
/* do nothing until you find a whitespace */
if ( IS_SPACE(*pPositionPointer) )
{
pQueue->EnQueue(m_pEscapeStrings[EndAttributeValueMarkup]);
pObj->state = IN_TAG;
}
else if ( *pPositionPointer == '>' )
{
pQueue->EnQueue(m_pEscapeStrings[EndAttributeValueMarkup]);
EndColorTag(pQueue, pObj);
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
else if ( *pPositionPointer == '&' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("&");
}
break;
}
case IN_QUOTED_ATTRIBUTE_VALUE:
{
/* do nothing until you find a closing '"' */
if ( *pPositionPointer == pObj->cQuote )
{
pObj->bPushChar = FALSE;
if ( pObj->bInBrokenXML )
{
pQueue->EnQueue(m_pEscapeStrings[EndBrokenAttributeMarkup]);
pObj->bInBrokenXML = FALSE;
}
pQueue->EnQueue((void*)&pObj->cQuote, 1);
pQueue->EnQueue(m_pEscapeStrings[EndAttributeValueMarkup]);
pObj->state = IN_TAG;
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
else if ( *pPositionPointer == '&' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("&");
}
else if ( *pPositionPointer == '>' )
{
pObj->bPushChar = FALSE;
/* probably a broken attribute value */
if ( !pObj->bInBrokenXML )
{
pObj->bInBrokenXML = TRUE;
pQueue->EnQueue(m_pEscapeStrings[BeginBrokenAttributeMarkup]);
pQueue->EnQueue(">");
}
}
}
break;
case IN_COMMENT:
{
/* do nothing until you find a closing '-->' */
if ( !strncmp((char*)pPositionPointer, "-->", 3) )
{
pObj->bPushChar = FALSE;
pQueue->EnQueue("-->");
pPositionPointer += 2;
uPositionOffset += 2;
pQueue->EnQueue(m_pEscapeStrings[EndCommentMarkup]);
pObj->state = IN_CONTENT;
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
else if ( *pPositionPointer == '&' )
{
/* protect ourselves from markup */
pQueue->EnQueue("&");
pObj->bPushChar = FALSE;
}
}
break;
case IN_AMPERSAND_THINGY:
{
/* do nothing until you find a ';' or space */
if ( *pPositionPointer == ';' || IS_SPACE(*pPositionPointer) )
{
pObj->bPushChar = FALSE;
pQueue->EnQueue((char*)pPositionPointer, 1);
pQueue->EnQueue(m_pEscapeStrings[EndAmpersandThingyMarkup]);
pObj->state = IN_CONTENT;
}
else if ( *pPositionPointer == '<' )
{
pObj->bPushChar = FALSE;
/* protect ourselves from markup */
pQueue->EnQueue("<");
}
}
break;
default:
HX_ASSERT(0);
break;
}
if ( pObj->bPushChar )
{
pQueue->EnQueue((char*)pPositionPointer, 1);
}
pObj->bPushChar = TRUE;
}
}
/*___________________________________________________________________________
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Private Methods
*___________________________________________________________________________
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*___________________________________________________________________________
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* PushMangledDisplayedPath(pIn, pQueue, cEndQuote)
*
* PARAMETERS:
* pIn Pointer to a character string. It is positioned
* inside a quote right infront of the path or file to
* to be mangled
* pQueue A pointer to a CBigByteGrowingQueue that is used for queuing up
* the parsered output.
* cEndQuote - the character which ends the quote (either ' or ")
*
* DESCRIPTION:
* This Method replaces any path after a protocol with a /.../.
* If there is no protocol, then it just replaces any relative path with
* /.../
*
* RETURNS:
* The Number of characters off pIn that it pushed onto the queue
*___________________________________________________________________________
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
UINT32
CEscapeXMLtoHTML::PushMangledDisplayedPath(const UCHAR* pIn,
CBigByteGrowingQueue* pQueue,
char cEndQuote)
{
const char* pszQuote = strchr((const char*) pIn, cEndQuote);
if (pszQuote)
{
UINT32 ulLen = ((const UCHAR*) pszQuote) - pIn;
UINT32 ulPos = 0;
if ( m_bMangleLinks )
{
const UCHAR* pProtocolEnd = (const UCHAR*)strnstr((const char*)pIn,
"://", (int)ulLen);
if ( pProtocolEnd ) // we have protocol
{
pProtocolEnd += 2; // only push one slash
UINT32 ulLenOfProtocol = pProtocolEnd - pIn;
pQueue->EnQueue((void*)pIn, ulLenOfProtocol);
pIn += ulLenOfProtocol;
ulPos += ulLenOfProtocol;
}
// find last '/'
while ( strnchr((const char*)pIn, '/', ulLen - ulPos) )
{
UINT32 temp = ulPos;
temp += (const UCHAR*)strnchr((const char*)pIn, '/', ulLen - ulPos)
- pIn + 1;
pIn = (const UCHAR*)strnchr((const char*)pIn, '/', ulLen - ulPos)
+ 1;
ulPos = temp;
}
pQueue->EnQueue("/.../");
}
// else we just do the whole thing...
pQueue->EnQueue((void*)pIn, ulLen - ulPos);
return ulLen;
}
return 0;
}
/*___________________________________________________________________________
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* PushOpenningHREF(pPositionPointer, pQueue, cEndQuote)
*
* PARAMETERS:
* pPositionPointer Pointer to a character string. It is positioned
* inside a quote right infront of the path or file to
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?