testdata/ts/node_modules/bebop/dist/index.js
/**
     * Writes a length-prefixed UTF-8-encoded string.
     */
Writes a length-prefixed UTF-8-encoded string.
Writes a length - prefixed UTF - 8 - encoded string .
writeString(value) {
        const stringLength = value.length;
        if (stringLength === 0) {
            this.writeUint32(0);
            return;
        }
        const maxBytes = 4 + stringLength * 3;
        this.guaranteeBufferLength(this.length + maxBytes);
        let w = this.length + 4;
        const start = w;
        let codePoint;
        for (let i = 0; i < stringLength; i++) {
            const a = value.charCodeAt(i);
            if (i + 1 === stringLength || a < 0xD800 || a >= 0xDC00) {
                codePoint = a;
            }
            else {
                const b = value.charCodeAt(++i);
                codePoint = (a << 10) + b + (0x10000 - (0xD800 << 10) - 0xDC00);
            }
            if (codePoint < 0x80) {
                this.buffer[w++] = codePoint;
            }
            else {
                if (codePoint < 0x800) {
                    this.buffer[w++] = ((codePoint >> 6) & 0x1F) | 0xC0;
                }
                else {
                    if (codePoint < 0x10000) {
                        this.buffer[w++] = ((codePoint >> 12) & 0x0F) | 0xE0;
                    }
                    else {
                        this.buffer[w++] = ((codePoint >> 18) & 0x07) | 0xF0;
                        this.buffer[w++] = ((codePoint >> 12) & 0x3F) | 0x80;
                    }
                    this.buffer[w++] = ((codePoint >> 6) & 0x3F) | 0x80;
                }
                this.buffer[w++] = (codePoint & 0x3F) | 0x80;
            }
        }
        const written = w - start;
        this.view.setUint32(this.length, written, true);
        this.length += 4 + written;
    }
writeString ( value ) { const stringLength = value . length ; if ( stringLength === 0 ) { this . writeUint32 ( 0 ) ; return ; } const maxBytes = 4 + stringLength * 3 ; this . guaranteeBufferLength ( this . length + maxBytes ) ; let w = this . length + 4 ; const start = w ; let codePoint ; for ( let i = 0 ; i < stringLength ; i ++ ) { const a = value . charCodeAt ( i ) ; if ( i + 1 === stringLength || a < 0xD800 || a >= 0xDC00 ) { codePoint = a ; } else { const b = value . charCodeAt ( ++ i ) ; codePoint = ( a << 10 ) + b + ( 0x10000 - ( 0xD800 << 10 ) - 0xDC00 ) ; } if ( codePoint < 0x80 ) { this . buffer [ w ++ ] = codePoint ; } else { if ( codePoint < 0x800 ) { this . buffer [ w ++ ] = ( ( codePoint >> 6 ) & 0x1F ) | 0xC0 ; } else { if ( codePoint < 0x10000 ) { this . buffer [ w ++ ] = ( ( codePoint >> 12 ) & 0x0F ) | 0xE0 ; } else { this . buffer [ w ++ ] = ( ( codePoint >> 18 ) & 0x07 ) | 0xF0 ; this . buffer [ w ++ ] = ( ( codePoint >> 12 ) & 0x3F ) | 0x80 ; } this . buffer [ w ++ ] = ( ( codePoint >> 6 ) & 0x3F ) | 0x80 ; } this . buffer [ w ++ ] = ( codePoint & 0x3F ) | 0x80 ; } } const written = w - start ; this . view . setUint32 ( this . length , written , true ) ; this . length += 4 + written ; }
Writes a length-prefixed UTF-8-encoded string.
Writes a length - prefixed UTF - 8 - encoded string .
// The number of characters in the string // If the string is empty avoid unnecessary allocations by writing the zero length and returning.  // value.length * 3 is an upper limit for the space taken up by the string: // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#Buffer_Sizing // We add 4 for our length prefix. // Reallocate if necessary, then write to this.length + 4. // Start writing the string from here: // decode UTF-16 // encode UTF-8 // Count how many bytes we wrote. // Write the length prefix, then skip over it and the written string.