/* ------------------------------------------------------------------------------- +

	File:		text.js
	Author:		Ben Nadel
	Date:		January 21, 2005
	Desc:		This has functions for manipulating text strings.

+ ------------------------------------------------------------------------------- */


// Gets a substring from the left of count length
function Left(strText, intCount){
	return(strText.substring(0, intCount));
}


// Deletes the left characters of length count
function LeftDelete(strText, intCount){
	return(strText.substring(intCount));
}


// Trims white space from left of a string
function LeftTrim(strText){
	while(Left(strText, 1) == " "){
		strText = LeftDelete(strText, 1);
	}
	
	return(strText);
}


// This gets a substring from within a string starting at the index, of length count
function Mid(strText, intIndex, intCount){
	return(strText.substring(intIndex, (intIndex + intCount)));
}


// This function deletes the given subsection of a string starting 
// at the index of length count
function MidDelete(strText, intIndex, intCount){
	return(
		strText.substring(0, intIndex) +
		strText.substring((intIndex + intCount), strText.length)
		);
}


// This wraps text around a substring of the given string
function MidSurround(strText, intIndex, intCount, strStart, strEnd){
	return(
		Left(strText, intIndex) +
		strStart + 
		Mid(strText, intIndex, intCount) +
		strEnd + 
		strText.substring((intIndex + intCount), strText.length)
		);
}


// Gets a substring from the right of count length
function Right(strText, intCount){
	return(strText.substring((strText.length - intCount), strText.length));
}


// Deletes the right characters of length count
function RightDelete(strText, intCount){
	return(strText.substring(0, (strText.length - intCount)));
}


// Trims white space from the right of a string
function RightTrim(strText){
	while(Right(strText, 1) == " "){
		strText = RightDelete(strText, 1);
	}
	
	return(strText);
}


// Trims the outlier spaces in a string
function Trim(strText){
	return(
		LeftTrim(
			RightTrim(strText)
			)
		);
}