/**
 * JS StringBuilder
 * 
 * @author ImPuls$$
 */

/**
 * StringBuilder class constructor
 *
 * @param mixed _string String/String array for class initialization
 */
function StringBuilder() {
	this.container = new Array();
	var arglen = arguments.length;
	for (var i = 0; i < arglen; i++) {
		this.container[this.container.length] = arguments[i];
	}
	
	return this;
}

/**
 * Appends the string representation to the end of class container
 *
 * @param string _string
 */
StringBuilder.prototype.Append = function() {
	var arglen = arguments.length;
	for (var i = 0; i < arglen; i++) {
		this.container[this.container.length] = arguments[i];
	}
	
	return this;
}

/**
 * Appends formated string representation to the end of class container
 *
 * @param string template
 * @param string[] _params
 */
StringBuilder.prototype.AppendFormat = function(template) {
	var arglen = arguments.length;
	for (var i = 1; i < arglen; i++) {
		template = template.replace('{' + (i - 1) + '}', arguments[i]);
	}
	
	this.container[this.container.length] = template;
	
	return this;
}

/**
 * Empties string builder container
 *
 * @param string _string
 */
StringBuilder.prototype.Empty = function() {
	this.container = new Array();
	
	return this;
}

/**
 *  Gets the length of the current StringBuilder
 *
 */
StringBuilder.prototype.Length = function() {
	return this.container.length;
}

/**
 * Converts the value of StringBuilder to a String
 *
 * @param string separator String separator; empty string is default
 */
StringBuilder.prototype.ToString = function() {
	if (arguments[0])
		return this.container.join(arguments[0]);
	else
		return this.container.join('');
}