/************************************************************
 * Javascript Lib V1.3
 * CONTACT: jerry.wang@clochase.com
 *
 * Add trim / trimLeft / trimRight / format functions for String object
 * String.format('$1', 'a');
 ************************************************************/
 
String.prototype.trimLeft = function()
{
    return this.replace(/(^\s*)/g, "");
}

String.prototype.trimRight = function()
{
    return this.replace(/(\s*$)/g, "");
}

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}



if (!String._FORMAT_SEPARATOR)
{
    String._FORMAT_SEPARATOR = String.fromCharCode(0x1f);
    String._FORMAT_ARGS_PATTERN 
        = new RegExp('^[^' + String._FORMAT_SEPARATOR + ']*' 
        + new Array(100).join('(?:.([^' + String._FORMAT_SEPARATOR + ']*))?'));
}

if (!String.format)
{
    String.format = function (s)
    {
        return Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR).replace(String._FORMAT_ARGS_PATTERN, s);
    }
}

if (!''.format)
{
    String.prototype.format = function ()
    {
        return (String._FORMAT_SEPARATOR +Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR)).replace(String._FORMAT_ARGS_PATTERN, this);
    }
}
