aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken/sbkstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/libshiboken/sbkstring.cpp')
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp53
1 files changed, 2 insertions, 51 deletions
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index 918aae756..ca32f5919 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -58,20 +58,12 @@ bool checkIterable(PyObject *obj)
bool checkType(PyTypeObject *type)
{
- return type == &PyUnicode_Type
-#if PY_MAJOR_VERSION < 3
- || type == &PyString_Type
-#endif
- ;
+ return type == &PyUnicode_Type;
}
bool check(PyObject *obj)
{
- return obj == Py_None ||
-#if PY_MAJOR_VERSION < 3
- PyString_Check(obj) ||
-#endif
- PyUnicode_Check(obj);
+ return obj == Py_None || PyUnicode_Check(obj);
}
bool checkChar(PyObject *pyobj)
@@ -86,20 +78,12 @@ bool isConvertible(PyObject *obj)
PyObject *fromCString(const char *value)
{
-#ifdef IS_PY3K
return PyUnicode_FromString(value);
-#else
- return PyBytes_FromString(value);
-#endif
}
PyObject *fromCString(const char *value, int len)
{
-#ifdef IS_PY3K
return PyUnicode_FromStringAndSize(value, len);
-#else
- return PyBytes_FromStringAndSize(value, len);
-#endif
}
const char *toCString(PyObject *str, Py_ssize_t *len)
@@ -112,17 +96,9 @@ const char *toCString(PyObject *str, Py_ssize_t *len)
Shiboken::AutoDecRef uniStr(PyUnicode_AsUTF8String(str));
*len = PyBytes_GET_SIZE(uniStr.object());
}
-#ifdef IS_PY3K
// Return unicode from str instead of uniStr, because the lifetime of the returned pointer
// depends on the lifetime of str.
return _PepUnicode_AsString(str);
-#else
- str = PyUnicode_AsUTF8String(str);
- if (str == NULL) {
- return NULL;
- }
- return PyString_AsString(str);
-#endif
}
if (PyBytes_Check(str)) {
if (len)
@@ -146,12 +122,6 @@ bool concat(PyObject **val1, PyObject *val2)
return true;
}
-#if PY_MAJOR_VERSION < 3
- if (PyString_Check(*val1) && PyString_Check(val2)) {
- PyString_Concat(val1, val2);
- return true;
- }
-#endif
return false;
}
@@ -160,39 +130,20 @@ PyObject *fromFormat(const char *format, ...)
va_list argp;
va_start(argp, format);
PyObject *result = nullptr;
-#ifdef IS_PY3K
result = PyUnicode_FromFormatV(format, argp);
-#else
- result = PyString_FromFormatV(format, argp);
-#endif
va_end(argp);
return result;
}
PyObject *fromStringAndSize(const char *str, Py_ssize_t size)
{
-#ifdef IS_PY3K
return PyUnicode_FromStringAndSize(str, size);
-#else
- return PyString_FromStringAndSize(str, size);
-#endif
}
int compare(PyObject *val1, const char *val2)
{
if (PyUnicode_Check(val1))
-#ifdef IS_PY3K
return PyUnicode_CompareWithASCIIString(val1, val2);
-#else
- {
- PyObject *uVal2 = PyUnicode_FromString(val2);
- bool result = PyUnicode_Compare(val1, uVal2);
- Py_XDECREF(uVal2);
- return result;
- }
- if (PyString_Check(val1))
- return strcmp(PyString_AS_STRING(val1), val2);
-#endif
return 0;
}