commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 29351] - FilenameUtils#removeExtension and FilenameUtils#getExtension don't handle all cases.
Date Thu, 03 Jun 2004 04:04:21 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29351>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29351

FilenameUtils#removeExtension and FilenameUtils#getExtension don't handle all cases.

oliver@deeper.co.nz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|FilenameUtils#removeExtensio|FilenameUtils#removeExtensio
                   |nand                        |n and
                   |FilenameUtils#getExtension  |FilenameUtils#getExtension
                   |don't handle all cases.     |don't handle all cases.



------- Additional Comments From oliver@deeper.co.nz  2004-06-03 04:04 -------
/**
     * Gets the extension of a filename.
     * <p>
     * eg
     * <pre>
     * foo.txt      --> "txt"
     * a/b/c.jpg    --> "jpg"
     * a/b/c        --> ""
     * a.b/c.txt    --> "txt"
     * a.b/c        --> ""
     * </pre>
     *
     * @param filename the filename to retreive the extension of.
     * @return the extension of filename or an empty string if none exists.
     */
    public static String getExtension(final String filename) {
        String suffix = "";
        String shortFilename = filename;

        int lastDirSeparator = filename.lastIndexOf(File.separatorChar);
        if(lastDirSeparator > 0){
            shortFilename = filename.substring(lastDirSeparator + 1);
        }

        int index = shortFilename.lastIndexOf('.');

        if (index > 0 && index < shortFilename.length() - 1) {
            suffix = shortFilename.substring(index + 1);
        }

        return suffix;
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message