dbertoni 2003/03/05 16:17:57
Modified: c/src/PlatformSupport XalanOutputStream.cpp
XalanOutputStream.hpp XalanStdOutputStream.cpp
XalanStdOutputStream.hpp
Log:
Make sure CR/LF translation happens as necessary. Fixes bug 17426.
Revision Changes Path
1.19 +56 -1 xml-xalan/c/src/PlatformSupport/XalanOutputStream.cpp
Index: XalanOutputStream.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanOutputStream.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- XalanOutputStream.cpp 20 Nov 2002 02:27:14 -0000 1.18
+++ XalanOutputStream.cpp 6 Mar 2003 00:17:57 -0000 1.19
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,33 @@
+const XalanDOMChar XalanOutputStream::s_nlString[] =
+{
+ XalanUnicode::charLF,
+ 0
+};
+
+
+
+const XalanDOMChar XalanOutputStream::s_nlCRString[] =
+{
+ XalanUnicode::charCR,
+ XalanUnicode::charLF,
+ 0
+};
+
+
+
+const XalanDOMString::size_type
XalanOutputStream::s_nlStringLength =
+ sizeof(s_nlString) / sizeof(s_nlString[0]) - 1;
+
+const XalanDOMString::size_type
XalanOutputStream::s_nlCRStringLength =
+ sizeof(s_nlCRString) / sizeof(s_nlCRString[0]) - 1;
+
+
+
+
+
XalanOutputStream::XalanOutputStream(
BufferType::size_type theBufferSize,
TranscodeVectorType::size_type theTranscoderBlockSize,
@@ -410,6 +437,34 @@
// m_buffer is now the correct size.
temp.swap(m_buffer);
}
+}
+
+
+
+void
+XalanOutputStream::newline()
+{
+ // We've had requests to make this a run-time switch, but for now,
+ // it's compile time only...
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ write(s_nlCRString, s_nlCRStringLength);
+#else
+ write(s_nlString, s_nlStringLength);
+#endif
+}
+
+
+
+const XalanDOMChar*
+XalanOutputStream::getNewlineString() const
+{
+ // We've had requests to make this a run-time switch, but for now,
+ // it's compile time only...
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ return s_nlCRString;
+#else
+ return s_nlString;
+#endif
}
1.12 +83 -46 xml-xalan/c/src/PlatformSupport/XalanOutputStream.hpp
Index: XalanOutputStream.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanOutputStream.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XalanOutputStream.hpp 20 Nov 2002 02:27:14 -0000 1.11
+++ XalanOutputStream.hpp 6 Mar 2003 00:17:57 -0000 1.12
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,33 +10,33 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
*
* 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact [EMAIL PROTECTED]
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
@@ -119,10 +119,32 @@
virtual
~XalanOutputStream();
+ static const XalanDOMChar*
+ defaultNewlineString()
+ {
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ return s_nlCRString;
+#else
+ return s_nlString;
+#endif
+ }
+
+ /**
+ * Write the appropriate newline character(s) to the stream.
+ */
+ virtual void
+ newline();
+
+ /**
+ * Get the string which is appropriate for inserting a line feed in the
stream.
+ */
+ virtual const XalanDOMChar*
+ getNewlineString() const;
+
/**
* Flush the stream's buffer.
*/
- void
+ void
flush()
{
flushBuffer();
@@ -131,12 +153,12 @@
}
/**
- * Write a character to the output stream. The character
+ * Write a character to the output stream. The character
* will not be transcoded.
*
- * @param theChar the character to write
+ * @param theChar the character to write
*/
- void
+ void
write(char theChar)
{
write(&theChar, 1);
@@ -146,9 +168,9 @@
* Write a wide character to the output stream. The character
* will be transcoded, if an output encoding is specified.
*
- * @param theChar the character to write
+ * @param theChar the character to write
*/
- void
+ void
write(XalanDOMChar theChar)
{
assert(m_bufferSize > 0);
@@ -165,9 +187,9 @@
* Write a null-terminated string to the output file. The character
* will not be transcoded.
*
- * @param theBuffer character buffer to write
+ * @param theBuffer character buffer to write
*/
- void
+ void
write(const char* theBuffer)
{
assert(theBuffer != 0);
@@ -178,12 +200,12 @@
}
/**
- * Write a null-terminated wide string to the output file. The string
+ * Write a null-terminated wide string to the output file. The
string
* will be transcoded, if an output encoding is specified.
*
- * @param theBuffer character buffer to write
+ * @param theBuffer character buffer to write
*/
- void
+ void
write(const XalanDOMChar* theBuffer)
{
XALAN_USING_XALAN(length)
@@ -195,12 +217,12 @@
* Write a specified number of characters to the output stream. The
string
* will not be transcoded.
*
- * @param theBuffer character buffer to write
+ * @param theBuffer character buffer to write
* @param theBufferLength number of characters to write
*/
- void
+ void
write(
- const char* theBuffer,
+ const char* theBuffer,
size_type theBufferLength)
{
assert(theBuffer != 0);
@@ -215,12 +237,12 @@
* Write a specified number of characters to the output stream. The
string
* will be transcoded, if an output encoding is specified.
*
- * @param theBuffer character buffer to write
+ * @param theBuffer character buffer to write
* @param theBufferLength number of characters to write
*/
- void
+ void
write(
- const XalanDOMChar* theBuffer,
+ const XalanDOMChar* theBuffer,
size_type
theBufferLength);
/**
@@ -240,7 +262,7 @@
* @param theEncoding The encoding name
*/
void
- setOutputEncoding(const XalanDOMString& theEncoding);
+ setOutputEncoding(const XalanDOMString& theEncoding);
/**
* Determine if a given value can be represented in
@@ -248,8 +270,8 @@
*
* @return true if the value can be represented, and false if not.
*/
- bool
- canTranscodeTo(unsigned int theChar) const;
+ bool
+ canTranscodeTo(unsigned int theChar) const;
const XalanOutputTranscoder*
getTranscoder() const
@@ -282,7 +304,7 @@
* @param the new value of the flag.
*/
void
- setThrowTranscodeException(bool flag)
+ setThrowTranscodeException(bool flag)
{
m_throwTranscodeException = flag;
}
@@ -293,7 +315,7 @@
* @param theBufferSize The buffer size.
*/
void
- setBufferSize(BufferType::size_type theBufferSize);
+ setBufferSize(BufferType::size_type theBufferSize);
class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStreamException : public
XSLException
@@ -381,27 +403,42 @@
*/
void
transcode(
- const XalanDOMChar* theBuffer,
+ const XalanDOMChar* theBuffer,
size_type theBufferLength,
TranscodeVectorType& theDestination);
+ /**
+ * Write the data in the buffer
+ *
+ * @param theBuffer The data to write
+ * @param theBufferLength The length of theBuffer.
+ */
virtual void
writeData(
- const char* theBuffer,
+ const char* theBuffer,
size_type theBufferLength) = 0;
+ /**
+ * Flush the stream.
+ */
virtual void
doFlush() = 0;
+ static const XalanDOMChar s_nlString[];
+ static const XalanDOMChar s_nlCRString[];
+
+ static const XalanDOMString::size_type s_nlStringLength;
+ static const XalanDOMString::size_type s_nlCRStringLength;
+
private:
- // These are not implemented...
- XalanOutputStream(const XalanOutputStream&);
+ // These are not implemented...
+ XalanOutputStream(const XalanOutputStream&);
- XalanOutputStream&
+ XalanOutputStream&
operator=(const XalanOutputStream&);
- bool
+ bool
operator==(const XalanOutputStream&) const;
// Utility functions...
@@ -410,7 +447,7 @@
void
doWrite(
- const XalanDOMChar* theBuffer,
+ const XalanDOMChar* theBuffer,
size_t
theBufferLength);
@@ -428,7 +465,7 @@
bool
m_throwTranscodeException;
- TranscodeVectorType
m_transcodingBuffer;
+ TranscodeVectorType
m_transcodingBuffer;
};
1.14 +45 -0 xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.cpp
Index: XalanStdOutputStream.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XalanStdOutputStream.cpp 20 Nov 2002 02:27:14 -0000 1.13
+++ XalanStdOutputStream.cpp 6 Mar 2003 00:17:57 -0000 1.14
@@ -81,13 +81,36 @@
XalanStdOutputStream::XalanStdOutputStream(StreamType&
theOutputStream) :
XalanOutputStream(),
+#if !defined(XALAN_NEWLINE_IS_CRLF)
m_outputStream(theOutputStream)
+#else
+ m_outputStream(theOutputStream),
+ m_newlineString(0),
+ m_newlineStringLength(0)
+#endif
{
// This will make sure that cerr is not buffered...
if (&m_outputStream == &XALAN_STD_QUALIFIER cerr)
{
setBufferSize(0);
+
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ m_newlineString = s_nlString;
+ m_newlineStringLength = s_nlStringLength;
+#endif
+ }
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ else if (&m_outputStream == &XALAN_STD_QUALIFIER cout)
+ {
+ m_newlineString = s_nlString;
+ m_newlineStringLength = s_nlStringLength;
+ }
+ else
+ {
+ m_newlineString = s_nlCRString;
+ m_newlineStringLength = s_nlCRStringLength;
}
+#endif
}
@@ -95,6 +118,28 @@
XalanStdOutputStream::~XalanStdOutputStream()
{
}
+
+
+
+#if defined(XALAN_NEWLINE_IS_CRLF)
+void
+XalanStdOutputStream::newline()
+{
+ assert(m_newlineString != 0 && length(m_newlineString) ==
m_newlineStringLength);
+
+ write(m_newlineString, m_newlineStringLength);
+}
+
+
+
+const XalanDOMChar*
+XalanStdOutputStream::getNewlineString() const
+{
+ assert(m_newlineString != 0);
+
+ return m_newlineString;
+}
+#endif
1.13 +16 -1 xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.hpp
Index: XalanStdOutputStream.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.hpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XalanStdOutputStream.hpp 20 Nov 2002 02:27:14 -0000 1.12
+++ XalanStdOutputStream.hpp 6 Mar 2003 00:17:57 -0000 1.13
@@ -114,6 +114,15 @@
virtual
~XalanStdOutputStream();
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ virtual void
+ newline();
+
+ virtual const XalanDOMChar*
+ getNewlineString() const;
+#endif
+
+
class XALAN_PLATFORMSUPPORT_EXPORT XalanStdOutputStreamWriteException :
public XalanOutputStream::XalanOutputStreamException
{
public:
@@ -143,7 +152,13 @@
operator=(const XalanStdOutputStream&);
// Data members...
- StreamType& m_outputStream;
+ StreamType& m_outputStream;
+
+#if defined(XALAN_NEWLINE_IS_CRLF)
+ const XalanDOMChar* m_newlineString;
+
+ XalanDOMString::size_type m_newlineStringLength;
+#endif
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]