arabica/Utils/utf16utf8codecvt.cpp

66 lines
2.1 KiB
C++
Raw Normal View History

2003-08-29 23:09:00 +02:00
//---------------------------------------------------------------------------
// $Id$
//---------------------------------------------------------------------------
#include "utf16utf8codecvt.h"
2003-09-02 13:23:52 +02:00
#include "impl/ucs2_utf8.h"
2003-08-29 23:09:00 +02:00
//---------------------------------------------------------------------------
// This facet converts from wide chars to char using the
// FSS-UTF (UCS2) encoding.
//
2003-09-11 16:05:18 +02:00
using namespace Arabica::convert;
2003-08-29 23:09:00 +02:00
std::codecvt_base::result utf16utf8codecvt::do_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 Arabica::Internal::utf8_2_ucs2(from, from_end, from_next, to, to_limit, to_next);
2003-08-29 23:09:00 +02:00
} // do_out
std::codecvt_base::result utf16utf8codecvt::do_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 Arabica::Internal::ucs2_2_utf8(from, from_end, from_next, to, to_limit, to_next);
2003-08-29 23:09:00 +02:00
} // do_in
std::codecvt_base::result utf16utf8codecvt::do_unshift(std::mbstate_t& /* state */,
wchar_t* to,
wchar_t* /* to_limit */,
wchar_t*& to_next) const
{
to_next = to;
2003-09-13 01:15:14 +02:00
return std::codecvt_base::noconv;
2003-08-29 23:09:00 +02:00
} // do_unshift
int utf16utf8codecvt::do_length(const std::mbstate_t&,
const wchar_t* from,
const wchar_t* end,
size_t max) const
{
size_t count(0);
const wchar_t* from_next = from;
while((from_next < end) && (count < max))
{
if(*from_next > 0x7FF)
++count;
if(*from_next > 0x7F)
++count;
++count;
++from_next;
} // while
return (from_next-from);
} // do_length
// end of file
2003-09-09 15:09:48 +02:00