PHP 7.4.33
Preview: HermesParserDecodeUTF8String.js.flow Size: 1.84 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/hermes-parser/dist/HermesParserDecodeUTF8String.js.flow
/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict
 * @format
 */

'use strict';

/**
 * Decode a UTF-8 encoded string from Hermes with a known length.
 * Based on Emscripten's UTF8ToString with the following differences:
 * - Always reads all bytes up to the given length, including null bytes. This
 *   means that we can decode strings that contain null bytes in the middle.
 * - Allow UTF-8 encoded code points that are part of a surrogate pair, even though
 *   this is technically invalid UTF-8 that UTF8ToString would convert to 0xfffd.
 */
export default function HermesParserDecodeUTF8String(
  ptrIn: number,
  length: number,
  heap: Uint8Array,
): string {
  let ptr = ptrIn;
  const endPtr = ptr + length;
  let str = '';

  while (ptr < endPtr) {
    // ASCII characters fit in single byte code point
    let u0 = heap[ptr++];
    if (!(u0 & 0x80)) {
      str += String.fromCharCode(u0);
      continue;
    }

    // Two byte code point
    const u1 = heap[ptr++] & 0x3f;
    if ((u0 & 0xe0) === 0xc0) {
      str += String.fromCharCode(((u0 & 0x1f) << 6) | u1);
      continue;
    }

    const u2 = heap[ptr++] & 0x3f;
    if ((u0 & 0xf0) === 0xe0) {
      // Three byte code point
      u0 = ((u0 & 0x0f) << 12) | (u1 << 6) | u2;
    } else {
      // Four byte code point
      u0 = ((u0 & 0x07) << 18) | (u1 << 12) | (u2 << 6) | (heap[ptr++] & 0x3f);
    }

    if (u0 < 0x10000) {
      // Code point fits into a single UTF-16 code unit
      str += String.fromCharCode(u0);
    } else {
      // Code point does not fit into single UTF-16 code unit so convert to surrogate pair
      u0 -= 0x10000;
      str += String.fromCharCode(0xd800 | (u0 >> 10), 0xdc00 | (u0 & 0x3ff));
    }
  }

  return str;
}

Directory Contents

Dirs: 6 × Files: 21
Name Size Perms Modified Actions
babel DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
estree DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
generated DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
transform DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
traverse DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
utils DIR
- drwxr-xr-x 2025-03-28 11:04:35
Edit Download
2.87 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
2.99 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
1.15 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
4.95 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
5.42 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
4.00 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
4.18 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
1.86 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
1.84 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
6.42 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
6.75 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
57.55 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
433 B lrw-r--r-- 2025-03-28 11:04:35
Edit Download
662.35 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
2.00 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
11.23 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
11.48 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
6.19 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
3.54 KB lrw-r--r-- 2025-03-28 11:04:35
Edit Download
557 B lrw-r--r-- 2025-03-28 11:04:35
Edit Download
771 B lrw-r--r-- 2025-03-28 11:04:35
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).