+ use UnicodeString->utf8->PyUnicode conversion

This commit is contained in:
Artem Pavlenko 2009-07-13 22:20:25 +00:00
parent 9872a3be7c
commit c83000eb60

View file

@ -48,29 +48,10 @@ namespace boost { namespace python {
PyObject * operator() (UnicodeString const& s) const
{
const int32_t BUF_SIZE = 2;
wchar_t buf[BUF_SIZE];
int32_t len = s.length();
int32_t dest_len=0;
UErrorCode err = U_ZERO_ERROR;
u_strToWCS(buf,BUF_SIZE,&dest_len,s.getBuffer(),len,&err);
std::string buffer;
mapnik::to_utf8(s,buffer);
PyObject *obj = Py_None;
if (err == U_BUFFER_OVERFLOW_ERROR || err == U_STRING_NOT_TERMINATED_WARNING)
{
err = U_ZERO_ERROR;
boost::scoped_array<wchar_t> buf_ptr(new wchar_t [dest_len+1]);
u_strToWCS(buf_ptr.get(),dest_len+1,0,s.getBuffer(),len,&err);
if (U_SUCCESS(err))
{
obj = ::PyUnicode_FromWideChar(buf_ptr.get(),implicit_cast<ssize_t>(dest_len));
}
}
else if (U_SUCCESS(err))
{
obj = ::PyUnicode_FromWideChar(buf,implicit_cast<ssize_t>(dest_len));
}
obj = ::PyUnicode_DecodeUTF8(buffer.c_str(),implicit_cast<ssize_t>(buffer.length()),0);
return obj;
}