string.slice = string.sub

string.beginsWith = function (str, beg)  
	if 'string' ~= type(str) or 'string' ~= type(beg) then
		error('String expected '..debug.traceback())  
	end  

	if 1 ~= string.find(str, beg, 1, true) then
	    return false  
	end  
	return true
end

string.ibeginsWith = function (str, beg)  
	if 'string' ~= type(str) or 'string' ~= type(beg) then
		error('String expected '..debug.traceback())  
	end  

	local s = string.lower(str)
	local b = string.lower(beg)
	if 1 ~= string.find(s, b, 1, true) then
	    return false  
	end  
	
	return true
end

string.endsWith = function (str, search)  
	if 'string' ~= type(str) or 'string' ~= type(search) then
		error('String expected '..debug.traceback())  
	end  
	
	if string.slice(str, -string.len(search)) ~= search then
	    return false  
	end  
	
	return true
end

string.iendsWith = function (str, search)  
	if 'string' ~= type(str) or 'string' ~= type(search) then
		error('String expected '..debug.traceback())  
	end  
	
	local s = string.lower(str)
	local e = string.lower(search)
	if string.slice(s, -string.len(e)) ~= search then
	    return false  
	end  
	
	return true
end

string.trim = function(str)

	return (str:gsub("^%s*(.-)%s*$", "%1"))

end
