dtoolutil: minor fix to TextEncoder::append_text

This commit is contained in:
rdb 2018-10-15 13:27:36 +02:00
parent 2d80d6d063
commit d7f19b73e0

View File

@ -94,7 +94,12 @@ append_text(PyObject *text) {
#if PY_VERSION_HEX >= 0x03030000
Py_ssize_t len;
const char *str = PyUnicode_AsUTF8AndSize(text, &len);
_this->append_text(std::string(str, len));
std::string text_str(str, len);
if (_this->get_encoding() == TextEncoder::E_utf8) {
_this->append_text(text_str);
} else {
_this->append_wtext(TextEncoder::decode_text(text_str, TextEncoder::E_utf8));
}
#else
Py_ssize_t len = PyUnicode_GET_SIZE(text);
wchar_t *str = (wchar_t *)alloca(sizeof(wchar_t) * (len + 1));