arabica/Utils/utf8ucs2codecvt.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

2003-08-29 23:09:00 +02:00
//---------------------------------------------------------------------------
// $Id$
//---------------------------------------------------------------------------
2003-09-02 13:23:52 +02:00
#include "utf8ucs2codecvt.h"
2003-09-10 14:40:58 +02:00
#ifndef ARABICA_NO_WCHAR_T
#include "impl/ucs2_utf16.h"
2003-09-02 13:23:52 +02:00
#include "impl/ucs2_utf8.h"
2003-08-29 23:09:00 +02:00
//---------------------------------------------------------------------------
2003-09-11 16:05:18 +02:00
using namespace Arabica::convert;
2003-09-02 13:23:52 +02:00
std::codecvt_base::result utf8ucs2codecvt::do_out(std::mbstate_t& /* state */,
2003-08-29 23:09:00 +02:00
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_out
2003-09-02 13:23:52 +02:00
std::codecvt_base::result utf8ucs2codecvt::do_in(std::mbstate_t& /* state */,
2003-08-29 23:09:00 +02:00
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_in
2003-09-02 13:23:52 +02:00
std::codecvt_base::result utf8ucs2codecvt::do_unshift(std::mbstate_t& /* state */,
2003-08-29 23:09:00 +02:00
char* to,
char* /* to_limit */,
char*& to_next) const
{
to_next = to;
return noconv;
} // do_unshift
2003-09-02 13:23:52 +02:00
int utf8ucs2codecvt::do_length(const std::mbstate_t&,
2003-08-29 23:09:00 +02:00
const char* from,
const char* end,
size_t max) const
{
size_t count(0);
const char* from_next = from;
while((from_next < end) && (count < max))
{
if(!(*from_next & 0x80))
{
++count;
++from_next;
}
else if((*from_next&0xc0) == 0xc0)
{
if(from_next+2 < end)
{
++count;
from_next += 2;
}
else
break;
}
else if((*from_next&0xe0) == 0xe0)
{
if(from_next+3 < end)
{
++count;
from_next += 3;
}
else
break;
}
} // while
return (from_next-from);
} // do_length
2003-09-10 14:40:58 +02:00
#endif // ARABICA_NO_WCHAR_T
2003-08-29 23:09:00 +02:00
// end of file
2003-09-09 15:09:48 +02:00