You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2004/01/21 00:23:57 UTC

cvs commit: xml-xerces/c/src/xercesc/dom/impl DOMWriterImpl.cpp

peiyongz    2004/01/20 15:23:57

  Modified:    c/src/xercesc/dom/impl DOMWriterImpl.cpp
  Log:
  patch to Bug#25751
  
  Revision  Changes    Path
  1.50      +70 -7     xml-xerces/c/src/xercesc/dom/impl/DOMWriterImpl.cpp
  
  Index: DOMWriterImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMWriterImpl.cpp,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- DOMWriterImpl.cpp	13 Jan 2004 20:47:42 -0000	1.49
  +++ DOMWriterImpl.cpp	20 Jan 2004 23:23:57 -0000	1.50
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.50  2004/01/20 23:23:57  peiyongz
  + * patch to Bug#25751
  + *
    * Revision 1.49  2004/01/13 20:47:42  knoaman
    * Remove unnecessary local static data
    *
  @@ -444,6 +447,8 @@
   static const XMLByte  BOM_ucs4be[]  = {(XMLByte)0x00, (XMLByte)0x00, (XMLByte)0xFE, (XMLByte)0xFF, (XMLByte) 0};
   static const XMLByte  BOM_ucs4le[]  = {(XMLByte)0xFF, (XMLByte)0xFE, (XMLByte)0x00, (XMLByte)0x00, (XMLByte) 0};
   
  +static bool lineFeedInTextNodePrinted = false;
  +static int  lastWhiteSpaceInTextNode = 0;
   
   //
   // Notification of the error though error handler
  @@ -855,11 +860,45 @@
               if (checkFilter(nodeToWrite) != DOMNodeFilter::FILTER_ACCEPT)
                   break;
   
  -            // Pretty-print skips whitespace-only text nodes unless whitespace-in-element is set.
  -            if (getFeature(FORMAT_PRETTY_PRINT_ID) && !getFeature(WHITESPACE_IN_ELEMENT_CONTENT_ID))
  +            if (getFeature(FORMAT_PRETTY_PRINT_ID))
               {
  +                lineFeedInTextNodePrinted = false;
  +                lastWhiteSpaceInTextNode = 0;
  +
                   if(XMLString::isAllWhiteSpace(nodeValue))
  -                    break;
  +                {
  +                    // skips whitespace-only text nodes unless whitespace-in-element is set.
  +                    if (!getFeature(WHITESPACE_IN_ELEMENT_CONTENT_ID))
  +                    {
  +                        break;
  +                    }
  +                    else        
  +                    {
  +                        //
  +                        // we need to trace if newline(s) have been printed out
  +                        // to avoid generate extra newline for pretty printing,
  +                        // as well as the number of whitespaces after the last
  +                        // newline character to do indentation properly.
  +                        //
  +                        int pos = XMLString::lastIndexOf(nodeValue, chLF);
  +                        if (-1 != pos)
  +                        {
  +                            lineFeedInTextNodePrinted = true;
  +                            lastWhiteSpaceInTextNode = lent - pos;
  +                        }
  +                        else
  +                        {
  +                            // for those platforms using chCR alone as
  +                            // a newline character
  +                            pos = XMLString::lastIndexOf(nodeValue, chCR);
  +                            if (-1 != pos)
  +                            {
  +                                lineFeedInTextNodePrinted = true;
  +                                lastWhiteSpaceInTextNode = lent - pos;
  +                            }
  +                        }
  +                    }
  +                }
               }
   
               setURCharRef();      // character data
  @@ -951,10 +990,18 @@
               if ( filterAction == DOMNodeFilter::FILTER_REJECT)
                   break;
   
  -            if(level == 1)
  +            if (!lineFeedInTextNodePrinted)
  +            {
  +                if(level == 1)
  +                    printNewLine();
  +
                   printNewLine();
  +            }
  +            else
  +            {
  +                lineFeedInTextNodePrinted = false;
  +            }
   
  -            printNewLine();
               printIndent(level);
   
               //track the line number the current node begins on
  @@ -1133,7 +1180,14 @@
                       //this node then print a new line and indent
                       if(nodeLine != fCurrentLine)
                       {
  -                        printNewLine();
  +                        if (!lineFeedInTextNodePrinted)
  +                        {
  +                            printNewLine();
  +                        }
  +                        else
  +                        {
  +                            lineFeedInTextNodePrinted = false;
  +                        }
   
                           if(nodeLine != fCurrentLine && level == 0)
                               printNewLine();
  @@ -1729,6 +1783,15 @@
   {
       if (getFeature(FORMAT_PRETTY_PRINT_ID))
       {
  +        if (lastWhiteSpaceInTextNode)
  +        {
  +            level -= lastWhiteSpaceInTextNode/2; // two chSpaces equals one indent level
  +            lastWhiteSpaceInTextNode = 0;
  +            // if lastWhiteSpaceInTextNode/2 is greater than level, then
  +            // it means too many spaces have been written to the
  +            // output stream and we can no longer indent properly
  +        }
  +
           for(int i = 0; i < level; i++)
               *fFormatter << chSpace << chSpace;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org