Added XMLQuote to quote special characters; changed MakeFrameName to avoid needing quoting

git-svn-id: svn://10.0.0.236/trunk@14949 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kipp%netscape.com
1998-11-19 17:55:22 +00:00
parent f8626bbd26
commit 7380c40198
4 changed files with 74 additions and 6 deletions

View File

@@ -1567,7 +1567,7 @@ nsresult
nsFrame::MakeFrameName(const char* aType, nsString& aResult) const
{
aResult = aType;
aResult.Append("<");
aResult.Append("(");
if (nsnull != mContent) {
nsIAtom* tag;
mContent->GetTag(tag);
@@ -1579,11 +1579,41 @@ nsFrame::MakeFrameName(const char* aType, nsString& aResult) const
}
}
char buf[40];
PR_snprintf(buf, sizeof(buf), ">(%d)", ContentIndexInContainer(this));
PR_snprintf(buf, sizeof(buf), ")(%d)", ContentIndexInContainer(this));
aResult.Append(buf);
return NS_OK;
}
void
nsFrame::XMLQuote(nsString& aString)
{
PRInt32 i, len = aString.Length();
for (i = 0; i < len; i++) {
PRUnichar ch = aString[i];
if (ch == '<') {
nsAutoString tmp("&lt;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 3;
i += 3;
}
else if (ch == '>') {
nsAutoString tmp("&gt;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 3;
i += 3;
}
else if (ch == '"') {
nsAutoString tmp("&quot;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 5;
i += 5;
}
}
}
NS_IMETHODIMP
nsFrame::DumpRegressionData(FILE* out, PRInt32 aIndent)
{
@@ -1591,6 +1621,7 @@ nsFrame::DumpRegressionData(FILE* out, PRInt32 aIndent)
fprintf(out, "<frame type=\"");
nsAutoString name;
GetFrameName(name);
XMLQuote(name);
fputs(name, out);
fprintf(out, "\">\n");
@@ -1656,6 +1687,7 @@ nsFrame::DumpBaseRegressionData(FILE* out, PRInt32 aIndent)
nsAutoString listName;
list->ToString(listName);
fprintf(out, "<child-list name=\"");
XMLQuote(listName);
fputs(listName, out);
fprintf(out, "\">\n");
}

View File

@@ -328,12 +328,14 @@ protected:
*/
virtual void DumpBaseRegressionData(FILE* out, PRInt32 aIndent);
void IndentBy(FILE* out, PRInt32 aIndent) const {
static void IndentBy(FILE* out, PRInt32 aIndent) {
while (--aIndent >= 0) fputs(" ", out);
}
nsresult MakeFrameName(const char* aKind, nsString& aResult) const;
static void XMLQuote(nsString& aString);
nsRect mRect;
nsIContent* mContent;
nsIStyleContext* mStyleContext;

View File

@@ -1567,7 +1567,7 @@ nsresult
nsFrame::MakeFrameName(const char* aType, nsString& aResult) const
{
aResult = aType;
aResult.Append("<");
aResult.Append("(");
if (nsnull != mContent) {
nsIAtom* tag;
mContent->GetTag(tag);
@@ -1579,11 +1579,41 @@ nsFrame::MakeFrameName(const char* aType, nsString& aResult) const
}
}
char buf[40];
PR_snprintf(buf, sizeof(buf), ">(%d)", ContentIndexInContainer(this));
PR_snprintf(buf, sizeof(buf), ")(%d)", ContentIndexInContainer(this));
aResult.Append(buf);
return NS_OK;
}
void
nsFrame::XMLQuote(nsString& aString)
{
PRInt32 i, len = aString.Length();
for (i = 0; i < len; i++) {
PRUnichar ch = aString[i];
if (ch == '<') {
nsAutoString tmp("&lt;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 3;
i += 3;
}
else if (ch == '>') {
nsAutoString tmp("&gt;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 3;
i += 3;
}
else if (ch == '"') {
nsAutoString tmp("&quot;");
aString.Cut(i, 1);
aString.Insert(tmp, i);
len += 5;
i += 5;
}
}
}
NS_IMETHODIMP
nsFrame::DumpRegressionData(FILE* out, PRInt32 aIndent)
{
@@ -1591,6 +1621,7 @@ nsFrame::DumpRegressionData(FILE* out, PRInt32 aIndent)
fprintf(out, "<frame type=\"");
nsAutoString name;
GetFrameName(name);
XMLQuote(name);
fputs(name, out);
fprintf(out, "\">\n");
@@ -1656,6 +1687,7 @@ nsFrame::DumpBaseRegressionData(FILE* out, PRInt32 aIndent)
nsAutoString listName;
list->ToString(listName);
fprintf(out, "<child-list name=\"");
XMLQuote(listName);
fputs(listName, out);
fprintf(out, "\">\n");
}

View File

@@ -328,12 +328,14 @@ protected:
*/
virtual void DumpBaseRegressionData(FILE* out, PRInt32 aIndent);
void IndentBy(FILE* out, PRInt32 aIndent) const {
static void IndentBy(FILE* out, PRInt32 aIndent) {
while (--aIndent >= 0) fputs(" ", out);
}
nsresult MakeFrameName(const char* aKind, nsString& aResult) const;
static void XMLQuote(nsString& aString);
nsRect mRect;
nsIContent* mContent;
nsIStyleContext* mStyleContext;