dbertoni    2003/03/05 16:18:24

  Modified:    c/src/XMLSupport FormatterToText.cpp FormatterToText.hpp
                        FormatterToXML.cpp FormatterToXML.hpp
  Log:
  Make sure CR/LF translation happens as necessary.  Fixes bug 17426.
  
  Revision  Changes    Path
  1.19      +70 -32    xml-xalan/c/src/XMLSupport/FormatterToText.cpp
  
  Index: FormatterToText.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToText.cpp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FormatterToText.cpp       20 Nov 2002 02:32:13 -0000      1.18
  +++ FormatterToText.cpp       6 Mar 2003 00:18:24 -0000       1.19
  @@ -79,7 +79,9 @@
        m_encoding(),
        m_haveEncoding(false),
        m_normalize(true),
  -     m_handleIgnorableWhitespace(true)
  +     m_handleIgnorableWhitespace(true),
  +     m_newlineString(0),
  +     m_newlineStringLength(0)
   {
   }
   
  @@ -95,8 +97,11 @@
        m_encoding(),
        m_haveEncoding(false),
        m_normalize(normalizeLinefeed),
  -     m_handleIgnorableWhitespace(handleIgnorableWhitespace)
  +     m_handleIgnorableWhitespace(handleIgnorableWhitespace),
  +     m_newlineString(0),
  +     m_newlineStringLength(0)
   {
  +     update(true);
   }
   
   
  @@ -112,9 +117,11 @@
        m_encoding(isEmpty(encoding) == false ? encoding : 
XalanDOMString(XalanTranscodingServices::s_utf8String)),
        m_haveEncoding(true),
        m_normalize(normalizeLinefeed),
  -     m_handleIgnorableWhitespace(handleIgnorableWhitespace)
  +     m_handleIgnorableWhitespace(handleIgnorableWhitespace),
  +     m_newlineString(0),
  +     m_newlineStringLength(0)
   {
  -     update();
  +     update(false);
   }
   
   
  @@ -159,8 +166,6 @@
        assert(m_writer != 0);
   
        m_writer->flush();
  -
  -     m_writer->close();
   }
   
   
  @@ -197,26 +202,41 @@
        }
        else
        {
  -             for (unsigned int i = 0; i < length; ++i)
  +             unsigned int i = 0;
  +
  +             while(i < length)
                {
  +                     if (chars[i] > m_maxCharacter)
  +                     {
  +                             //$$$ ToDo: Figure out what we're going to do 
here...
  +                     }
  +
   #if defined(XALAN_NEWLINE_IS_CRLF)
  -                     if (m_normalize == true)
  +                     if (m_normalize == false)
  +                     {
  +                             m_writer->write(XalanUnicode::charLF);
  +                     }
  +                     else
                        {
                                // Normalize LF to CR/LF...
                                if (chars[i] == XalanUnicode::charLF &&
  -                                     (i == 0 ||
  -                                      chars[i - 1] != XalanUnicode::charCR))
  +                                     (i + 1 < length &&
  +                                      chars[i + 1] == XalanUnicode::charCR))
                                {
  -                                     m_writer->write(XalanUnicode::charCR);
  +                                     m_writer->write(m_newlineString, 
m_newlineStringLength);
  +
  +                                     ++i;
  +                             }
  +                             else
  +                             {
  +                                     m_writer->write(chars[i]);
                                }
                        }
  +#else
  +                     m_writer->write(chars[i]);
   #endif
  -                     if (chars[i] > m_maxCharacter)
  -                     {
  -                             //$$$ ToDo: Figure out what we're going to do 
here...
  -                     }
   
  -                     m_writer->write(chars[i]);
  +                     ++i;
                }
        }
   }
  @@ -289,8 +309,12 @@
   
   
   
  +static const XalanDOMChar    s_newlineChar = XalanUnicode::charLF;
  +
  +
  +
   void
  -FormatterToText::update()
  +FormatterToText::update(bool fNormalizationOnly)
   {
        assert(m_writer != 0);
   
  @@ -298,29 +322,43 @@
   
        if (theStream == 0)
        {
  -             // We're pretty much screwed here, since we can't transcode, so 
get the
  -             // maximum character for the local code page.
  -             m_maxCharacter = 
XalanTranscodingServices::getMaximumCharacterValue();
  +             m_newlineString = &s_newlineChar;
  +             m_newlineStringLength = 1;
  +
  +             if (fNormalizationOnly == false)
  +             {
  +                     // We're pretty much screwed here, since we can't 
transcode, so get the
  +                     // maximum character for the local code page.
  +                     m_maxCharacter = 
XalanTranscodingServices::getMaximumCharacterValue();
  +             }
        }
        else
        {
  -             try
  -             {
  -                     theStream->setOutputEncoding(m_encoding);
  -             }
  -             catch(const XalanOutputStream::UnsupportedEncodingException&)
  +             m_newlineString = theStream->getNewlineString();
  +             assert(m_newlineString != 0);
  +
  +             m_newlineStringLength = length(m_newlineString);
  +
  +             if (fNormalizationOnly == false)
                {
  -                     const XalanDOMString    
theUTF8String(XalanTranscodingServices::s_utf8String);
  +                     try
  +                     {
  +                             theStream->setOutputEncoding(m_encoding);
  +                     }
  +                     catch(const 
XalanOutputStream::UnsupportedEncodingException&)
  +                     {
  +                             const XalanDOMString    
theUTF8String(XalanTranscodingServices::s_utf8String);
   
  -                     // Default to UTF-8 if the requested encoding is not 
supported...
  -                     theStream->setOutputEncoding(theUTF8String);
  +                             // Default to UTF-8 if the requested encoding 
is not supported...
  +                             theStream->setOutputEncoding(theUTF8String);
   
  -                     m_encoding = theUTF8String;
  +                             m_encoding = theUTF8String;
   
  -                     m_haveEncoding = true;
  -             }
  +                             m_haveEncoding = true;
  +                     }
   
  -             m_maxCharacter = 
XalanTranscodingServices::getMaximumCharacterValue(theStream->getOutputEncoding());
  +                     m_maxCharacter = 
XalanTranscodingServices::getMaximumCharacterValue(theStream->getOutputEncoding());
  +             }
        }
   }
   
  
  
  
  1.13      +7 -3      xml-xalan/c/src/XMLSupport/FormatterToText.hpp
  
  Index: FormatterToText.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToText.hpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FormatterToText.hpp       20 Nov 2002 02:32:13 -0000      1.12
  +++ FormatterToText.hpp       6 Mar 2003 00:18:24 -0000       1.13
  @@ -135,7 +135,7 @@
        {
                m_writer = theWriter;
   
  -             update();
  +             update(false);
        }
   
        void
  @@ -152,7 +152,7 @@
        {
                m_encoding = theEncoding;
   
  -             update();
  +             update(false);
        }
   
        XalanDOMChar
  @@ -258,7 +258,7 @@
        // Utility function to update various member variables
        // when data changes.
        void
  -     update();
  +     update(bool     fNormalizationOnly);
   
        // Data members...
        Writer*                 m_writer;
  @@ -272,6 +272,10 @@
        bool                    m_normalize;
   
        bool                    m_handleIgnorableWhitespace;
  +
  +     const XalanDOMChar*                     m_newlineString;
  +
  +     XalanDOMString::size_type       m_newlineStringLength;
   };
   
   
  
  
  
  1.66      +14 -7     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.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- FormatterToXML.cpp        8 Jan 2003 06:56:10 -0000       1.65
  +++ FormatterToXML.cpp        6 Mar 2003 00:18:24 -0000       1.66
  @@ -166,7 +166,11 @@
                }
        }
   
  -     if (m_stream != 0)
  +     if (m_stream == 0)
  +     {
  +             m_newlineString = XalanOutputStream::defaultNewlineString();
  +     }
  +     else
        {
                try
                {
  @@ -179,8 +183,14 @@
   
                        m_encoding = XalanTranscodingServices::s_utf8String;
                }
  +
  +             m_newlineString = m_stream->getNewlineString();
        }
   
  +     assert(m_newlineString != 0);
  +
  +     m_newlineStringLength = length(m_newlineString);
  +
        m_maxCharacter = 
XalanTranscodingServices::getMaximumCharacterValue(m_encoding);
   
        m_encodingIsUTF = XalanTranscodingServices::encodingIsUTF8(m_encoding) 
||
  @@ -1662,12 +1672,9 @@
   void
   FormatterToXML::outputLineSep()
   {
  -#if defined(XALAN_NEWLINE_IS_CRLF)
  -     accumContent(XalanUnicode::charCR);
  -     accumContent(XalanUnicode::charLF);
  -#else
  -     accumContent(XalanUnicode::charLF);
  -#endif
  +     assert(m_newlineString != 0 && length(m_newlineString) == 
m_newlineStringLength);
  +
  +     accumContent(m_newlineString, 0, m_newlineStringLength);
   }
   
   
  
  
  
  1.43      +10 -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.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- FormatterToXML.hpp        8 Jan 2003 06:56:10 -0000       1.42
  +++ FormatterToXML.hpp        6 Mar 2003 00:18:24 -0000       1.43
  @@ -1205,6 +1205,16 @@
         * A pointer to the member function that will flush the buffer.
         */
        FlushFunctionType                       m_flushFunction;
  +
  +     /**
  +      * The string of characters that represents the newline
  +      */
  +     const XalanDOMChar*                     m_newlineString;
  +
  +     /**
  +      * The length of the the string of characters that represents the 
newline
  +      */
  +     XalanDOMString::size_type       m_newlineStringLength;
   };
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to