Added Encoding of charset information
Encoded < and > as LT and GT character entities to fix bug #4709 git-svn-id: svn://10.0.0.236/trunk@29161 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
d3ed7620de
commit
17d6c2ea7a
@ -2618,13 +2618,24 @@ void nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
|
||||
|
||||
converter.SetSelection(aSelection);
|
||||
|
||||
converter.AddStartTag("section");
|
||||
|
||||
converter.AddStartTag("section");
|
||||
converter.AddStartTag("section_head");
|
||||
converter.AddEndTag("section_head");
|
||||
|
||||
nsString charset = "ISO-8859-1";
|
||||
if (mCharacterSet != nsnull)
|
||||
charset = *mCharacterSet;
|
||||
|
||||
converter.BeginStartTag("document_info");
|
||||
converter.AddAttribute(nsString("charset"),charset);
|
||||
converter.FinishStartTag("document_info",PR_TRUE,PR_TRUE);
|
||||
|
||||
|
||||
converter.AddEndTag("section_head");
|
||||
converter.AddStartTag("section_body");
|
||||
|
||||
|
||||
|
||||
|
||||
nsIDOMElement* root = nsnull;
|
||||
if (NS_OK == GetDocumentElement(&root))
|
||||
{
|
||||
|
||||
@ -2618,13 +2618,24 @@ void nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
|
||||
|
||||
converter.SetSelection(aSelection);
|
||||
|
||||
converter.AddStartTag("section");
|
||||
|
||||
converter.AddStartTag("section");
|
||||
converter.AddStartTag("section_head");
|
||||
converter.AddEndTag("section_head");
|
||||
|
||||
nsString charset = "ISO-8859-1";
|
||||
if (mCharacterSet != nsnull)
|
||||
charset = *mCharacterSet;
|
||||
|
||||
converter.BeginStartTag("document_info");
|
||||
converter.AddAttribute(nsString("charset"),charset);
|
||||
converter.FinishStartTag("document_info",PR_TRUE,PR_TRUE);
|
||||
|
||||
|
||||
converter.AddEndTag("section_head");
|
||||
converter.AddStartTag("section_body");
|
||||
|
||||
|
||||
|
||||
|
||||
nsIDOMElement* root = nsnull;
|
||||
if (NS_OK == GetDocumentElement(&root))
|
||||
{
|
||||
|
||||
@ -39,6 +39,7 @@ nsXIFConverter::nsXIFConverter(nsString& aBuffer) :
|
||||
mContainer = "container";
|
||||
mLeaf = "leaf";
|
||||
mIsa = "isa";
|
||||
mEntity = "entity";
|
||||
|
||||
mSelector = "css_selector";
|
||||
mRule = "css_rule";
|
||||
@ -228,13 +229,78 @@ void nsXIFConverter::AddEndTag(nsIAtom* aTag, PRBool aDoIndent, PRBool aDoReturn
|
||||
AddEndTag(tag,aDoIndent,aDoReturn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool nsXIFConverter::IsMarkupEntity(const PRUnichar aChar)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
switch (aChar)
|
||||
{
|
||||
case '<':
|
||||
case '>':
|
||||
case '&':
|
||||
result = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
PRBool nsXIFConverter::AddMarkupEntity(const PRUnichar aChar)
|
||||
{
|
||||
nsAutoString data;
|
||||
PRBool result = PR_TRUE;
|
||||
|
||||
switch (aChar)
|
||||
{
|
||||
case '<': data = "lt"; break;
|
||||
case '>': data = "gt"; break;
|
||||
case '&': data = "amp"; break;
|
||||
default:
|
||||
result = PR_FALSE;
|
||||
break;
|
||||
}
|
||||
if (result == PR_TRUE)
|
||||
{
|
||||
BeginStartTag(mEntity);
|
||||
AddAttribute(mValue,data);
|
||||
FinishStartTag(mEntity,PR_TRUE,PR_FALSE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void nsXIFConverter::AddContent(const nsString& aContent)
|
||||
{
|
||||
nsString tag(mContent);
|
||||
|
||||
AddStartTag(tag,PR_FALSE);
|
||||
|
||||
mBuffer.Append(aContent);
|
||||
PRBool startTagAdded = PR_TRUE;
|
||||
PRInt32 length = aContent.Length();
|
||||
PRUnichar ch;
|
||||
for (PRInt32 i = 0; i < length; i++)
|
||||
{
|
||||
ch = aContent[i];
|
||||
if (IsMarkupEntity(ch))
|
||||
{
|
||||
if (startTagAdded == PR_TRUE)
|
||||
{
|
||||
AddEndTag(tag,PR_FALSE);
|
||||
startTagAdded = PR_FALSE;
|
||||
}
|
||||
AddMarkupEntity(ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startTagAdded == PR_FALSE)
|
||||
{
|
||||
AddStartTag(tag,PR_FALSE);
|
||||
startTagAdded = PR_TRUE;
|
||||
}
|
||||
mBuffer.Append(ch);
|
||||
}
|
||||
}
|
||||
AddEndTag(tag,PR_FALSE);
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ private:
|
||||
nsString mContent;
|
||||
nsString mComment;
|
||||
nsString mContainer;
|
||||
nsString mEntity;
|
||||
nsString mIsa;
|
||||
nsString mLeaf;
|
||||
|
||||
@ -111,6 +112,9 @@ public:
|
||||
void EndCSSDeclaration();
|
||||
void EndCSSDeclarationList();
|
||||
|
||||
PRBool IsMarkupEntity(const PRUnichar aChar);
|
||||
PRBool AddMarkupEntity(const PRUnichar aChar);
|
||||
|
||||
// Output routines
|
||||
void Write();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user