Browse Source

More efficient form for PyString_AsStringEx

Michael Hansen 12 years ago
parent
commit
767b0622d9
  1. 20
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

20
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

@ -49,14 +49,18 @@ plString PyString_AsStringEx(PyObject* obj)
{
if (PyString_Check(obj))
return plString::FromUtf8(PyString_AsString(obj));
else if (PyUnicode_Check(obj))
{
PyObject* utf8 = PyUnicode_AsUTF8String(obj);
plString str = plString::FromUtf8(PyString_AsString(utf8));
Py_DECREF(utf8);
return str;
} else
return plString::Null;
if (PyUnicode_Check(obj)) {
#if (Py_UNICODE_SIZE == 2)
return plString::FromUtf16(reinterpret_cast<const uint16_t *>(PyUnicode_AsUnicode(obj)));
#elif (Py_UNICODE_SIZE == 4)
return plString::FromUtf32(reinterpret_cast<const UniChar *>(PyUnicode_AsUnicode(obj)));
#else
# error "Py_UNICODE is an unexpected size"
#endif
}
return plString::Null;
}
bool PyString_CheckEx(PyObject* obj)

Loading…
Cancel
Save