static protected void normalizePath ( CharBuffer cb , String oldPath , String newPath , int offset , char separatorChar ) { cb . clear ( ) ; cb . append ( oldPath ) ; if ( cb . length ( ) == 0 || cb . lastChar ( ) != ' ' ) cb . append ( ' ' ) ; int length = newPath . length ( ) ; int i = offset ; while ( i < length ) { char ch = newPath . charAt ( i ) ; char ch2 ; switch ( ch ) { default : if ( ch != separatorChar ) { cb . append ( ch ) ; i ++ ; break ; } // the separator character falls through to be treated as '/' case ' ' : // "//" -> "/" if ( cb . lastChar ( ) != ' ' ) cb . append ( ' ' ) ; i ++ ; break ; case ' ' : if ( cb . lastChar ( ) != ' ' ) { cb . append ( ' ' ) ; i ++ ; break ; } // "/." -> "" if ( i + 1 >= length ) { i += 2 ; break ; } switch ( newPath . charAt ( i + 1 ) ) { default : if ( newPath . charAt ( i + 1 ) != separatorChar ) { cb . append ( ' ' ) ; i ++ ; break ; } // the separator falls through to be treated as '/' // "/./" -> "/" case ' ' : i += 2 ; break ; // "foo/.." -> "" case ' ' : if ( ( i + 2 >= length || ( ch2 = newPath . charAt ( i + 2 ) ) == ' ' || ch2 == separatorChar ) && cb . lastChar ( ) == ' ' ) { int segment = cb . lastIndexOf ( ' ' , cb . length ( ) - 2 ) ; if ( segment == - 1 ) { cb . clear ( ) ; cb . append ( ' ' ) ; } else cb . length ( segment + 1 ) ; i += 3 ; } else { cb . append ( ' ' ) ; i ++ ; } break ; } } } // strip trailing "/" /* if (cb.length() > 1 && cb.getLastChar() == '/') cb.setLength(cb.length() - 1); */ }
Normalizes a filesystemPath path .