﻿/**
 *  This function (added to string) will take an object hash and
 *  for each '#{ [some_string] }' in the string it will substitute
 *  that sequence with the value of the property in the provided
 *  object.
 */
String.prototype.substitute = function (o) {
    return this.replace(/#{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};

/**
 *  This function returns a new string minus leading whitespace, and
 *  minus trailing whitespace.
 */
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
