// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
// Author: John Leach
// Contact: john.leach@syger.it

if (!syger.exists(String.prototype, "trim")) {

	/**
	 Trims leading and trailing whitespace from a string.
	 From Douglas Crockford "Remedial JavaScript",
	 http://javascript.crockford.com/remedial.html
	 
	 @returns the trimmed string.
	*/
	
	String.prototype.trim = function () {
		return this.replace(/^\s+|\s+$/g, "");
	}; 
}

if (!syger.exists(String.prototype, "startsWith")) {

	/**
	 Checks if the string starts with the specified sub string.
	 
	 @param str the sub string to check for.
	 @returns true if the string starts with the sub string, otherwise
	  false.
	*/
	
	String.prototype.startsWith = function (str) {
		return this.indexOf(str) === 0;
	};
}

if (!syger.exists(String.prototype, "endsWith")) {

	/**
	 Checks if the string ends with the specified sub string.
	 
	 @param str the sub string to check for.
	 @returns true if the string ends with the sub string, otherwise
	  false.
	*/
	
	String.prototype.endsWith = function (str) {
		var offset = this.length - str.length;
		return offset >= 0 && this.lastIndexOf(str) === offset;
	};
}
