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

Function Str_like_utf8_count

python/stringzilla.c:4462–4490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4460 " 1";
4461
4462static PyObject *Str_like_utf8_count(PyObject *self, PyObject *const *args, Py_ssize_t positional_args_count,
4463 PyObject *args_names_tuple) {
4464 // Check minimum arguments
4465 int is_member = self != NULL && PyObject_TypeCheck(self, &StrType);
4466 Py_ssize_t min_args = !is_member;
4467 Py_ssize_t max_args = !is_member;
4468 if (positional_args_count < min_args || positional_args_count > max_args) {
4469 PyErr_Format(PyExc_TypeError, "utf8_count() takes exactly %zd argument(s)", min_args);
4470 return NULL;
4471 }
4472
4473 // No keyword arguments expected
4474 if (args_names_tuple && PyTuple_GET_SIZE(args_names_tuple) > 0) {
4475 PyErr_SetString(PyExc_TypeError, "utf8_count() takes no keyword arguments");
4476 return NULL;
4477 }
4478
4479 PyObject *text_obj = is_member ? self : args[0];
4480 sz_string_view_t text;
4481
4482 // Validate and convert `text`
4483 if (!sz_py_export_string_like(text_obj, &text.start, &text.length)) {
4484 wrap_current_exception("The text argument must be string-like");
4485 return NULL;
4486 }
4487
4488 sz_size_t count = sz_utf8_count(text.start, text.length);
4489 return PyLong_FromSize_t(count);
4490}
4491
4492static char const doc_utf8_splitlines_iter[] = //
4493 "Create an iterator for splitting a string by Unicode newline characters.\n"

Callers

nothing calls this directly

Calls 3

sz_py_export_string_likeFunction · 0.85
wrap_current_exceptionFunction · 0.85
sz_utf8_countFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…