mirror of
https://github.com/jezhiggins/arabica
synced 2024-12-27 21:58:30 +01:00
codecvt workarounds -
some implementations don't provide function bodies for the codecvt template clase - I need to check spec on this some implementations have an opaque definition of std::mbstate_t which means it's actually exceeding difficult to use :)
This commit is contained in:
parent
fdb2825e52
commit
f356c2cf10
5 changed files with 38 additions and 25 deletions
|
@ -23,6 +23,8 @@ define pasty(ARABICA, _NO_WCHAR_T) 1
|
|||
#if (_MSC_VER < 1300)
|
||||
define ARABICA_VS6_WORKAROUND
|
||||
#endif
|
||||
|
||||
define ARABICA_NO_CODECVT_SPECIALISATIONS
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
22
SAX/Makefile
22
SAX/Makefile
|
@ -32,18 +32,22 @@ LDFLAGS += $(DYNAMIC_LIBS)
|
|||
# SOURCE FILES
|
||||
SRCS = saxlib.cpp \
|
||||
helpers/InputSourceResolver.cpp \
|
||||
../Utils/rot13codecvt.cpp \
|
||||
../Utils/utf8ucs2codecvt.cpp \
|
||||
../Utils/impl/ucs2_utf8.cpp \
|
||||
../Utils/utf16beucs2codecvt.cpp \
|
||||
../Utils/utf16leucs2codecvt.cpp \
|
||||
../Utils/impl/ucs2_utf16.cpp \
|
||||
../Utils/iso88591utf8codecvt.cpp \
|
||||
../Utils/utf8iso88591codecvt.cpp \
|
||||
../Utils/impl/iso88591_utf8.cpp \
|
||||
../Utils/utf16utf8codecvt.cpp \
|
||||
../Utils/base64codecvt.cpp \
|
||||
../XML/XMLCharacterClasses.cpp
|
||||
# ../Utils/base64codecvt.cpp \
|
||||
# ../Utils/iso88591utf8codecvt.cpp \
|
||||
# ../Utils/rot13codecvt.cpp \
|
||||
# ../Utils/utf16beucs2codecvt.cpp \
|
||||
# ../Utils/utf16leucs2codecvt.cpp \
|
||||
# ../Utils/utf16utf8codecvt.cpp \
|
||||
# ../Utils/utf8iso88591codecvt.cpp \
|
||||
# ../Utils/impl/iso88591_utf8.cpp \
|
||||
# ../Utils/impl/ucs2_utf16.cpp \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HDRS = $(patsubst %.c,%.h,$(patsubst %.cpp,%.h,$(SRCS)))
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
static const std::string base64_charset("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
||||
static const int NO_MORE = 256;
|
||||
|
||||
std::codecvt_base::result base64codecvt::do_out(state_t& state,
|
||||
std::codecvt_base::result base64codecvt::do_out(std::mbstate_t& state,
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
const char*& from_next,
|
||||
|
@ -67,7 +67,7 @@ std::codecvt_base::result base64codecvt::do_out(state_t& state,
|
|||
return ((getState() == 0) && (getCurrentOutChar() == NO_MORE) && (getPreviousChar() == 0)) ? std::codecvt_base::ok : std::codecvt_base::partial;
|
||||
} // do_out
|
||||
|
||||
std::codecvt_base::result base64codecvt::do_in(state_t& state,
|
||||
std::codecvt_base::result base64codecvt::do_in(std::mbstate_t& state,
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
const char*& from_next,
|
||||
|
@ -109,7 +109,7 @@ std::codecvt_base::result base64codecvt::do_in(state_t& state,
|
|||
return (from_next == from_end) ? std::codecvt_base::ok : std::codecvt_base::partial;
|
||||
} // do_in
|
||||
|
||||
std::codecvt_base::result base64codecvt::do_unshift(state_t& state,
|
||||
std::codecvt_base::result base64codecvt::do_unshift(std::mbstate_t& state,
|
||||
char* to,
|
||||
char* to_limit,
|
||||
char*& to_next) const
|
||||
|
@ -126,7 +126,7 @@ std::codecvt_base::result base64codecvt::do_unshift(state_t& state,
|
|||
return (to_next == to_limit) ? codecvt_base::ok : codecvt_base::partial;
|
||||
} // do_unshift
|
||||
|
||||
int base64codecvt::do_length(const state_t&,
|
||||
int base64codecvt::do_length(const std::mbstate_t&,
|
||||
const char* from,
|
||||
const char* end,
|
||||
size_t max) const
|
||||
|
@ -158,7 +158,7 @@ int base64codecvt::getState() const
|
|||
|
||||
void base64codecvt::nextState() const
|
||||
{
|
||||
state_t s = getState();
|
||||
int s = getState();
|
||||
s = s + 1;
|
||||
if(s == 4)
|
||||
s = 0;
|
||||
|
|
|
@ -8,15 +8,18 @@
|
|||
|
||||
#include <locale>
|
||||
|
||||
class base64codecvt : public std::codecvt<char, char, int>
|
||||
{
|
||||
public:
|
||||
typedef int state_t;
|
||||
#ifdef ARABICA_VS6_WORKAROUND
|
||||
namespace std {
|
||||
typedef ::mbstate_t mbstate_t;
|
||||
}
|
||||
#endif
|
||||
|
||||
class base64codecvt : public std::codecvt<char, char, std::mbstate_t>
|
||||
{
|
||||
protected:
|
||||
virtual ~base64codecvt() { }
|
||||
|
||||
virtual result do_out(state_t& state,
|
||||
virtual result do_out(std::mbstate_t& state,
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
const char*& from_next,
|
||||
|
@ -24,7 +27,7 @@ protected:
|
|||
char* to_limit,
|
||||
char*& to_next) const;
|
||||
|
||||
virtual result do_in(state_t& state,
|
||||
virtual result do_in(std::mbstate_t& state,
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
const char*& from_next,
|
||||
|
@ -32,7 +35,7 @@ protected:
|
|||
char* to_limit,
|
||||
char*& to_next) const;
|
||||
|
||||
virtual result do_unshift(state_t& state,
|
||||
virtual result do_unshift(std::mbstate_t& state,
|
||||
char* to,
|
||||
char* to_limit,
|
||||
char*& to_next) const;
|
||||
|
@ -41,7 +44,7 @@ protected:
|
|||
|
||||
virtual bool do_always_noconv() const throw() { return false; }
|
||||
|
||||
virtual int do_length(const state_t&,
|
||||
virtual int do_length(const std::mbstate_t&,
|
||||
const char* from,
|
||||
const char* end,
|
||||
size_t max) const;
|
||||
|
@ -53,10 +56,10 @@ private:
|
|||
// 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)
|
||||
mutable state_t* state_;
|
||||
mutable int* state_;
|
||||
mutable const char** from_next_;
|
||||
mutable const char** from_end_;
|
||||
void grabState(state_t& state) const { state_ = &state; }
|
||||
void grabState(std::mbstate_t& state) const { state_ = reinterpret_cast<int*>(&state); }
|
||||
void grabFromNext(const char*& from_next) const { from_next_ = &from_next; }
|
||||
void grabFromEnd(const char*& from_end) const { from_end_ = &from_end; }
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
//---------------------------------------------------------------------------
|
||||
#include <locale>
|
||||
|
||||
#if(_MSC_VER < 1300)
|
||||
#ifndef ARABICA_NO_CODECVT_SPECIALISATIONS
|
||||
#include <Utils/impl/codecvt_specialisations.h>
|
||||
#endif
|
||||
#ifdef ARABICA_VS6_WORKAROUND
|
||||
namespace std {
|
||||
typedef ::mbstate_t mbstate_t;
|
||||
}
|
||||
|
@ -59,3 +62,4 @@ protected:
|
|||
}; // class utf16utf8codecvt
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue