testdata/ts/node_modules/bebop/dist/index.js
/**
     * Reads a length-prefixed UTF-8-encoded string.
     */
Reads a length-prefixed UTF-8-encoded string.
Reads a length - prefixed UTF - 8 - encoded string .
readString() {
        const lengthBytes = this.readUint32();
        if (lengthBytes === 0) {
            return emptyString;
        }
        if (lengthBytes >= this.minimumTextDecoderLength) {
            return BebopView.textDecoder.decode(this.buffer.subarray(this.index, this.index += lengthBytes));
        }
        const end = this.index + lengthBytes;
        let result = "";
        let codePoint;
        while (this.index < end) {
            const a = this.buffer[this.index++];
            if (a < 0xC0) {
                codePoint = a;
            }
            else {
                const b = this.buffer[this.index++];
                if (a < 0xE0) {
                    codePoint = ((a & 0x1F) << 6) | (b & 0x3F);
                }
                else {
                    const c = this.buffer[this.index++];
                    if (a < 0xF0) {
                        codePoint = ((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F);
                    }
                    else {
                        const d = this.buffer[this.index++];
                        codePoint = ((a & 0x07) << 18) | ((b & 0x3F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F);
                    }
                }
            }
            if (codePoint < 0x10000) {
                result += String.fromCharCode(codePoint);
            }
            else {
                codePoint -= 0x10000;
                result += String.fromCharCode((codePoint >> 10) + 0xD800, (codePoint & ((1 << 10) - 1)) + 0xDC00);
            }
        }
        this.index = end;
        return result;
    }
readString ( ) { const lengthBytes = this . readUint32 ( ) ; if ( lengthBytes === 0 ) { return emptyString ; } if ( lengthBytes >= this . minimumTextDecoderLength ) { return BebopView . textDecoder . decode ( this . buffer . subarray ( this . index , this . index += lengthBytes ) ) ; } const end = this . index + lengthBytes ; let result = "" ; let codePoint ; while ( this . index < end ) { const a = this . buffer [ this . index ++ ] ; if ( a < 0xC0 ) { codePoint = a ; } else { const b = this . buffer [ this . index ++ ] ; if ( a < 0xE0 ) { codePoint = ( ( a & 0x1F ) << 6 ) | ( b & 0x3F ) ; } else { const c = this . buffer [ this . index ++ ] ; if ( a < 0xF0 ) { codePoint = ( ( a & 0x0F ) << 12 ) | ( ( b & 0x3F ) << 6 ) | ( c & 0x3F ) ; } else { const d = this . buffer [ this . index ++ ] ; codePoint = ( ( a & 0x07 ) << 18 ) | ( ( b & 0x3F ) << 12 ) | ( ( c & 0x3F ) << 6 ) | ( d & 0x3F ) ; } } } if ( codePoint < 0x10000 ) { result += String . fromCharCode ( codePoint ) ; } else { codePoint -= 0x10000 ; result += String . fromCharCode ( ( codePoint >> 10 ) + 0xD800 , ( codePoint & ( ( 1 << 10 ) - 1 ) ) + 0xDC00 ) ; } } this . index = end ; return result ; }
Reads a length-prefixed UTF-8-encoded string.
Reads a length - prefixed UTF - 8 - encoded string .
// bail out early on an empty string // decode UTF-8 // encode UTF-16 // Damage control, if the input is malformed UTF-8.