KMIME Library
kmime_codec_identity.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00035 #include "kmime_codec_identity.h"
00036
00037 #include <kdebug.h>
00038 #include <kglobal.h>
00039
00040 #include <QtCore/QByteArray>
00041
00042 #include <cassert>
00043 #include <cstring>
00044
00045 using namespace KMime;
00046
00047 namespace KMime {
00048
00049 class IdentityEnDecoder : public Encoder, public Decoder
00050 {
00051 protected:
00052 friend class IdentityCodec;
00053 IdentityEnDecoder( bool withCRLF ): Encoder( false )
00054 {
00055 kWarning( withCRLF, 5100 ) << "IdentityEnDecoder: withCRLF isn't yet supported!";
00056 }
00057
00058 public:
00059 ~IdentityEnDecoder() {}
00060
00061 bool encode( const char* &scursor, const char *const send,
00062 char* &dcursor, const char *const dend )
00063 { return decode( scursor, send, dcursor, dend ); }
00064
00065 bool decode( const char* &scursor, const char *const send,
00066 char* &dcursor, const char *const dend );
00067
00068 bool finish( char* &dcursor, const char *const dend )
00069 { Q_UNUSED( dcursor ); Q_UNUSED( dend ); return true; }
00070 };
00071
00072 Encoder *IdentityCodec::makeEncoder( bool withCRLF ) const
00073 {
00074 return new IdentityEnDecoder( withCRLF );
00075 }
00076
00077 Decoder *IdentityCodec::makeDecoder( bool withCRLF ) const
00078 {
00079 return new IdentityEnDecoder( withCRLF );
00080 }
00081
00082
00083
00084
00085
00086 bool IdentityEnDecoder::decode( const char* &scursor, const char *const send,
00087 char* &dcursor, const char *const dend )
00088 {
00089 const int size = qMin( send - scursor, dcursor - dend );
00090 if ( size > 0 ) {
00091 std::memmove( dcursor, scursor, size );
00092 dcursor += size;
00093 scursor += size;
00094 }
00095 return scursor == send;
00096 }
00097
00098 QByteArray IdentityCodec::encode( const QByteArray &src, bool withCRLF ) const
00099 {
00100 kWarning( withCRLF, 5100 ) << "IdentityCodec::encode(): withCRLF not yet supported!";
00101 return src;
00102 }
00103
00104 QByteArray IdentityCodec::decode( const QByteArray &src, bool withCRLF ) const
00105 {
00106 kWarning( withCRLF, 5100 ) << "IdentityCodec::decode(): withCRLF not yet supported!";
00107 return src;
00108 }
00109
00110 }