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

Function indexOfAPI

javascript/lib.c:37–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37napi_value indexOfAPI(napi_env env, napi_callback_info info) {
38 size_t argc = 2;
39 napi_value args[2];
40 napi_get_cb_info(env, info, &argc, args, NULL, NULL);
41
42 void *haystack_data, *needle_data;
43 size_t haystack_length, needle_length;
44 napi_status status = napi_get_buffer_info(env, args[0], &haystack_data, &haystack_length);
45 if (status != napi_ok) {
46 napi_throw_error(env, NULL, "First argument must be a Buffer");
47 return NULL;
48 }
49 status = napi_get_buffer_info(env, args[1], &needle_data, &needle_length);
50 if (status != napi_ok) {
51 napi_throw_error(env, NULL, "Second argument must be a Buffer");
52 return NULL;
53 }
54
55 napi_value js_result;
56 if (needle_length == 0) { napi_create_bigint_int64(env, 0, &js_result); }
57 else {
58 sz_cptr_t result = sz_find((sz_cptr_t)haystack_data, haystack_length, (sz_cptr_t)needle_data, needle_length);
59 if (result == NULL) { napi_create_bigint_int64(env, -1, &js_result); }
60 else { napi_create_bigint_uint64(env, result - (sz_cptr_t)haystack_data, &js_result); }
61 }
62
63 return js_result;
64}
65
66napi_value utf8CaseFoldAPI(napi_env env, napi_callback_info info) {
67 size_t argc = 2;

Callers

nothing calls this directly

Calls 1

sz_findFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…