| 251 | // Finds the length of a given data array, stopping at the first 0 byte. |
| 252 | template <class T> |
| 253 | [[nodiscard]] |
| 254 | static size_t zero_terminated_length(const T* data, size_t len) { |
| 255 | if (!data || len == 0) |
| 256 | return 0; |
| 257 | |
| 258 | const T* start = data; |
| 259 | auto* found = static_cast<const T*>(memchr(start, '\0', len)); |
| 260 | |
| 261 | // If a null byte was not found, return the passed length. |
| 262 | if (!found) |
| 263 | return len; |
| 264 | |
| 265 | return std::distance(start, found); |
| 266 | } |
| 267 | |
| 268 | // decode() function implementation |
| 269 | JSString* gjs_decode_from_uint8array(JSContext* cx, JS::HandleObject byte_array, |
no outgoing calls
no test coverage detected