aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2005-10-20 06:30:49 +0000
committerVincent Richard <[email protected]>2005-10-20 06:30:49 +0000
commit5e41e4bd7ed8f5c803f5519cfcfce16989edc4d9 (patch)
tree6de77ad83d70343534f3d989016db6ea82824dfb
parentAdded 'charsetFilteredOutputStream'. (diff)
downloadvmime-5e41e4bd7ed8f5c803f5519cfcfce16989edc4d9.tar.gz
vmime-5e41e4bd7ed8f5c803f5519cfcfce16989edc4d9.zip
Added 'charsetFilteredOutputStream'.
-rw-r--r--vmime/charsetConverter.hpp59
-rw-r--r--vmime/vmime.hpp1
2 files changed, 60 insertions, 0 deletions
diff --git a/vmime/charsetConverter.hpp b/vmime/charsetConverter.hpp
index aa1ac4f5..9c465907 100644
--- a/vmime/charsetConverter.hpp
+++ b/vmime/charsetConverter.hpp
@@ -29,6 +29,7 @@
#include "vmime/component.hpp"
#include "vmime/charset.hpp"
+#include "vmime/utility/filteredStream.hpp"
namespace vmime
@@ -83,6 +84,64 @@ private:
};
+namespace utility {
+
+
+/** A filtered output stream which applies a charset conversion
+ * to input bytes.
+ *
+ * May throw a exceptions::charset_conv_error if an error
+ * occured when initializing convert, or during charset conversion.
+ */
+
+class charsetFilteredOutputStream : public filteredOutputStream
+{
+public:
+
+ /** Construct a new filter for the specified output stream.
+ *
+ * @param source input charset
+ * @param dest output charset
+ * @param os stream into which write filtered data
+ */
+ charsetFilteredOutputStream
+ (const charset& source, const charset& dest, outputStream& os);
+
+ ~charsetFilteredOutputStream();
+
+
+ outputStream& getNextOutputStream();
+
+ void write(const value_type* const data, const size_type count);
+
+private:
+
+ // Maximum character width in any charset
+ enum { MAX_CHARACTER_WIDTH = 128 };
+
+
+ void* m_desc;
+
+ const charset m_sourceCharset;
+ const charset m_destCharset;
+
+ outputStream& m_stream;
+
+ // Buffer in which unconverted bytes are left until they can
+ // be converted (when more data arrives). The length should be
+ // large enough to contain any character in any charset.
+ value_type m_unconvBuffer[MAX_CHARACTER_WIDTH];
+ size_type m_unconvCount;
+
+ // Buffer used for conversion. Avoids declaring it in write().
+ // Should be at least MAX_CHARACTER_WIDTH * MAX_CHARACTER_WIDTH.
+ value_type m_outputBuffer[32768];
+};
+
+
+} // utility
+
+
} // vmime
diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp
index c878ae60..337f91f2 100644
--- a/vmime/vmime.hpp
+++ b/vmime/vmime.hpp
@@ -91,6 +91,7 @@
// Utilities
#include "vmime/utility/datetimeUtils.hpp"
#include "vmime/utility/filteredStream.hpp"
+#include "vmime/charsetConverter.hpp"
// Security
#include "vmime/security/authenticator.hpp"