You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/12/06 22:15:18 UTC
cvs commit: xml-xalan/c/src/XMLSupport FormatterToHTML.cpp FormatterToHTML.hpp FormatterToXML.cpp FormatterToXML.hpp
dbertoni 00/12/06 13:15:15
Modified: c/src/XMLSupport FormatterToHTML.cpp FormatterToHTML.hpp
FormatterToXML.cpp FormatterToXML.hpp
Log:
Better HTML formatting.
Revision Changes Path
1.36 +142 -131 xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp
Index: FormatterToHTML.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- FormatterToHTML.cpp 2000/12/01 22:01:31 1.35
+++ FormatterToHTML.cpp 2000/12/06 21:14:59 1.36
@@ -417,7 +417,7 @@
accum(XalanUnicode::charLessThanSign);
- accum(name);
+ writeCharacters(name);
const unsigned int nAttrs = attrs.getLength();
@@ -476,23 +476,18 @@
accum(XalanUnicode::charLessThanSign);
accum(XalanUnicode::charSolidus);
- accum(name);
+ writeCharacters(name);
accum(XalanUnicode::charGreaterThanSign);
- }
+ }
else
{
if(elemDesc.is(ElemDesc::EMPTY) == false)
{
accum(XalanUnicode::charGreaterThanSign);
- if (shouldIndent == true)
- {
- indent(m_currentIndent);
- }
-
accum(XalanUnicode::charLessThanSign);
accum(XalanUnicode::charSolidus);
- accum(name, 0, length(name));
+ writeCharacters(name);
accum(XalanUnicode::charGreaterThanSign);
}
else
@@ -557,115 +552,8 @@
writeParentTagEnd();
m_ispreserve = true;
-
- for (unsigned int i = 0; i < length; ++i)
- {
- const XalanDOMChar ch = chars[i];
-
- if(ch < SPECIALSSIZE && m_charsMap[ch] != 'S')
- {
- accum(ch);
-
- continue;
- }
- else if (0x0A == ch && i + 1 < length && 0x0D == chars[i + 1])
- {
- outputLineSep();
-
- ++i;
- }
-
- if (0x0D == ch && i + 1 < length && 0x0A == chars[i + 1])
- {
- outputLineSep();
- ++i;
- }
- else if (0x0D == ch)
- {
- outputLineSep();
-
- ++i;
- }
- else if (XalanUnicode::charLF == ch)
- {
- outputLineSep();
- }
- else if (XalanUnicode::charLessThanSign == ch)
- {
- copyEntityIntoBuffer(s_ltString);
- }
- else if (XalanUnicode::charGreaterThanSign == ch)
- {
- copyEntityIntoBuffer(s_gtString);
- }
- else if (XalanUnicode::charAmpersand == ch)
- {
- copyEntityIntoBuffer(s_ampString);
- }
- else if(ch >= 9 && ch <= 126)
- {
- accum(ch);
- }
- else if(ch >= 160 && ch <= 255)
- {
- copyEntityIntoBuffer(theHTMLLatin1Symbols[ch - 160]);
- }
- else if(ch >= 913 && ch <= 937 && ch != 930)
- {
- copyEntityIntoBuffer(theHTMLSymbols1[ch - 913]);
- }
- else if(ch >= 945 && ch <= 969)
- {
- copyEntityIntoBuffer(theHTMLSymbols2[ch - 945]);
- }
- else if(ch >= 977 && ch <= 978)
- {
- // subtract the unused characters
- copyEntityIntoBuffer(theHTMLSymbols2[ch - 945 - 7]);
- }
- else if(ch == 982)
- {
- // subtract the unused characters
- copyEntityIntoBuffer(theHTMLSymbols2[ch - 945 - 10]);
- }
- else if (402 == ch)
- {
- copyEntityIntoBuffer(s_fnofString);
- }
- else if (m_isUTF8 == true && 0xd800 <= ch && ch < 0xdc00)
- {
- // UTF-16 surrogate
- unsigned int next = 0;
-
- if (i + 1 >= length)
- {
- throwInvalidUTF16SurrogateException(ch);
- }
- else
- {
- next = chars[++i];
-
- if (!(0xdc00 <= next && next < 0xe000))
- {
- throwInvalidUTF16SurrogateException(ch, next);
- }
-
- next = ((ch - 0xd800) << 10) + next - 0xdc00 + 0x00010000;
- }
-
- writeNumberedEntityReference(next);
- }
- else if(ch >= 0x007Fu && ch <= m_maxCharacter)
- {
- // Hope this is right...
- accum(ch);
- }
- else
- {
- writeNumberedEntityReference(ch);
- }
- }
+ writeCharacters(chars, length);
}
}
@@ -750,7 +638,7 @@
accum(XalanUnicode::charLessThanSign);
accum(XalanUnicode::charQuestionMark);
- accum(target);
+ writeCharacters(target);
if (length(data) > 0)
{
@@ -759,7 +647,7 @@
accum(XalanUnicode::charSpace);
}
- accum(data);
+ writeCharacters(data);
}
accum(XalanUnicode::charGreaterThanSign); // different from XML
@@ -771,6 +659,117 @@
void
+FormatterToHTML::writeCharacters(const XalanDOMString& theString)
+{
+ writeCharacters(toCharArray(theString), length(theString));
+}
+
+
+
+void
+FormatterToHTML::writeCharacters(
+ const XalanDOMChar* theString,
+ unsigned int theLength)
+{
+ assert(theString != 0);
+
+ if (theLength == unsigned(-1))
+ {
+ theLength = length(theString);
+ }
+
+ for (unsigned int i = 0; i < theLength; ++i)
+ {
+ const XalanDOMChar ch = theString[i];
+
+ if(ch < SPECIALSSIZE && m_charsMap[ch] != 'S')
+ {
+ accum(ch);
+ }
+ else if (XalanUnicode::charLF == ch)
+ {
+ outputLineSep();
+ }
+ else if (XalanUnicode::charLessThanSign == ch)
+ {
+ copyEntityIntoBuffer(s_ltString);
+ }
+ else if (XalanUnicode::charGreaterThanSign == ch)
+ {
+ copyEntityIntoBuffer(s_gtString);
+ }
+ else if (XalanUnicode::charAmpersand == ch)
+ {
+ copyEntityIntoBuffer(s_ampString);
+ }
+ else if(ch >= 160 && ch <= 255)
+ {
+ copyEntityIntoBuffer(theHTMLLatin1Symbols[ch - 160]);
+ }
+ else if(ch >= 913 && ch <= 937 && ch != 930)
+ {
+ copyEntityIntoBuffer(theHTMLSymbols1[ch - 913]);
+ }
+ else if(ch >= 945 && ch <= 969)
+ {
+ copyEntityIntoBuffer(theHTMLSymbols2[ch - 945]);
+ }
+ else if(ch >= 977 && ch <= 978)
+ {
+ // subtract the unused characters
+ copyEntityIntoBuffer(theHTMLSymbols2[ch - 945 - 7]);
+ }
+ else if(ch == 982)
+ {
+ // subtract the unused characters
+ copyEntityIntoBuffer(theHTMLSymbols2[ch - 945 - 10]);
+ }
+ else if (338 == ch)
+ {
+ copyEntityIntoBuffer(s_oeligString);
+ }
+ else if (402 == ch)
+ {
+ copyEntityIntoBuffer(s_fnofString);
+ }
+ else if (m_isUTF8 == true && 0xd800 <= ch && ch < 0xdc00)
+ {
+ // UTF-16 surrogate
+ unsigned int next = 0;
+
+ if (i + 1 >= theLength)
+ {
+ throwInvalidUTF16SurrogateException(ch);
+ }
+ else
+ {
+ next = theString[++i];
+
+ if (!(0xdc00 <= next && next < 0xe000))
+ {
+ throwInvalidUTF16SurrogateException(ch, next);
+ }
+
+ next = ((ch - 0xd800) << 10) + next - 0xdc00 + 0x00010000;
+ }
+
+ writeNumberedEntityReference(next);
+ }
+ else if(ch >= 0x007Fu && ch <= m_maxCharacter)
+ {
+ // Hope this is right...
+ accum(ch);
+ }
+ else
+ {
+ writeNumberedEntityReference(ch);
+ }
+ }
+}
+
+
+
+void
FormatterToHTML::writeAttrString(
const XalanDOMChar* string,
const XalanDOMString& /* encoding */)
@@ -852,21 +851,17 @@
accum(theHTMLSymbols2[ch - 945 - 10]);
accum(XalanUnicode::charSemicolon);
}
+ else if (338 == ch)
+ {
+ copyEntityIntoBuffer(s_oeligString);
+ }
else if (402 == ch)
{
- accum(XalanUnicode::charAmpersand);
- accum(XalanUnicode::charLetter_f);
- accum(XalanUnicode::charLetter_n);
- accum(XalanUnicode::charLetter_o);
- accum(XalanUnicode::charLetter_f);
- accum(XalanUnicode::charSemicolon);
+ copyEntityIntoBuffer(s_fnofString);
}
else
{
- accum(XalanUnicode::charAmpersand);
- accum(XalanUnicode::charNumberSign);
- accum(UnsignedLongToDOMString(ch));
- accum(XalanUnicode::charSemicolon);
+ writeNumberedEntityReference(ch);
}
}
}
@@ -875,6 +870,14 @@
void
+FormatterToHTML::commentData(const XalanDOMChar* data)
+{
+ writeCharacters(data);
+}
+
+
+
+void
FormatterToHTML::copyEntityIntoBuffer(const XalanDOMChar* s)
{
const unsigned int len = length(s);
@@ -934,11 +937,11 @@
if(elemDesc.isAttrFlagSet(name, ElemDesc::ATTREMPTY) == true &&
(length(value) == 0) || equalsIgnoreCaseASCII(value, name) == true)
{
- accum(name);
+ writeCharacters(name);
}
else
{
- accum(name);
+ writeCharacters(name);
accum(XalanUnicode::charEqualsSign);
accum(XalanUnicode::charQuoteMark);
@@ -1559,6 +1562,7 @@
static XalanDOMCharVectorType s_fnofString;
+static XalanDOMCharVectorType s_oeligString;
const XalanDOMCharVectorType& FormatterToHTML::s_doctypeHeaderStartString =
@@ -1588,6 +1592,9 @@
const XalanDOMCharVectorType& FormatterToHTML::s_fnofString =
::s_fnofString;
+const XalanDOMCharVectorType& FormatterToHTML::s_oeligString =
+ ::s_oeligString;
+
#if !defined(XALAN_LSTRSUPPORT)
@@ -1631,6 +1638,8 @@
::s_fnofString = MakeXalanDOMCharVector(c_wstr(XALAN_STATIC_UCODE_STRING("fnof")));
+ ::s_oeligString = MakeXalanDOMCharVector(c_wstr(XALAN_STATIC_UCODE_STRING("OElig")));
+
#if !defined(XALAN_LSTRSUPPORT)
pushStringsOnVector(
theHTMLSymbols1Narrow,
@@ -1673,6 +1682,8 @@
XalanDOMCharVectorType().swap(::s_ampString);
XalanDOMCharVectorType().swap(::s_fnofString);
+
+ XalanDOMCharVectorType().swap(::s_oeligString);
#if !defined(XALAN_LSTRSUPPORT)
XalanDOMStringVectorType().swap(theHTMLSymbols1);
1.15 +17 -2 xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp
Index: FormatterToHTML.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FormatterToHTML.hpp 2000/12/01 21:38:53 1.14
+++ FormatterToHTML.hpp 2000/12/06 21:15:01 1.15
@@ -58,7 +58,7 @@
#define FORMATTERTOHTML_HEADER_GUARD_1357924680
/**
- * $Id: FormatterToHTML.hpp,v 1.14 2000/12/01 21:38:53 dbertoni Exp $
+ * $Id: FormatterToHTML.hpp,v 1.15 2000/12/06 21:15:01 dbertoni Exp $
*
* $State: Exp $
*
@@ -165,7 +165,6 @@
virtual void
entityReference(const XMLCh* const name);
-
virtual void
cdata(
const XMLCh* const ch,
@@ -287,6 +286,17 @@
const XalanDOMChar* string,
const XalanDOMString& encoding);
+ virtual void
+ commentData(const XalanDOMChar* data);
+
+ void
+ writeCharacters(const XalanDOMString& theString);
+
+ void
+ writeCharacters(
+ const XalanDOMChar* theString,
+ unsigned int theLength = unsigned(-1));
+
private:
static const ElementFlagsMapType& s_elementFlags;
@@ -340,6 +350,11 @@
* The string "fnof".
*/
static const XalanDOMCharVectorType& s_fnofString;
+
+ /**
+ * The string "OElig".
+ */
+ static const XalanDOMCharVectorType& s_oeligString;
/**
* Set the attribute characters what will require special mapping.
1.37 +9 -1 xml-xalan/c/src/XMLSupport/FormatterToXML.cpp
Index: FormatterToXML.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToXML.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- FormatterToXML.cpp 2000/11/09 18:01:41 1.36
+++ FormatterToXML.cpp 2000/12/06 21:15:03 1.37
@@ -859,6 +859,14 @@
void
+FormatterToXML::commentData(const XalanDOMChar* data)
+{
+ accum(data);
+}
+
+
+
+void
FormatterToXML::writeNormalizedChars(
const XalanDOMChar ch[],
unsigned int start,
@@ -1072,7 +1080,7 @@
accum(XalanUnicode::charHyphenMinus);
accum(XalanUnicode::charHyphenMinus);
- accum(data);
+ commentData(data);
accum(XalanUnicode::charHyphenMinus);
accum(XalanUnicode::charHyphenMinus);
1.24 +7 -0 xml-xalan/c/src/XMLSupport/FormatterToXML.hpp
Index: FormatterToXML.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToXML.hpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- FormatterToXML.hpp 2000/12/05 17:19:53 1.23
+++ FormatterToXML.hpp 2000/12/06 21:15:04 1.24
@@ -505,6 +505,13 @@
const XalanDOMString& encoding);
/**
+ * Write the data of a comment.
+ * @param data The string to write.
+ */
+ virtual void
+ commentData(const XalanDOMChar* data);
+
+ /**
* Throw an exception when an invalid
* surrogate is encountered.
* @param ch The first character in the surrogate