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/11/20 17:18:57 UTC

cvs commit: xml-xalan/c/src/XMLSupport FormatterToText.cpp FormatterToText.hpp

dbertoni    00/11/20 08:18:56

  Modified:    c/src/XMLSupport FormatterToText.cpp FormatterToText.hpp
  Log:
  Added option to bypass CR/LF normalization.
  
  Revision  Changes    Path
  1.12      +34 -17    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FormatterToText.cpp	2000/11/02 01:45:51	1.11
  +++ FormatterToText.cpp	2000/11/20 16:18:52	1.12
  @@ -72,11 +72,15 @@
   
   
   
  -FormatterToText::FormatterToText(Writer&	writer) :
  +FormatterToText::FormatterToText(
  +			Writer&		writer,
  +			bool		normalizeLinefeed) :
   	FormatterListener(OUTPUT_METHOD_TEXT),
   	m_writer(writer),
   	m_maxCharacter(~0),
  -	m_encoding()
  +	m_encoding(),
  +	m_haveEncoding(false),
  +	m_normalize(normalizeLinefeed)
   {
   }
   
  @@ -84,11 +88,14 @@
   
   FormatterToText::FormatterToText(
   			Writer&					writer,
  -			const XalanDOMString&	encoding) :
  +			const XalanDOMString&	encoding,
  +			bool					normalizeLinefeed) :
   	FormatterListener(OUTPUT_METHOD_TEXT),
   	m_writer(writer),
   	m_maxCharacter(0),
  -	m_encoding(isEmpty(encoding) == false ? encoding : XalanDOMString(XalanTranscodingServices::s_utf8String))
  +	m_encoding(isEmpty(encoding) == false ? encoding : XalanDOMString(XalanTranscodingServices::s_utf8String)),
  +	m_haveEncoding(true),
  +	m_normalize(normalizeLinefeed)
   {
   	XalanOutputStream* const	theStream = m_writer.getStream();
   
  @@ -175,23 +182,33 @@
   			const XMLCh* const	chars,
   			const unsigned int	length)
   {
  -	for (unsigned int i = 0; i < length; ++i)
  +	if (m_normalize == false && m_haveEncoding == false)
   	{
  -#if defined(XALAN_NEWLINE_IS_CRLF)
  -		// Normalize LF to CR/LF...
  -		if (chars[i] == XalanUnicode::charLF &&
  -			(i == 0 ||
  -			 chars[i - 1] != XalanUnicode::charCR))
  +		m_writer.write(chars, 0, length);
  +	}
  +	else
  +	{
  +		for (unsigned int i = 0; i < length; ++i)
   		{
  -			m_writer.write(XalanUnicode::charCR);
  -		}
  +#if defined(XALAN_NEWLINE_IS_CRLF)
  +			if (m_normalize == true)
  +			{
  +				// Normalize LF to CR/LF...
  +				if (chars[i] == XalanUnicode::charLF &&
  +					(i == 0 ||
  +					 chars[i - 1] != XalanUnicode::charCR))
  +				{
  +					m_writer.write(XalanUnicode::charCR);
  +				}
  +			}
   #endif
  -		if (chars[i] > m_maxCharacter)
  -		{
  -			//$$$ ToDo: Figure out what we're going to do here...
  -		}
  +			if (chars[i] > m_maxCharacter)
  +			{
  +				//$$$ ToDo: Figure out what we're going to do here...
  +			}
   
  -		m_writer.write(chars[i]);
  +			m_writer.write(chars[i]);
  +		}
   	}
   }
   
  
  
  
  1.7       +18 -8     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FormatterToText.hpp	2000/10/07 15:25:34	1.6
  +++ FormatterToText.hpp	2000/11/20 16:18:53	1.7
  @@ -90,18 +90,23 @@
   	 * FormatterToText instance constructor.
   	 *
   	 * @param writer writer for output
  +	 * @param normalizeLindefeed Normalize \n or \r\n (on certain platforms).
   	 */
  -	FormatterToText(Writer&		writer);
  +	FormatterToText(
  +			Writer&		writer,
  +			bool		normalizeLinefeed = true);
   
   	/**
   	 * FormatterToText instance constructor.
   	 *
   	 * @param writer writer for output
   	 * @param encoding character encoding for the writer
  +	 * @param normalizeLindefeed Normalize \n or \r\n on certain platforms.
   	 */
   	FormatterToText(
   			Writer&					writer,
  -			const XalanDOMString&	encoding);
  +			const XalanDOMString&	encoding,
  +			bool					normalizeLinefeed = true);
   
   	virtual
   	~FormatterToText();
  @@ -163,12 +168,6 @@
   
   private:
   
  -	Writer&			m_writer;
  -
  -	XalanDOMChar	m_maxCharacter;
  -
  -	XalanDOMString	m_encoding;
  -
   	// These are not implemented.
   	FormatterToText(const FormatterToText&);
   
  @@ -177,6 +176,17 @@
   
   	bool
   	operator==(const FormatterToText&) const;
  +
  +	// Data members...
  +	Writer&			m_writer;
  +
  +	XalanDOMChar	m_maxCharacter;
  +
  +	XalanDOMString	m_encoding;
  +
  +	const bool		m_haveEncoding;
  +
  +	const bool		m_normalize;
   };