<!-- global_string_tools -->
<!--

/**
 * Entfernt white space characters am Beginn und Ende des Strings.
 *
 * @param str Zeichenkette.
 * @return Zeichenkette ohne white spaces.
 */
function STR_trim(str)
{
  if (str && typeof(str) == "string")
  {
	  var trimmed = "";
	  var regularExpressionLeading = /^\s+/;
	  var regularExpressionTrailing = /$\s+/;  
	  trimmed = str.replace(regularExpressionLeading, "");	
	  trimmed = trimmed.replace(regularExpressionTrailing, "");	
	  return trimmed;
	}
	else
	{
		return str;	
	} 
}

/**
 * Check if a string is not empty.
 *
 * @param str the string
 * @return true, if str is not empty, i.e. if it contains any character that is not a white space character
 */
function STR_isNotEmpty(str)
{
  var regularExpression = /\S.+/;
  return regularExpression.test(str);	
}

/**
 * Check if a string is empty.
 *
 * @param str the string
 * @return true, if str is empty, i.e. it has zero length or contains only white space characters
 */
function STR_isEmpty(str)
{
	return (! STR_isNotEmpty(str));
}

/**
 * Get the first count characters of a string.
 *
 * @param str the string
 * @param count the number of characters to get
 * @return the first count characters of the string (may be less than count), not null
 */
function STR_left(str, count)
{
	return STR_cut(str, count, true);
}

/**
 * Get the last count characters of a string.
 *
 * @param str the string
 * @param count the number of characters to get
 * @return the last count characters of the string (may be less than count), not null
 */
function STR_right(str, count)
{
	return STR_cut(str, count, false);
}

/**
 * Get the first or last count characters of a string.
 *
 * @param str the string
 * @param count the number of characters to get
 * @param leading true to get the leading count characters, false to get the trailing count characters
 * @return count or less characters of the string, not null
 */
function STR_cut(str, count, leading)
{
	if (str == null)
	{
		return "";
	}

	var charCount = count;
	if (charCount < 1)
	{
		return "";
	}

	if (str.length < count)
	{
		return str;
	}	
	
	if (leading)
	{
		return str.substring(0, count);
	}
	else
	{
		return str.substring(str.length - count);
	}
}

/**
 * Parse a list of comma-separated values into an array of strings.
 *
 * @param inputString e.g. "pdf,xls,ppt,doc"
 * @return array of strings, may be empty, not null
 */
function STR_parseCommaSeparatedList(inputString)
{
  return inputString.split(",");
}

function STR_startsWith(inputString, pattern)
{
  return (inputString.indexOf(pattern) == 0);
}

function STR_endsWith(inputString, pattern)
{
  var lastIndex = inputString.lastIndexOf(pattern);
  if (lastIndex == -1)
  {
  	return false;
  }
  var requiredIndex = inputString.length - pattern.length;
	return (lastIndex == requiredIndex);
}

function STR_hasDigits(inputString)
{
  var regularExpression = /\d+/;
  return regularExpression.test(inputString);
}

function STR_hasSpecialChars(inputString)
{
  var hasUnderscore = (inputString.indexOf("_") != -1);
  if (hasUnderscore)
  {
  	return true;
  }
  
  var regularExpression = /\W+/; // does not treat the underscore as a special character
  return regularExpression.test(inputString);
}

/**
 * Check if 2 strings are equal.
 *
 * @param str1 The first string.
 * @param str2 The second string.
 * @param ignoreCase True to ignore case when comparing the strings.
 * @return True, if the strings are equal.
 */ 
function STR_equals(str1, str2, ignoreCase)
{
  if (ignoreCase)
  {
	  return (str1.toLowerCase() == str2.toLowerCase()); 
  }
  else
  {
 		return str1 == str2;  	
  }
}

-->