libkmime

kmime_codec_identity.cpp
1/*
2 kmime_codec_identity.cpp
3
4 This file is part of KMime, the KDE internet mail/usenet news message library.
5 Copyright (c) 2004 Marc Mutz <mutz@kde.org>
6
7 KMime is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMime is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this library with any edition of
22 the TQt library by Trolltech AS, Norway (or with modified versions
23 of TQt that use the same license as TQt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 TQt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#include "kmime_codec_identity.h"
33
34#include <kdebug.h>
35#include <tdeglobal.h>
36
37#include <cassert>
38#include <cstring>
39
40using namespace KMime;
41
42namespace KMime {
43
44
45class IdentityEnDecoder : public Encoder, public Decoder {
46protected:
47 friend class IdentityCodec;
48 IdentityEnDecoder( bool withCRLF )
49 : Encoder( false )
50 {
51 kdWarning( withCRLF, 5100 ) << "IdentityEnDecoder: withCRLF isn't yet supported!" << endl;
52 }
53
54public:
55 ~IdentityEnDecoder() {}
56
57 bool encode( const char* & scursor, const char * const send,
58 char* & dcursor, const char * const dend ) {
59 return decode( scursor, send, dcursor, dend );
60 }
61 bool decode( const char* & scursor, const char * const send,
62 char* & dcursor, const char * const dend );
63 bool finish( char* & /*dcursor*/, const char * const /*dend*/ ) { return true; }
64};
65
66
67Encoder * IdentityCodec::makeEncoder( bool withCRLF ) const {
68 return new IdentityEnDecoder( withCRLF );
69}
70
71Decoder * IdentityCodec::makeDecoder( bool withCRLF ) const {
72 return new IdentityEnDecoder( withCRLF );
73}
74
75
76 /********************************************************/
77 /********************************************************/
78 /********************************************************/
79
80
81
82bool IdentityEnDecoder::decode( const char* & scursor, const char * const send,
83 char* & dcursor, const char * const dend )
84{
85 const int size = kMin( send - scursor, dcursor - dend );
86 if ( size > 0 ) {
87 std::memmove( dcursor, scursor, size );
88 dcursor += size;
89 scursor += size;
90 }
91 return scursor == send;
92}
93
94TQByteArray IdentityCodec::encode( const TQByteArray & src, bool withCRLF ) const {
95 kdWarning( withCRLF, 5100 ) << "IdentityCodec::encode(): withCRLF not yet supported!" << endl;
96 return src;
97}
98
99TQByteArray IdentityCodec::decode( const TQByteArray & src, bool withCRLF ) const {
100 kdWarning( withCRLF, 5100 ) << "IdentityCodec::decode(): withCRLF not yet supported!" << endl;
101 return src;
102}
103
104TQCString IdentityCodec::encodeToTQCString( const TQByteArray & src, bool withCRLF ) const {
105 kdWarning( withCRLF, 5100 ) << "IdentityCodec::encodeToTQCString(): withCRLF not yet supported!" << endl;
106 return TQCString( src.data(), src.size() + 1 );
107}
108
109} // namespace KMime
Stateful decoder class, modelled after TQTextDecoder.
Definition: kmime_codecs.h:268
Stateful encoder class, modelled after TQTextEncoder.
Definition: kmime_codecs.h:300