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

Function findLastByteFromAPI

javascript/lib.c:689–724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

687}
688
689napi_value findLastByteFromAPI(napi_env env, napi_callback_info info) {
690 size_t argc = 2;
691 napi_value args[2];
692 napi_get_cb_info(env, info, &argc, args, NULL, NULL);
693
694 // Get buffer info for haystack (zero-copy)
695 void *haystack_data;
696 size_t haystack_length;
697 napi_status status = napi_get_buffer_info(env, args[0], &haystack_data, &haystack_length);
698 if (status != napi_ok) {
699 napi_throw_error(env, NULL, "First argument must be a Buffer");
700 return NULL;
701 }
702
703 // Get buffer info for allowed bytes (zero-copy)
704 void *allowed_data;
705 size_t allowed_length;
706 status = napi_get_buffer_info(env, args[1], &allowed_data, &allowed_length);
707 if (status != napi_ok) {
708 napi_throw_error(env, NULL, "Second argument must be a Buffer");
709 return NULL;
710 }
711
712 // Find last byte that is in the allowed set using sz_rfind_byteset
713 sz_byteset_t byteset;
714 sz_byteset_init(&byteset);
715 for (size_t i = 0; i < allowed_length; i++) { sz_byteset_add_u8(&byteset, ((sz_u8_t *)allowed_data)[i]); }
716 sz_cptr_t result = sz_rfind_byteset((sz_cptr_t)haystack_data, haystack_length, &byteset);
717
718 // Convert the result to JavaScript BigInt and return
719 napi_value js_result;
720 if (result == NULL) { napi_create_bigint_int64(env, -1, &js_result); }
721 else { napi_create_bigint_uint64(env, result - (sz_cptr_t)haystack_data, &js_result); }
722
723 return js_result;
724}
725
726napi_value equalAPI(napi_env env, napi_callback_info info) {
727 size_t argc = 2;

Callers

nothing calls this directly

Calls 3

sz_byteset_initFunction · 0.85
sz_byteset_add_u8Function · 0.85
sz_rfind_bytesetFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…