(nonAsciiChars)
| 34 | } |
| 35 | |
| 36 | function encoderReplacer(nonAsciiChars) { |
| 37 | // make the UTF string into a binary UTF-8 encoded string |
| 38 | let point = nonAsciiChars.charCodeAt(0) | 0; |
| 39 | if (point >= 0xd800 && point <= 0xdbff) { |
| 40 | const nextcode = nonAsciiChars.charCodeAt(1) | 0; |
| 41 | if (nextcode !== nextcode) { |
| 42 | // NaN because string is 1 code point long |
| 43 | return String.fromCharCode(0xef /*11101111*/, 0xbf /*10111111*/, 0xbd /*10111101*/); |
| 44 | } |
| 45 | // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae |
| 46 | if (nextcode >= 0xdc00 && nextcode <= 0xdfff) { |
| 47 | point = (((point - 0xd800) << 10) + nextcode - 0xdc00 + 0x10000) | 0; |
| 48 | if (point > 0xffff) { |
| 49 | return String.fromCharCode((0x1e /*0b11110*/ << 3) | (point >>> 18), (0x2 /*0b10*/ << 6) | ((point >>> 12) & 0x3f) /*0b00111111*/, (0x2 /*0b10*/ << 6) | ((point >>> 6) & 0x3f) /*0b00111111*/, (0x2 /*0b10*/ << 6) | (point & 0x3f) /*0b00111111*/); |
| 50 | } |
| 51 | } else { |
| 52 | return String.fromCharCode(0xef, 0xbf, 0xbd); |
| 53 | } |
| 54 | } |
| 55 | if (point <= 0x007f) { |
| 56 | return nonAsciiChars; |
| 57 | } else if (point <= 0x07ff) { |
| 58 | return String.fromCharCode((0x6 << 5) | (point >>> 6), (0x2 << 6) | (point & 0x3f)); |
| 59 | } else { |
| 60 | return String.fromCharCode((0xe /*0b1110*/ << 4) | (point >>> 12), (0x2 /*0b10*/ << 6) | ((point >>> 6) & 0x3f) /*0b00111111*/, (0x2 /*0b10*/ << 6) | (point & 0x3f) /*0b00111111*/); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export class TextDecoder { |
| 65 | public get encoding() { |
nothing calls this directly
no outgoing calls
no test coverage detected