MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / Utf8CaseInsensitiveFindIteratorType_next

Function Utf8CaseInsensitiveFindIteratorType_next

python/stringzilla.c:5783–5817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5781#pragma region UTF8 Case Insensitive Find Iterator
5782
5783static PyObject *Utf8CaseInsensitiveFindIteratorType_next(Utf8CaseInsensitiveFindIterator *self) {
5784 // Check if we've reached the end
5785 sz_size_t remaining = (sz_size_t)(self->haystack_end - self->current);
5786 if (remaining == 0) return NULL;
5787
5788 // Search for next match
5789 sz_size_t matched_length = 0;
5790 sz_cptr_t match = sz_utf8_case_insensitive_find(self->current, remaining, self->needle.start, self->needle.length,
5791 &self->metadata, &matched_length);
5792
5793 if (!match) return NULL;
5794
5795 // Create a new `Str` object for the matched region
5796 Str *result_obj = (Str *)StrType.tp_alloc(&StrType, 0);
5797 if (result_obj == NULL && PyErr_NoMemory()) return NULL;
5798
5799 result_obj->memory.start = match;
5800 result_obj->memory.length = matched_length;
5801 result_obj->parent = self->haystack_obj;
5802 Py_INCREF(self->haystack_obj);
5803
5804 // Advance position for next search
5805 if (self->include_overlapping) {
5806 // Move forward by one UTF-8 codepoint to allow overlapping matches
5807 sz_size_t pos = 0;
5808 sz_utf8_decode_(match, matched_length, &pos);
5809 self->current = match + (pos > 0 ? pos : 1);
5810 }
5811 else {
5812 // Move past the entire matched region (non-overlapping)
5813 self->current = match + matched_length;
5814 }
5815
5816 return (PyObject *)result_obj;
5817}
5818
5819static void Utf8CaseInsensitiveFindIteratorType_dealloc(Utf8CaseInsensitiveFindIterator *self) {
5820 Py_XDECREF(self->haystack_obj);

Callers

nothing calls this directly

Calls 2

sz_utf8_decode_Function · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…