(self, buf, i)
| 66873 | |
| 66874 | // Returns only complete characters in a Buffer |
| 66875 | StringDecoder.prototype.text = utf8Text; |
| 66876 | |
| 66877 | // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer |
| 66878 | StringDecoder.prototype.fillLast = function (buf) { |
| 66879 | if (this.lastNeed <= buf.length) { |
| 66880 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); |
| 66881 | return this.lastChar.toString(this.encoding, 0, this.lastTotal); |
| 66882 | } |
| 66883 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length); |
| 66884 | this.lastNeed -= buf.length; |
| 66885 | }; |
| 66886 | |
| 66887 | // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a |
| 66888 | // continuation byte. If an invalid byte is detected, -2 is returned. |
| 66889 | function utf8CheckByte(byte) { |
| 66890 | if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4; |
| 66891 | return byte >> 6 === 0x02 ? -1 : -2; |
| 66892 | } |
| 66893 | |
| 66894 | // Checks at most 3 bytes at the end of a Buffer in order to detect an |
| 66895 | // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4) |
| 66896 | // needed to complete the UTF-8 character (if applicable) are returned. |
| 66897 | function utf8CheckIncomplete(self, buf, i) { |
| 66898 | var j = buf.length - 1; |
| 66899 | if (j < i) return 0; |
| 66900 | var nb = utf8CheckByte(buf[j]); |
| 66901 | if (nb >= 0) { |
no test coverage detected