class Const {

  public static String[] splitPath( String path, String separator ) {
    //
    // Example /a/b/c --> new String[] { a, b, c }
    //
    // Make sure training slashes are removed
    //
    // Example /a/b/c/ --> new String[] { a, b, c }
    //

    // Check for empty paths...
    //
    if ( path == null || path.length() == 0 || path.equals( separator ) ) {
      return new String[] {};
    }

    // lose trailing separators
    //
    while ( path.endsWith( separator ) ) {
      path = path.substring( 0, path.length() - 1 );
    }

    int sepLen = separator.length();
    int nr_separators = 1;
    int from = path.startsWith( separator ) ? sepLen : 0;

    for ( int i = from; i < path.length(); i += sepLen ) {
      if ( path.substring( i, i + sepLen ).equalsIgnoreCase( separator ) ) {
        nr_separators++;
      }
    }

    String[] spath = new String[nr_separators];
    int nr = 0;
    for ( int i = from; i < path.length(); i += sepLen ) {
      if ( path.substring( i, i + sepLen ).equalsIgnoreCase( separator ) ) {
        spath[nr] = path.substring( from, i );
        nr++;

        from = i + sepLen;
      }
    }
    if ( nr < spath.length ) {
      spath[nr] = path.substring( from );
    }

    //
    // a --> { a }
    //
    if ( spath.length == 0 && path.length() > 0 ) {
      spath = new String[] { path };
    }

    return spath;
  }

}