
/* (C) 2001 Colombiasoft Technologies Ltda. All rights reserved	*/
/* STRING.JS - Utility strings functions			*/

function makeBlankStr ( length )
{
	str = new String() ;
	for ( var xxx = length ; xxx ; xxx--, str += "\xA0" ) ;
	return str ;
}

function stripFiller( input )
{
	for ( var cnt = 0 ; cnt < input.length && input.charAt( cnt ) != "\xA0" ; cnt++ ) ;
	return input.substring( 0, cnt ) ;
}

/* findOccurrence
   Returns the number of occurences of dest in src.
   0 if none.

   Parameters:

   src      Source string
   dest     String to search for
   options  It could be "i" or "". ("i" is for "insensitive")
*/
function findOccurrence ( src, dest, options )
{
	if ( (matches = src.match(eval( "/" + dest + "/g" + options ))) )
		return matches.length ;

	return 0 ;
}

/* doTrim
  Removes the trailing and heading spaces in a string.
  Returns the string.
  
  Parameters:
  str		The string
*/
function doTrim( str )
{
	var index ;
	
	for ( index = 0 ; index < str.length && str.charAt(index)==" "; index++ ) ;
	
	str = str.substring( index ) ;

	for( index = str.length - 1 ; str.charAt(index)==" " && index ; index-- ) ;
	
	return str.substring( 0, index+1 ) ;
}

/* fillStr */

function fillStr ( str, length, fillerStr )
{
	var	filler, fillChar, side, xxx,
		left_or_right = 0 ; // Left Justified 

	switch ( fillStr.arguments.length )
	{
		case 2:
			fillerStr = "\xA0" ;
			break ;
	}

	if ( length < 0 )
	{
		left_or_right = 1 ; // Right justified
		length *= -1 ;
	}

	if ( str.length > length )
		str = str.substring( 0, length )

	for ( filler = "", xxx = length - str.length ; xxx ; xxx-- )
		filler += fillerStr ;

	if ( left_or_right ) // > 0 Fills to the left side
		str = filler + str ;
	else
		str = str + filler ;

	return str ;
}

/* EOF */
