/** String.js ******************************************************************
 * @fileOverview
 * Extensions to the native String object.
 *
 * @minify true
 * @author Joe Whetzel (jwhetzel [at] mcclatchyinteractive.com)
 */

/**
 * Append values to a sting using a delimiter. This method will automatically
 * determine if the delimiter is needed.
 */
String.prototype.append = function(str,del){
	var newStr = this;
	if (del) {
		if (newStr.length > 0) {newStr += del + str;}
		else {newStr += str;}
	}
	else {newStr += str;}
	return newStr;
};

/**
 * Preppend values to a sting using a delimiter. This method will automatically
 * determine if the delimiter is needed.
 */
String.prototype.prepend = function(str,del){
	var newStr = this;
	if (del) {
		if (newStr.length > 0) {newStr = str + del + newStr;}
		else {newStr = str + newStr;}
	}
	else {newStr = str + newStr;}
	return newStr;
};

/**
 * Detects whether or not the string consists only of whitespace.
 *
 * @returns boolean
 */
String.prototype.isBlank = function(){
	return (this.search(/\S/) == -1) ? true : false;
};

/**
 * Trims whitespace from the beginning and/or end of the string. By default
 * whitespace will be trimmed from both ends of the string. If the optional 
 * side argument is included it will only trim whitespace from that side.
 *
 * @arg side string 'left' or 'right' indicates which side to trim from
 */
String.prototype.trim = function(side){
	var left = new RegExp(/^\s*/);
	var right = new RegExp(/\s*$/);
	var str = this;
	switch (side) {
		case 'left':
		case 'start':
		case 'beginning':
			str = str.replace(left, '');
			break;
		case 'right':
		case 'end':
			str = str.replace(right, '');
			break;
		default:
			str = str.replace(left, '');
			str = str.replace(right, '');
	}
	return str;
};

/**
 * Converts &, <, and > to their respective HTML escape codes.
 */
String.prototype.htmlEntities = function () {
	return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};

/**
 * Strip HTML tags from a string.
 */
String.prototype.stripTags = function () {
	return this.replace(/<([^>]+)>/g,'');
};




/** String.js ^ ************************************************************* */
