(encoded)
| 2 | const ArrayBufferString = Object_prototype_toString.call(ArrayBuffer.prototype); |
| 3 | |
| 4 | function decoderReplacer(encoded) { |
| 5 | let codePoint = encoded.charCodeAt(0) << 24; |
| 6 | const leadingOnes = Math.clz32(~codePoint) | 0; |
| 7 | let endPos = 0; |
| 8 | const stringLen = encoded.length | 0; |
| 9 | let result = ''; |
| 10 | if (leadingOnes < 5 && stringLen >= leadingOnes) { |
| 11 | codePoint = (codePoint << leadingOnes) >>> (24 + leadingOnes); |
| 12 | for (endPos = 1; endPos < leadingOnes; endPos = (endPos + 1) | 0) { |
| 13 | codePoint = (codePoint << 6) | (encoded.charCodeAt(endPos) & 0x3f) /*0b00111111*/; |
| 14 | } |
| 15 | if (codePoint <= 0xffff) { |
| 16 | // BMP code point |
| 17 | result += String.fromCharCode(codePoint); |
| 18 | } else if (codePoint <= 0x10ffff) { |
| 19 | // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae |
| 20 | codePoint = (codePoint - 0x10000) | 0; |
| 21 | result += String.fromCharCode( |
| 22 | ((codePoint >> 10) + 0xd800) | 0, // highSurrogate |
| 23 | ((codePoint & 0x3ff) + 0xdc00) | 0 // lowSurrogate |
| 24 | ); |
| 25 | } else { |
| 26 | endPos = 0; |
| 27 | } // to fill it in with INVALIDs |
| 28 | } |
| 29 | for (; endPos < stringLen; endPos = (endPos + 1) | 0) { |
| 30 | result += '\ufffd'; |
| 31 | } |
| 32 | |
| 33 | return result; |
| 34 | } |
| 35 | |
| 36 | function encoderReplacer(nonAsciiChars) { |
| 37 | // make the UTF string into a binary UTF-8 encoded string |
nothing calls this directly
no outgoing calls
no test coverage detected