mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Simplify podofo str->unicode conversion
This commit is contained in:
parent
91b812b718
commit
3255ecbcf1
@ -394,7 +394,6 @@ PDFDoc_version_getter(PDFDoc *self, void *closure) {
|
||||
static PyObject *
|
||||
PDFDoc_getter(PDFDoc *self, int field)
|
||||
{
|
||||
PyObject *ans;
|
||||
PdfString s;
|
||||
PdfInfo *info = self->doc->GetInfo();
|
||||
if (info == NULL) {
|
||||
@ -419,13 +418,7 @@ PDFDoc_getter(PDFDoc *self, int field)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ans = podofo_convert_pdfstring(s);
|
||||
if (ans == NULL) {PyErr_NoMemory(); return NULL;}
|
||||
PyObject *uans = PyUnicode_FromEncodedObject(ans, "utf-8", "replace");
|
||||
Py_DECREF(ans);
|
||||
if (uans == NULL) {return NULL;}
|
||||
Py_INCREF(uans);
|
||||
return uans;
|
||||
return podofo_convert_pdfstring(s);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -25,8 +25,7 @@ pdf::podofo_set_exception(const PdfError &err) {
|
||||
|
||||
PyObject *
|
||||
pdf::podofo_convert_pdfstring(const PdfString &s) {
|
||||
std::string raw = s.GetStringUtf8();
|
||||
return PyBytes_FromStringAndSize(raw.c_str(), raw.length());
|
||||
return PyUnicode_FromString(s.GetStringUtf8().c_str());
|
||||
}
|
||||
|
||||
PdfString *
|
||||
|
Loading…
x
Reference in New Issue
Block a user