32 #ifndef __KMIME_CODECS__
33 #define __KMIME_CODECS__
35 #include <tqasciidict.h>
36 #if defined(TQT_THREAD_SUPPORT)
40 #include <tqcstring.h>
43 #include <tdemacros.h>
60 static TQAsciiDict<Codec>* all;
61 #if defined(TQT_THREAD_SUPPORT)
62 static TQMutex* dictLock;
67 static void fillDictionary();
70 static Codec * codecForName(
const char * name );
71 static Codec * codecForName(
const TQCString & name );
73 virtual int maxEncodedSizeFor(
int insize,
bool withCRLF=
false )
const = 0;
74 virtual int maxDecodedSizeFor(
int insize,
bool withCRLF=
false )
const = 0;
76 virtual Encoder * makeEncoder(
bool withCRLF=
false )
const = 0;
77 virtual Decoder * makeDecoder(
bool withCRLF=
false )
const = 0;
111 virtual bool encode(
const char* & scursor,
const char *
const send,
112 char* & dcursor,
const char *
const dend,
113 bool withCRLF=
false )
const;
147 virtual bool decode(
const char* & scursor,
const char *
const send,
148 char* & dcursor,
const char *
const dend,
149 bool withCRLF=
false )
const;
158 virtual TQByteArray encode(
const TQByteArray & src,
bool withCRLF=
false )
const;
171 virtual TQCString encodeToTQCString(
const TQByteArray & src,
bool withCRLF=
false )
const;
180 virtual TQByteArray decode(
const TQByteArray & src,
bool withCRLF=
false )
const;
185 virtual const char * name()
const = 0;
277 : mWithCRLF( withCRLF ) {}
284 virtual bool decode(
const char* & scursor,
const char *
const send,
285 char* & dcursor,
const char *
const dend ) = 0;
290 virtual bool finish(
char* & dcursor,
const char *
const dend ) = 0;
293 const bool mWithCRLF;
307 : mOutputBufferCursor( 0 ), mWithCRLF( withCRLF ) {}
313 virtual bool encode(
const char* & scursor,
const char *
const send,
314 char* & dcursor,
const char *
const dend ) = 0;
319 virtual bool finish(
char* & dcursor,
const char *
const dend ) = 0;
323 enum { maxBufferedChars = 8 };
328 bool write(
char ch,
char* & dcursor,
const char *
const dend ) {
329 if ( dcursor != dend ) {
335 kdFatal( mOutputBufferCursor >= maxBufferedChars )
336 <<
"KMime::Encoder: internal buffer overflow!" << endl;
337 mOutputBuffer[ mOutputBufferCursor++ ] = ch;
350 bool writeCRLF(
char* & dcursor,
const char *
const dend ) {
352 write(
'\r', dcursor, dend );
353 return write(
'\n', dcursor, dend );
359 char mOutputBuffer[ maxBufferedChars ];
361 uchar mOutputBufferCursor;
362 const bool mWithCRLF;
367 #endif // __KMIME_CODECS__
virtual bool decode(const char *&scursor, const char *const send, char *&dcursor, const char *const dend)=0
Decode a chunk of data, maintaining state information between calls.
Stateful encoder class, modelled after TQTextEncoder.
Abstract base class of codecs like base64 and quoted-printable.
bool write(char ch, char *&dcursor, const char *const dend)
Writes ch to the output stream or the output buffer, depending on whether or not the output stream ha...
virtual bool finish(char *&dcursor, const char *const dend)=0
Call this method to finalize the output stream.
Stateful decoder class, modelled after TQTextDecoder.
virtual bool encode(const char *&scursor, const char *const send, char *&dcursor, const char *const dend)=0
Encode a chunk of data, maintaining state information between calls.
Decoder(bool withCRLF=false)
Protected constructor.
bool flushOutputBuffer(char *&dcursor, const char *const dend)
Writes characters from the output buffer to the output stream.
virtual bool finish(char *&dcursor, const char *const dend)=0
Call this method to finalize the output stream.
bool writeCRLF(char *&dcursor, const char *const dend)
Convenience function.
Encoder(bool withCRLF=false)
Protected constructor.