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

Function findByteAPI

javascript/lib.c:580–614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578}
579
580napi_value findByteAPI(napi_env env, napi_callback_info info) {
581 size_t argc = 2;
582 napi_value args[2];
583 napi_get_cb_info(env, info, &argc, args, NULL, NULL);
584
585 // Get buffer info for haystack (zero-copy)
586 void *haystack_data;
587 size_t haystack_length;
588 napi_status status = napi_get_buffer_info(env, args[0], &haystack_data, &haystack_length);
589 if (status != napi_ok) {
590 napi_throw_error(env, NULL, "First argument must be a Buffer");
591 return NULL;
592 }
593
594 // Get byte value (as number)
595 double byte_value_double;
596 status = napi_get_value_double(env, args[1], &byte_value_double);
597 if (status != napi_ok) {
598 napi_throw_error(env, NULL, "Second argument must be a number");
599 return NULL;
600 }
601
602 sz_u8_t byte_value = (sz_u8_t)byte_value_double;
603
604 // Find the byte using sz_find_byte (needs pointer to byte)
605 char byte_char = (char)byte_value;
606 sz_cptr_t result = sz_find_byte((sz_cptr_t)haystack_data, haystack_length, &byte_char);
607
608 // Convert the result to JavaScript BigInt and return
609 napi_value js_result;
610 if (result == NULL) { napi_create_bigint_int64(env, -1, &js_result); }
611 else { napi_create_bigint_uint64(env, result - (sz_cptr_t)haystack_data, &js_result); }
612
613 return js_result;
614}
615
616napi_value findLastByteAPI(napi_env env, napi_callback_info info) {
617 size_t argc = 2;

Callers

nothing calls this directly

Calls 1

sz_find_byteFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…