class Const {

  public static String trim( String str ) {
    if ( str == null ) {
      return null;
    }

    int max = str.length() - 1;
    int min = 0;

    while ( min <= max && isSpace( str.charAt( min ) ) ) {
      min++;
    }
    while ( max >= 0 && isSpace( str.charAt( max ) ) ) {
      max--;
    }

    if ( max < min ) {
      return "";
    }

    return str.substring( min, max + 1 );
  }

}