2003-08-29 15:34:01 +02:00
|
|
|
#ifndef ARABICA_BASE64_CODECVT_H
|
|
|
|
#define ARABICA_BASE64_CODECVT_H
|
2002-08-30 17:52:22 +02:00
|
|
|
///////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <locale>
|
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
#ifdef ARABICA_VS6_WORKAROUND
|
|
|
|
namespace std {
|
|
|
|
typedef ::mbstate_t mbstate_t;
|
|
|
|
}
|
|
|
|
#endif
|
2002-09-02 17:52:19 +02:00
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
class base64codecvt : public std::codecvt<char, char, std::mbstate_t>
|
|
|
|
{
|
2002-08-30 17:52:22 +02:00
|
|
|
protected:
|
2003-08-29 15:34:01 +02:00
|
|
|
virtual ~base64codecvt() { }
|
2002-08-30 17:52:22 +02:00
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
virtual result do_out(std::mbstate_t& state,
|
2002-08-30 17:52:22 +02:00
|
|
|
const char* from,
|
|
|
|
const char* from_end,
|
|
|
|
const char*& from_next,
|
|
|
|
char* to,
|
|
|
|
char* to_limit,
|
|
|
|
char*& to_next) const;
|
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
virtual result do_in(std::mbstate_t& state,
|
2002-08-30 17:52:22 +02:00
|
|
|
const char* from,
|
|
|
|
const char* from_end,
|
|
|
|
const char*& from_next,
|
|
|
|
char* to,
|
|
|
|
char* to_limit,
|
|
|
|
char*& to_next) const;
|
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
virtual result do_unshift(std::mbstate_t& state,
|
2002-08-30 17:52:22 +02:00
|
|
|
char* to,
|
|
|
|
char* to_limit,
|
|
|
|
char*& to_next) const;
|
|
|
|
|
2003-08-29 15:34:01 +02:00
|
|
|
virtual int do_encoding() const throw() { return -1; }
|
2002-08-30 17:52:22 +02:00
|
|
|
|
2003-08-29 15:34:01 +02:00
|
|
|
virtual bool do_always_noconv() const throw() { return false; }
|
2002-08-30 17:52:22 +02:00
|
|
|
|
2003-09-10 12:39:01 +02:00
|
|
|
virtual int do_length(const std::mbstate_t&,
|
2002-08-30 17:52:22 +02:00
|
|
|
const char* from,
|
|
|
|
const char* end,
|
|
|
|
size_t max) const;
|
|
|
|
|
2002-09-02 17:52:19 +02:00
|
|
|
virtual int do_max_length() const throw();
|
2002-08-30 17:52:22 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// state here is a little tricky - we need the previous char and
|
|
|
|
// the state counter, and in some case we need to "pad" the input
|
|
|
|
// strings. I use these helper functions to mungle them
|
|
|
|
// together and keep the details neater (or try to anyway)
|
2003-09-10 12:39:01 +02:00
|
|
|
mutable int* state_;
|
2002-08-30 17:52:22 +02:00
|
|
|
mutable const char** from_next_;
|
|
|
|
mutable const char** from_end_;
|
2003-09-10 13:47:39 +02:00
|
|
|
void grabState(std::mbstate_t& state) const;
|
2002-08-30 17:52:22 +02:00
|
|
|
void grabFromNext(const char*& from_next) const { from_next_ = &from_next; }
|
|
|
|
void grabFromEnd(const char*& from_end) const { from_end_ = &from_end; }
|
|
|
|
|
2002-09-02 17:52:19 +02:00
|
|
|
int getState() const;
|
2002-08-30 17:52:22 +02:00
|
|
|
void nextState() const;
|
|
|
|
int getCurrentOutChar() const;
|
|
|
|
void consumeOutChar() const;
|
|
|
|
char getPreviousChar() const;
|
|
|
|
void setPreviousChar(char c) const;
|
2003-08-29 15:34:01 +02:00
|
|
|
}; // class base64codecvt
|
2002-08-30 17:52:22 +02:00
|
|
|
|
|
|
|
#endif
|