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 *
|
static PyObject *
|
||||||
PDFDoc_getter(PDFDoc *self, int field)
|
PDFDoc_getter(PDFDoc *self, int field)
|
||||||
{
|
{
|
||||||
PyObject *ans;
|
|
||||||
PdfString s;
|
PdfString s;
|
||||||
PdfInfo *info = self->doc->GetInfo();
|
PdfInfo *info = self->doc->GetInfo();
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
@ -419,13 +418,7 @@ PDFDoc_getter(PDFDoc *self, int field)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ans = podofo_convert_pdfstring(s);
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -25,8 +25,7 @@ pdf::podofo_set_exception(const PdfError &err) {
|
|||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
pdf::podofo_convert_pdfstring(const PdfString &s) {
|
pdf::podofo_convert_pdfstring(const PdfString &s) {
|
||||||
std::string raw = s.GetStringUtf8();
|
return PyUnicode_FromString(s.GetStringUtf8().c_str());
|
||||||
return PyBytes_FromStringAndSize(raw.c_str(), raw.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PdfString *
|
PdfString *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user