Beispiel #1
0
void VValueBag::DumpXMLCData( VString& ioDump, VIndex inCDataAttributeIndex) const
{
	VStr<1000> cdata;

	GetNthAttribute( inCDataAttributeIndex, NULL)->GetString( cdata);

	if (NeedsEscapeSequence( cdata, sXMLEscapeChars_Contents, sXMLEscapeChars_Contents + sizeof(sXMLEscapeChars_Contents)/sizeof(UniChar)))
	{
		ioDump += CVSTR( "<![CDATA[");

		// see if there's a "]]>" for which we need to split
		// someting like: hello ]]> world
		// becomes: <![CDATA[hello ]]>]]<![CDATA[> world]]>
		
		VIndex pos = 1;
		while( pos <= cdata.GetLength())
		{
			VIndex endTag = cdata.Find( CVSTR( "]]>"), pos, true);
			if (endTag > 0)
			{
				// add everything including ]]>
				ioDump.AppendBlock( cdata.GetCPointer() + pos - 1, (endTag - pos + 3) * sizeof( UniChar), VTC_UTF_16);
				// add ]] outside CDATA section
				ioDump.AppendString( CVSTR( "]]"));
				// open a new CDATA section and add remaining >
				ioDump += CVSTR( "<![CDATA[>");
				pos = endTag + 3;
			}
			else
			{
				// add everything left
				ioDump.AppendBlock( cdata.GetCPointer() + pos - 1, (cdata.GetLength() - pos + 1) * sizeof( UniChar), VTC_UTF_16);
				break;
			}
		}
		ioDump += CVSTR( "]]>");
	}
	else
	{
		VString toInsert;
		for (sLONG i = 0, n = cdata.GetLength(); i < n; i++)
		{
			UniChar c = cdata[ i ];
			if (c != 13 && c != 10 && c != 9)
			{
				toInsert += c;
			}
		}
		if ( ! toInsert.IsEmpty() )
			ioDump += toInsert;
	}
}