js/pgnvjs.js
// and appends the given value if supplied
and appends the given value if supplied
and appends the given value if supplied
function StringBuilder(value) {
    var that = {};
    that.strings = new Array("");
    var append = function (value) {
        if (value) {
            that.strings.push(value);
        }
    };
    var clear = function () {
        that.strings.length = 1;
    };
    var length = function () {
        return that.strings.reduce(function(previousValue, currentValue, index, array){
            return previousValue + currentValue.length;
        }, 0);
    };
    var isEmpty = function () {
        for (var i = 0; i < that.strings.length; i++) {
            if (that.strings[i].length > 0) {
                return false;
            }
        }
        return true;
    }
    var lastChar = function () {
        if (that.strings.length === 0) {
            return null;
        }
        return that.strings[that.strings.length - 1].slice(-1);
    }
    var toString = function () {
        return that.strings.join("");
    };
    append(value);
    return {
        append: append,
        clear: clear,
        toString: toString,
        length: length,
        isEmpty: isEmpty,
        lastChar: lastChar
    }
}
function StringBuilder ( value ) { var that = { } ; that . strings = new Array ( "" ) ; var append = function ( value ) { if ( value ) { that . strings . push ( value ) ; } } ; var clear = function ( ) { that . strings . length = 1 ; } ; var length = function ( ) { return that . strings . reduce ( function ( previousValue , currentValue , index , array ) { return previousValue + currentValue . length ; } , 0 ) ; } ; var isEmpty = function ( ) { for ( var i = 0 ; i < that . strings . length ; i ++ ) { if ( that . strings [ i ] . length > 0 ) { return false ; } } return true ; } var lastChar = function ( ) { if ( that . strings . length === 0 ) { return null ; } return that . strings [ that . strings . length - 1 ] . slice ( - 1 ) ; } var toString = function ( ) { return that . strings . join ( "" ) ; } ; append ( value ) ; return { append : append , clear : clear , toString : toString , length : length , isEmpty : isEmpty , lastChar : lastChar } }
and appends the given value if supplied
and appends the given value if supplied
// Appends the given value to the end of this instance. // Clears the string buffer // Returns the length of the final string (without building it) // Return true if the receiver is empty. Don't compute length!! // Return the last character (as string) of the receiver. // Return null if none is found // Converts this instance to a String.