* @brief Will be called by the `PySequence_Contains` to check the presence of a string in array. * @return 1 if the string is present, 0 if it is not, -1 in case of error. * @see Docs: https://docs.python.org/3/c-api/sequence.html#c.PySequence_Contains */
| 2181 | * @see Docs: https://docs.python.org/3/c-api/sequence.html#c.PySequence_Contains |
| 2182 | */ |
| 2183 | static int Strs_in(Str *self, PyObject *needle_obj) { |
| 2184 | |
| 2185 | // Validate and convert `needle` |
| 2186 | sz_string_view_t needle; |
| 2187 | if (!sz_py_export_string_like(needle_obj, &needle.start, &needle.length)) { |
| 2188 | wrap_current_exception("The needle argument must be string-like"); |
| 2189 | return -1; |
| 2190 | } |
| 2191 | |
| 2192 | // Depending on the layout, we will need to use different logic |
| 2193 | Py_ssize_t count = Strs_len(self); |
| 2194 | get_string_at_offset_t getter = str_at_offset_getter(self); |
| 2195 | if (!getter) { |
| 2196 | PyErr_SetString(PyExc_TypeError, "Unknown Strs kind"); |
| 2197 | return -1; |
| 2198 | } |
| 2199 | |
| 2200 | // Time for a full-scan |
| 2201 | for (Py_ssize_t i = 0; i < count; ++i) { |
| 2202 | PyObject *parent = NULL; |
| 2203 | sz_cptr_t start = NULL; |
| 2204 | sz_size_t length = 0; |
| 2205 | getter(self, i, count, &parent, &start, &length); |
| 2206 | if (length == needle.length && sz_equal(start, needle.start, needle.length) == sz_true_k) return 1; |
| 2207 | } |
| 2208 | |
| 2209 | return 0; |
| 2210 | } |
| 2211 | |
| 2212 | static PyObject *Str_richcompare(PyObject *self, PyObject *other, int op) { |
| 2213 |
nothing calls this directly
no test coverage detected
searching dependent graphs…