/**
 *  @fileoverview
 *  Adds additional utility functions to the String object.
 *
 *  Contents:
 *    .strReverse()
 *    .stripSpaces()
 *    .trim()
 *    .trimLeft()
 *    .trimRight()
 *    .ucfirst()
 */

/**
 *  Reverses the characters in a string. Method extends String object.
 *
 *  @return New string with characters in reverse order.
 *  @type String
 */
String.prototype.strReverse = function()
{
  return this.split("").reverse().join("");
}

/**
 *  Strips spaces from a string. Method extends String object.
 *
 *  @return New string with spaces removed.
 *  @type String
 */
String.prototype.stripSpaces = function()
{
  return this.split(" ").join("");
}

/**
 *  Trims leading whitespace from a string. Method extends String object.
 *
 *  @return New string with spaces removed from the left.
 *  @type String
 */
String.prototype.trimLeft = function()
{
  return this.replace(/^\s+/, "");
}

/**
 *  Trims trailing whitespace from a string. Method extends String object.
 *
 *  @return New string with spaces removed from the right.
 *  @type String
 */
String.prototype.trimRight = function()
{
  return this.replace(/\s+$/, "");
}

/**
 *  Trims leading and trailing whitespace from a string. Method extends String
 *  object.
 *
 *  @return New string with leading and trailing spaces removed.
 *  @type String
 */
String.prototype.trim = function()
{
  return this.trimLeft().trimRight();
}

String.prototype.ucfirst = function()
{
  return this.substring(0, 1).toUpperCase() + this.substring(1);
}
