From 181a0e9d43c7a95bf78dd0269b357ed4f5ade2a3 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Tue, 4 Oct 2011 16:06:02 -0300 Subject: Updated Shiboken::String functions. --- libshiboken/sbkstring.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libshiboken/sbkstring.cpp') diff --git a/libshiboken/sbkstring.cpp b/libshiboken/sbkstring.cpp index d9de1a44f..ebe1efb2f 100644 --- a/libshiboken/sbkstring.cpp +++ b/libshiboken/sbkstring.cpp @@ -28,6 +28,16 @@ namespace Shiboken namespace String { +bool checkType(PyTypeObject* type) +{ +#if PY_MAJOR_VERSION >= 3 + return type == &PyUnicode_Type; +#else + return type == &PyString_Type || + type == &PyUnicode_Type; +#endif +} + bool check(PyObject* obj) { return obj == Py_None || @@ -38,6 +48,16 @@ bool check(PyObject* obj) #endif } +bool checkChar(PyObject* pyobj) +{ + if (PyBytes_Check(pyobj) && (PyBytes_GET_SIZE(pyobj) == 1)) + return true; + if (check(pyobj) && (len(pyobj) == 1)) + return true; + + return false; +} + bool convertible(PyObject* obj) { return check(obj); @@ -54,6 +74,8 @@ PyObject* fromCString(const char* value) const char* toCString(PyObject* str) { + if (str == Py_None) + return NULL; #if PY_MAJOR_VERSION >= 3 return _PyUnicode_AsString(str); #else @@ -108,6 +130,10 @@ int compare(PyObject* val1, const char* val2) Py_ssize_t len(PyObject* str) { + printf("TYPE NAME: %s\n", Py_TYPE(str)->tp_name); + if (str == Py_None) + return 0; + #if PY_MAJOR_VERSION >= 3 return PyUnicode_GET_SIZE(str); #else -- cgit v1.2.3