﻿// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value) {
    this.strings = new Array("");
    this.Append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.Append = function(value) {
    if (value) {
        this.strings.push(value);
    }
}

// Appends the given value and the new line character to the end of this instance.
StringBuilder.prototype.AppendLine = function(value) {
    if (value) {
        this.strings.push(value);
    }
    this.strings.push('\n');
}

// Clears the string buffer
StringBuilder.prototype.Clear = function() {
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.ToString = function() {
    return this.strings.join("");
}

String.Format = function(text) {
    if (arguments.length <= 1) {
        return text;
    }
    var tokenCount = arguments.length - 2;
    for (var token = 0; token <= tokenCount; token++) {
        text = text.replace(new RegExp("\\{" + token + "\\}", "gi"), arguments[token + 1]);
    }
    return text;
};