arabica/include/convert/impl/codecvt_specialisations.hpp

132 lines
3.6 KiB
C++
Raw Normal View History

#ifndef ARABICA_IMPL_CODECVT_SPECIALISATIONS_H
#define ARABICA_IMPL_CODECVT_SPECIALISATIONS_H
#include <locale>
namespace std
{
template<>
2006-05-19 20:48:17 +02:00
class codecvt<char, wchar_t, std::mbstate_t> :
public locale::facet, public codecvt_base
{
2006-05-19 20:48:17 +02:00
public:
static locale::id id;
codecvt_base::result out(std::mbstate_t& state,
const char* from,
const char* from_end,
const char*& from_next,
wchar_t* to,
wchar_t* to_limit,
wchar_t*& to_next) const
{
return this->do_out(state, from, from_end, from_next, to, to_limit, to_next);
} // out
codecvt_base::result in(std::mbstate_t& state,
const wchar_t* from,
const wchar_t* from_end,
const wchar_t*& from_next,
char* to,
char* to_limit,
char*& to_next) const
{
return this->do_in(state, from, from_end, from_next, to, to_limit, to_next);
} // in
int encoding() const throw()
{
return this->do_encoding();
} // encoding
bool always_noconv() const throw()
{
return this->do_always_noconv();
} // always_noconv
int length(std::mbstate_t& state,
const wchar_t* from,
const wchar_t* end,
size_t max) const
{
return this->do_length(state, from, end, max);
} // length
protected:
2006-05-05 15:19:47 +02:00
virtual ~codecvt() { }
2005-08-07 22:16:02 +02:00
2006-05-19 20:48:17 +02:00
virtual codecvt_base::result do_out(std::mbstate_t&,
2003-09-13 01:15:14 +02:00
const char* from,
const char* from_end,
const char*& from_next,
wchar_t* to,
wchar_t* to_limit,
2006-05-05 15:19:47 +02:00
wchar_t*& to_next) const
{
int limit = std::max<int>(from_end - from, to_limit - to);
from_next = from;
to_next = to;
while(limit--)
*to_next++ = static_cast<wchar_t>(*from_next++);
return codecvt_base::ok;
} // do_out
2003-09-13 01:15:14 +02:00
2006-05-19 20:48:17 +02:00
virtual codecvt_base::result do_in(std::mbstate_t&,
2003-09-13 01:15:14 +02:00
const wchar_t* from,
const wchar_t* from_end,
const wchar_t*& from_next,
char* to,
char* to_limit,
2006-05-05 15:19:47 +02:00
char*& to_next) const
{
int limit = std::max<int>(from_end - from, to_limit - to);
from_next = from;
to_next = to;
while(limit--)
*to_next++ = static_cast<char>(*from_next++);
return codecvt_base::ok;
} // do_in
2003-09-13 01:15:14 +02:00
2006-05-19 20:48:17 +02:00
virtual codecvt_base::result do_unshift(std::mbstate_t&,
2003-09-13 01:15:14 +02:00
wchar_t* to,
wchar_t* /*to_limit*/,
2006-05-05 15:19:47 +02:00
wchar_t*& to_next) const
{
to_next = to;
return codecvt_base::noconv;
} // do_unshift
2003-09-13 01:15:14 +02:00
2006-05-05 15:19:47 +02:00
virtual int do_encoding() const throw()
{
return 1;
} // do_encoding
2003-09-13 01:15:14 +02:00
2006-05-05 15:19:47 +02:00
virtual bool do_always_noconv() const throw()
{
return false;
} // do_always_noconv
2006-05-19 20:48:17 +02:00
virtual int do_length(std::mbstate_t&,
const wchar_t* from,
const wchar_t* end,
2006-05-19 20:48:17 +02:00
size_t max) const
2006-05-05 15:19:47 +02:00
{
return std::min<int>(max, (end - from));
} // do_length
2003-09-13 01:15:14 +02:00
2006-05-05 15:19:47 +02:00
virtual int do_max_length() const throw()
{
return 1;
} // do_max_length
2003-09-13 01:15:14 +02:00
}; // class codecvt<char, wchar_t, std::mbstate_t> :
2003-09-13 01:15:14 +02:00
} // namespace std
#endif