aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-10-04 16:06:02 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:18:19 -0300
commit181a0e9d43c7a95bf78dd0269b357ed4f5ade2a3 (patch)
treeb0eb7435de2a19a1f1837429d624d9d7d5a03464
parent3de584066e350e4b8cf269e5a3729a0d319f9ce3 (diff)
Updated Shiboken::String functions.
-rw-r--r--libshiboken/sbkstring.cpp26
-rw-r--r--libshiboken/sbkstring.h2
2 files changed, 28 insertions, 0 deletions
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
diff --git a/libshiboken/sbkstring.h b/libshiboken/sbkstring.h
index 13aa25ef2..214acc1d5 100644
--- a/libshiboken/sbkstring.h
+++ b/libshiboken/sbkstring.h
@@ -37,6 +37,8 @@ namespace Shiboken
namespace String
{
LIBSHIBOKEN_API bool check(PyObject* obj);
+ LIBSHIBOKEN_API bool checkType(PyTypeObject* obj);
+ LIBSHIBOKEN_API bool checkChar(PyObject* obj);
LIBSHIBOKEN_API bool convertible(PyObject* obj);
LIBSHIBOKEN_API PyObject* fromCString(const char* value);
LIBSHIBOKEN_API const char* toCString(PyObject* str);