MCPcopy Create free account
hub / github.com/codesandbox/excalidraw-firebase / stringToUTF8Array

Function stringToUTF8Array

.pnp.cjs:8451–8488  ·  view source on GitHub ↗
(str, heap, outIdx, maxBytesToWrite)

Source from the content-addressed store, hash-verified

8449 return UTF8Decoder.decode(HEAPU8.subarray(ptr, end));
8450 }
8451 function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
8452 if (!(maxBytesToWrite > 0))
8453 return 0;
8454 var startIdx = outIdx;
8455 var endIdx = outIdx + maxBytesToWrite - 1;
8456 for (var i = 0; i < str.length; ++i) {
8457 var u = str.charCodeAt(i);
8458 if (u >= 55296 && u <= 57343) {
8459 var u1 = str.charCodeAt(++i);
8460 u = 65536 + ((u & 1023) << 10) | u1 & 1023;
8461 }
8462 if (u <= 127) {
8463 if (outIdx >= endIdx)
8464 break;
8465 heap[outIdx++] = u;
8466 } else if (u <= 2047) {
8467 if (outIdx + 1 >= endIdx)
8468 break;
8469 heap[outIdx++] = 192 | u >> 6;
8470 heap[outIdx++] = 128 | u & 63;
8471 } else if (u <= 65535) {
8472 if (outIdx + 2 >= endIdx)
8473 break;
8474 heap[outIdx++] = 224 | u >> 12;
8475 heap[outIdx++] = 128 | u >> 6 & 63;
8476 heap[outIdx++] = 128 | u & 63;
8477 } else {
8478 if (outIdx + 3 >= endIdx)
8479 break;
8480 heap[outIdx++] = 240 | u >> 18;
8481 heap[outIdx++] = 128 | u >> 12 & 63;
8482 heap[outIdx++] = 128 | u >> 6 & 63;
8483 heap[outIdx++] = 128 | u & 63;
8484 }
8485 }
8486 heap[outIdx] = 0;
8487 return outIdx - startIdx;
8488 }
8489 function stringToUTF8(str, outPtr, maxBytesToWrite) {
8490 return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
8491 }

Callers 2

stringToUTF8Function · 0.85
allocateUTF8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected