@ Pure @ SuppressWarnings ( "checkstyle:magicnumber" ) private static String extractLocalPath ( String filename ) { if ( filename == null ) { return null ; } final int max = Math . min ( FILE_PREFIX . length , filename . length ( ) ) ; final int inner = max - 2 ; if ( inner <= 0 ) { return filename ; } boolean foundInner = false ; boolean foundFull = false ; for ( int i = 0 ; i < max ; ++ i ) { final char c = Character . toLowerCase ( filename . charAt ( i ) ) ; if ( FILE_PREFIX [ i ] != c ) { foundFull = false ; foundInner = i >= inner ; break ; } foundFull = true ; } String fn ; if ( foundFull ) { fn = filename . substring ( FILE_PREFIX . length ) ; } else if ( foundInner ) { fn = filename . substring ( inner ) ; } else { fn = filename ; } if ( Pattern . matches ( "^(" + Pattern . quote ( URL_PATH_SEPARATOR ) + "|" //$NON-NLS-1$ //$NON-NLS-2$ + Pattern . quote ( WINDOWS_SEPARATOR_STRING ) + ")[a-zA-Z][:|].*$" , fn ) ) { //$NON-NLS-1$ fn = fn . substring ( 1 ) ; } return fn ; }
Test if the given filename is a local filename and extract the path component .