
/*# ----------------------------------------------------------------------------------------------- #
  #																				#
  # String.tweak.js																	#
  #																				#
  # MySpinalCord.com																#
  # Copyright 2011 Thommy Morgan														#
  # All Rights Reserved																#
  #																				#
  # ----------------------------------------------------------------------------------------------- #*/




// Determines if a substring is contained by the string
String.prototype.contains = function(str) {
	return (!str) ? false : (this.indexOf(str) > -1);
}

// Converts the string to an integer value
String.prototype.toInt = function() {
	return parseInt(this);
}

// Replaces all occurences of the specified string
String.prototype.replaceAll = function(str, newstr) {
	var exp = new RegExp(str, "gi");
	return (!str) ? this : this.replace(exp, (!newstr) ? "" : newstr);
}

// Insert a string after a specified index or string
String.prototype.insertBefore = function(str, sub) {
	var end = (typeof sub == "string") ? this.substring(this.indexOf(sub) + sub.length) : this.substring(index + 1);
	return (!str) ? this : (!index) ? this + str : this.substring(0, index) + str + end;
}

// Insert a string after a specified string
String.prototype.insertAfter = function(str, sub) {
	var end = (typeof sub == "string") ? this.substring(this.indexOf(sub) + sub.length) : this.substring(index + 1);
	return (!str) ? this : (!sub) ? this : this.substring(0, this.indexOf(sub) + sub.length) + str + end;
}

// Lowercase specified character
String.prototype.lcChar = function(index) {
	return (!index) ? this : this.substring(index, 1).toLowerCase() + this.substring(index + 1);
}

// Capitalize specified character
String.prototype.ucChar = function(index) {
	return (!index) ? this : this.substring(index, 1).toUpperCase() + this.substring(index + 1);
}

// Lowercase first Letter
String.prototype.lcfirst = function() {
	return this.lcChar(0);
}

// Capitalize first letter
String.prototype.ucfirst = function() {
	return this.ucChar(0);
}

// remove multiple, leading or trailing spaces
String.prototype.trim = function() {
	var str = this.replace(/(^\s*)|(\s*$)/gi,"");
	str = str.replace(/[ ]{2,}/gi," ");
	str = str.replace(/\n /,"\n");
	return str;
}
