* The only purpose of this function is that it allows the "rstrip". * From my (@seberg's) perspective, this function should be deprecated * and I do not think it matters if it is not particularly fast. */
| 3955 | * and I do not think it matters if it is not particularly fast. |
| 3956 | */ |
| 3957 | static PyObject * |
| 3958 | compare_chararrays(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds) |
| 3959 | { |
| 3960 | PyObject *array; |
| 3961 | PyObject *other; |
| 3962 | PyArrayObject *newarr, *newoth; |
| 3963 | int cmp_op; |
| 3964 | npy_bool rstrip; |
| 3965 | char *cmp_str; |
| 3966 | Py_ssize_t strlength; |
| 3967 | PyObject *res = NULL; |
| 3968 | static char msg[] = "comparison must be '==', '!=', '<', '>', '<=', '>='"; |
| 3969 | static char *kwlist[] = {"a1", "a2", "cmp", "rstrip", NULL}; |
| 3970 | |
| 3971 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOs#O&:compare_chararrays", |
| 3972 | kwlist, |
| 3973 | &array, &other, &cmp_str, &strlength, |
| 3974 | PyArray_BoolConverter, &rstrip)) { |
| 3975 | return NULL; |
| 3976 | } |
| 3977 | if (strlength < 1 || strlength > 2) { |
| 3978 | goto err; |
| 3979 | } |
| 3980 | if (strlength > 1) { |
| 3981 | if (cmp_str[1] != '=') { |
| 3982 | goto err; |
| 3983 | } |
| 3984 | if (cmp_str[0] == '=') { |
| 3985 | cmp_op = Py_EQ; |
| 3986 | } |
| 3987 | else if (cmp_str[0] == '!') { |
| 3988 | cmp_op = Py_NE; |
| 3989 | } |
| 3990 | else if (cmp_str[0] == '<') { |
| 3991 | cmp_op = Py_LE; |
| 3992 | } |
| 3993 | else if (cmp_str[0] == '>') { |
| 3994 | cmp_op = Py_GE; |
| 3995 | } |
| 3996 | else { |
| 3997 | goto err; |
| 3998 | } |
| 3999 | } |
| 4000 | else { |
| 4001 | if (cmp_str[0] == '<') { |
| 4002 | cmp_op = Py_LT; |
| 4003 | } |
| 4004 | else if (cmp_str[0] == '>') { |
| 4005 | cmp_op = Py_GT; |
| 4006 | } |
| 4007 | else { |
| 4008 | goto err; |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | newarr = (PyArrayObject *)PyArray_FROM_O(array); |
| 4013 | if (newarr == NULL) { |
| 4014 | return NULL; |
no test coverage detected