code: public static String trim(String str, boolean removeBOM, boolean removeSpecialWhiteSpace, String defaultValue) {
  	if (str == null) return defaultValue;
  	if (str.isEmpty()) return str;
  	// remove leading BOM Marks
  	if (removeBOM) {
  	    // UTF-16, big-endian
  	    if (str.charAt(0) == '\uFEFF') str = str.substring(1);
  	    else if (str.charAt(0) == '\uFFFD') str = str.substring(1);
  
  	    // UTF-16, little-endian
  	    else if (str.charAt(0) == '\uFFFE') str = str.substring(1);
  
  	    // UTF-8
  	    else if (str.length() >= 2) {
  		// TODO i get this from UTF-8 files generated by suplime text, i was expecting something else
  		if (str.charAt(0) == '\uBBEF' && str.charAt(1) == '\uFFFD') str = str.substring(2);
  	    }
  	}
  
  	if (removeSpecialWhiteSpace) {
  	    int len = str.length();
  	    int startIndex = 0, endIndex = len - 1;
  	    // left
  	    while ((startIndex < len) && isWhiteSpace(str.charAt(startIndex), true)) {
  		startIndex++;
  	    }
  	    // right
  	    while ((startIndex < endIndex) && isWhiteSpace(str.charAt(endIndex), true)) {
  		endIndex--;
  	    }
  	    return ((startIndex > 0) || (endIndex + 1 < len)) ? str.substring(startIndex, endIndex + 1) : str;
  	}
  
  	return str.trim();
      }
docs: trim given value, return defaultvalue when input is null this function no only removes the
  "classic" whitespaces, it also removes Byte order masks forgotten to remove when reading a UTF
  file.
  
  @param str
  @param removeBOM if set to true, Byte Order Mask that got forgotten get removed as well
  @param removeSpecialWhiteSpace if set to true, lucee removes also uncommon white spaces.
  @param defaultValue
  @return trimmed string or defaultValue