Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/bug-1189636 into
lp:zorba.
Commit message:
* Added hexbinary::streambuf and friends.
* Fixed buffer overflow bug in base64::streambuf::xsputn().
Requested reviews:
Paul J. Lucas (paul-lucas)
Related bugs:
Bug #1189636 in Zorba: transcoding hexBinary streambuf
https://bugs.launchpad.net/zorba/+bug/1189636
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/bug-1189636/+merge/170471
* Added hexbinary::streambuf and friends.
* Fixed buffer overflow bug in base64::streambuf::xsputn().
--
https://code.launchpad.net/~paul-lucas/zorba/bug-1189636/+merge/170471
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2013-06-19 19:27:26 +
+++ ChangeLog 2013-06-20 00:55:33 +
@@ -23,6 +23,7 @@
Bug Fixes/Other Changes:
* Fixed bug #1117952 (Improve XML error output format)
* Fixed bug #1188084 (fn-replace-42 failing)
+ * Fixed bug #1189636 (transcoding hexBinary streambuf)
* Fixed bug in hoisting through try-catch expr
* Fixed bug #1162631 (format-integer 'w' format of negative numbers)
* Fixed bug #1190261 (relative paths bug in file module)
=== modified file 'include/zorba/util/base64_stream.h'
--- include/zorba/util/base64_stream.h 2013-06-12 00:21:05 +
+++ include/zorba/util/base64_stream.h 2013-06-20 00:55:33 +
@@ -198,7 +198,7 @@
* destroyed.
* \code
* void f( ostream os ) {
- *base64::auto_attachostream const raii( os, ISO-8859-1 );
+ *base64::auto_attachostream const raii( os );
*// ...
* }
* \endcode
=== added file 'include/zorba/util/hexbinary_stream.h'
--- include/zorba/util/hexbinary_stream.h 1970-01-01 00:00:00 +
+++ include/zorba/util/hexbinary_stream.h 2013-06-20 00:55:33 +
@@ -0,0 +1,310 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ZORBA_HEXBINARY_STREAM_API_H
+#define ZORBA_HEXBINARY_STREAM_API_H
+
+#include streambuf
+
+#include zorba/config.h
+#include zorba/internal/cxx_util.h
+#include zorba/internal/streambuf.h
+
+namespace zorba {
+namespace hexbinary {
+
+///
+
+/**
+ * A %hexbinary::streambuf is-a std::streambuf for encoding to and decoding
+ * from HexBinary on-the-fly.
+ *
+ * To use it, replace a stream's streambuf:
+ * \code
+ * istream is;
+ * // ...
+ * hexbinary::streambuf hb_buf( is.rdbuf() );
+ * is.ios::rdbuf( hb_buf );
+ * \endcode
+ * Note that the %hexbinary::streambuf must exist for as long as it's being
+ * used by the stream. If you are replacing the streabuf for a stream you did
+ * not create, you should set it back to the original streambuf:
+ * \code
+ * void f( ostream os ) {
+ *hexbinary::streambuf hb_buf( os.rdbuf() );
+ *try {
+ * os.ios::rdbuf( hb_buf );
+ * // ...
+ *}
+ *catch ( ... ) {
+ * os.ios::rdbuf( hb_buf.orig_streambuf() );
+ * throw;
+ *}
+ *os.ios::rdbuf( hb_buf.orig_streambuf() );
+ * }
+ * \endcode
+ * Alternatively, you may wish to use either \c attach(), \c auto_attach, or
+ * \c hexbinary::stream instead.
+ *
+ * While %hexbinary::streambuf does support seeking, the positions are relative
+ * to the original byte stream.
+ */
+class ZORBA_DLL_PUBLIC streambuf : public std::streambuf {
+public:
+ /**
+ * Constructs a %hexbinary::streambuf.
+ *
+ * @param orig The original streambuf to read/write from/to.
+ * @throws std::invalid_argument if is not supported or \a orig is null.
+ */
+ streambuf( std::streambuf *orig );
+
+ /**
+ * Gets the original streambuf.
+ *
+ * @return said streambuf.
+ */
+ std::streambuf* orig_streambuf() const {
+return orig_buf_;
+ }
+
+protected:
+ void imbue( std::locale const );
+ pos_type seekoff( off_type, std::ios_base::seekdir, std::ios_base::openmode );
+ pos_type seekpos( pos_type, std::ios_base::openmode );
+ std::streambuf* setbuf( char_type*, std::streamsize );
+ std::streamsize showmanyc();
+ int_type overflow( int_type );
+ int_type pbackfail( int_type );
+ int_type underflow();
+ std::streamsize xsgetn( char_type*, std::streamsize );
+ std::streamsize xsputn( char_type const*, std::streamsize );
+
+private:
+ std::streambuf *orig_buf_;
+ char gbuf_[2];
+
+ void clear();
+
+ // forbid
+ streambuf( streambuf const );
+ streambuf operator=( streambuf const );
+};
+