* @param {string} str * @param {Int8Array} noEscapeTable * @param {string[]} hexTable * @returns {string}
(str, noEscapeTable, hexTable)
| 43 | * @returns {string} |
| 44 | */ |
| 45 | function encodeStr(str, noEscapeTable, hexTable) { |
| 46 | const len = str.length; |
| 47 | if (len === 0) |
| 48 | return ''; |
| 49 | |
| 50 | let out = ''; |
| 51 | let lastPos = 0; |
| 52 | let i = 0; |
| 53 | |
| 54 | outer: |
| 55 | for (; i < len; i++) { |
| 56 | let c = StringPrototypeCharCodeAt(str, i); |
| 57 | |
| 58 | // ASCII |
| 59 | while (c < 0x80) { |
| 60 | if (noEscapeTable[c] !== 1) { |
| 61 | if (lastPos < i) |
| 62 | out += StringPrototypeSlice(str, lastPos, i); |
| 63 | lastPos = i + 1; |
| 64 | out += hexTable[c]; |
| 65 | } |
| 66 | |
| 67 | if (++i === len) |
| 68 | break outer; |
| 69 | |
| 70 | c = StringPrototypeCharCodeAt(str, i); |
| 71 | } |
| 72 | |
| 73 | if (lastPos < i) |
| 74 | out += StringPrototypeSlice(str, lastPos, i); |
| 75 | |
| 76 | // Multi-byte characters ... |
| 77 | if (c < 0x800) { |
| 78 | lastPos = i + 1; |
| 79 | out += hexTable[0xC0 | (c >> 6)] + |
| 80 | hexTable[0x80 | (c & 0x3F)]; |
| 81 | continue; |
| 82 | } |
| 83 | if (c < 0xD800 || c >= 0xE000) { |
| 84 | lastPos = i + 1; |
| 85 | out += hexTable[0xE0 | (c >> 12)] + |
| 86 | hexTable[0x80 | ((c >> 6) & 0x3F)] + |
| 87 | hexTable[0x80 | (c & 0x3F)]; |
| 88 | continue; |
| 89 | } |
| 90 | // Surrogate pair |
| 91 | ++i; |
| 92 | |
| 93 | // This branch should never happen because all URLSearchParams entries |
| 94 | // should already be converted to USVString. But, included for |
| 95 | // completion's sake anyway. |
| 96 | if (i >= len) |
| 97 | throw new ERR_INVALID_URI(); |
| 98 | |
| 99 | const c2 = StringPrototypeCharCodeAt(str, i) & 0x3FF; |
| 100 | |
| 101 | lastPos = i + 1; |
| 102 | c = 0x10000 + (((c & 0x3FF) << 10) | c2); |
no outgoing calls
no test coverage detected
searching dependent graphs…