| 3517 | " 0"; |
| 3518 | |
| 3519 | static PyObject *Str_like_utf8_case_insensitive_find(PyObject *self, PyObject *const *args, |
| 3520 | Py_ssize_t positional_args_count, PyObject *args_names_tuple) { |
| 3521 | int const is_member = self != NULL && PyObject_TypeCheck(self, &StrType); |
| 3522 | |
| 3523 | // Argument objects |
| 3524 | PyObject *haystack_obj = NULL; |
| 3525 | PyObject *needle_obj = NULL; |
| 3526 | PyObject *start_obj = NULL; |
| 3527 | PyObject *end_obj = NULL; |
| 3528 | int validate = 0; |
| 3529 | |
| 3530 | // Argument count validation |
| 3531 | Py_ssize_t const args_names_count = args_names_tuple ? PyTuple_GET_SIZE(args_names_tuple) : 0; |
| 3532 | Py_ssize_t const total_args = positional_args_count + args_names_count; |
| 3533 | Py_ssize_t const expected_min = is_member ? 1 : 2; // needle required |
| 3534 | Py_ssize_t const expected_max = expected_min + 3; // + start + end + validate |
| 3535 | |
| 3536 | if (total_args < expected_min || total_args > expected_max) { |
| 3537 | PyErr_SetString(PyExc_TypeError, "Invalid number of arguments"); |
| 3538 | return NULL; |
| 3539 | } |
| 3540 | |
| 3541 | // Extract positional arguments |
| 3542 | if (is_member) { |
| 3543 | haystack_obj = self; |
| 3544 | if (positional_args_count >= 1) needle_obj = args[0]; |
| 3545 | if (positional_args_count >= 2) start_obj = args[1]; |
| 3546 | if (positional_args_count >= 3) end_obj = args[2]; |
| 3547 | } |
| 3548 | else { |
| 3549 | if (positional_args_count >= 1) haystack_obj = args[0]; |
| 3550 | if (positional_args_count >= 2) needle_obj = args[1]; |
| 3551 | if (positional_args_count >= 3) start_obj = args[2]; |
| 3552 | if (positional_args_count >= 4) end_obj = args[3]; |
| 3553 | } |
| 3554 | |
| 3555 | // Parse keyword arguments |
| 3556 | for (Py_ssize_t i = 0; i < args_names_count; ++i) { |
| 3557 | PyObject *key = PyTuple_GET_ITEM(args_names_tuple, i); |
| 3558 | PyObject *val = args[positional_args_count + i]; |
| 3559 | |
| 3560 | if (PyUnicode_CompareWithASCIIString(key, "start") == 0) { |
| 3561 | if (start_obj) { |
| 3562 | PyErr_SetString(PyExc_TypeError, "start specified twice"); |
| 3563 | return NULL; |
| 3564 | } |
| 3565 | start_obj = val; |
| 3566 | } |
| 3567 | else if (PyUnicode_CompareWithASCIIString(key, "end") == 0) { |
| 3568 | if (end_obj) { |
| 3569 | PyErr_SetString(PyExc_TypeError, "end specified twice"); |
| 3570 | return NULL; |
| 3571 | } |
| 3572 | end_obj = val; |
| 3573 | } |
| 3574 | else if (PyUnicode_CompareWithASCIIString(key, "validate") == 0) { |
| 3575 | validate = PyObject_IsTrue(val); |
| 3576 | if (validate < 0) return NULL; |
nothing calls this directly
no test coverage detected
searching dependent graphs…