src/StringWriter.js
function __append_utf8(codepoint) {

        var mask;
        var bytes;

        // 1 byte
        if (codepoint <= 0x7F) {
            mask = 0x00;
            bytes = 1;
        }

        // 2 byte
        else if (codepoint <= 0x7FF) {
            mask = 0xC0;
            bytes = 2;
        }

        // 3 byte
        else if (codepoint <= 0xFFFF) {
            mask = 0xE0;
            bytes = 3;
        }

        // 4 byte
        else if (codepoint <= 0x1FFFFF) {
            mask = 0xF0;
            bytes = 4;
        }

        // If invalid codepoint, append replacement character
        else {
            __append_utf8(0xFFFD);
            return;
        }

        // Offset buffer by size
        __expand(bytes);
        var offset = length - 1;

        // Add trailing bytes, if any
        for (var i=1; i<bytes; i++) {
            buffer[offset--] = 0x80 | (codepoint & 0x3F);
            codepoint >>= 6;
        }

        // Set initial byte
        buffer[offset] = mask | codepoint;

    }
function __append_utf8(codepoint) {

        var mask;
        var bytes;

        // 1 byte
        if (codepoint <= 0x7F) {
            mask = 0x00;
            bytes = 1;
        }

        // 2 byte
        else if (codepoint <= 0x7FF) {
            mask = 0xC0;
            bytes = 2;
        }

        // 3 byte
        else if (codepoint <= 0xFFFF) {
            mask = 0xE0;
            bytes = 3;
        }

        // 4 byte
        else if (codepoint <= 0x1FFFFF) {
            mask = 0xF0;
            bytes = 4;
        }

        // If invalid codepoint, append replacement character
        else {
            __append_utf8(0xFFFD);
            return;
        }

        // Offset buffer by size
        __expand(bytes);
        var offset = length - 1;

        // Add trailing bytes, if any
        for (var i=1; i<bytes; i++) {
            buffer[offset--] = 0x80 | (codepoint & 0x3F);
            codepoint >>= 6;
        }

        // Set initial byte
        buffer[offset] = mask | codepoint;

    }
function __append_utf8 ( codepoint ) { var mask ; var bytes ; // 1 byte if ( codepoint <= 0x7F ) { mask = 0x00 ; bytes = 1 ; } // 2 byte else if ( codepoint <= 0x7FF ) { mask = 0xC0 ; bytes = 2 ; } // 3 byte else if ( codepoint <= 0xFFFF ) { mask = 0xE0 ; bytes = 3 ; } // 4 byte else if ( codepoint <= 0x1FFFFF ) { mask = 0xF0 ; bytes = 4 ; } // If invalid codepoint, append replacement character else { __append_utf8 ( 0xFFFD ) ; return ; } // Offset buffer by size __expand ( bytes ) ; var offset = length - 1 ; // Add trailing bytes, if any for ( var i = 1 ; i < bytes ; i ++ ) { buffer [ offset -- ] = 0x80 | ( codepoint & 0x3F ) ; codepoint >>= 6 ; } // Set initial byte buffer [ offset ] = mask | codepoint ; }
Appends a single Unicode character to the current buffer, resizing the
buffer if necessary. The character will be encoded as UTF-8.

@private
@param {Number} codepoint The codepoint of the Unicode character to
append.
Appends a single Unicode character to the current buffer resizing the buffer if necessary . The character will be encoded as UTF - 8 .