RFR 8057113: (fs) Path should have a method to test the filename extension
Roger Riggs
Roger.Riggs at Oracle.com
Fri Feb 16 21:34:48 UTC 2018
Hi,
On 2/16/2018 3:20 PM, Brian Burkhalter wrote:
> Hi Daniel,
>
> On Feb 16, 2018, at 10:32 AM, Daniel Fuchs <daniel.fuchs at oracle.com
> <mailto:daniel.fuchs at oracle.com>> wrote:
>
>> As David noted, .vimrc is a filename - not an extension,
>> and the Unix/Linux basename command will treat it as such:
>>
>> $ basename ~/.vimrc .vimrc
>> .vimrc
>>
>> I think we should try to honor this expectation.
>> However:
>>
>> $ basename ~/.vimrc.vimrc .vimrc
>> .vimrc
>
> Extrapolating it seems that maybe the extension should be empty if the
> prefix is one or more dots and there are no more dots in what the
> basename would return. What then do we do about cases such as
> .java.policy? It seems the result might better be “policy” than empty.
>
>> So would the code below work?
>>
>> String filename = Optional.ofNullable(getFilename())
>> .map(Object::toString).orElse("");
>> int index = filename.lastIndexOf('.');
>> if (index > 0) return filename.substring(index+1);
>> else return ""
>
> It looks like for the aberration “..foo” the above would return “foo”
> which I am not sure we would want.
The convention for a single leading "." to indicate a hidden file is fine.
To keep it simple, the last "." that is not the first character can be
the delimiter for the extension.
"." ext ""
".." ext ""
".a.b" ext "b"
"......." ext ""
".....a" ext "a"
"....a.b" ext "b"
"..foo" ext "foo"
It might be useful to check how native unix utilities parse these cases.
Roger
>
> Thanks,
>
> Brian
More information about the nio-dev
mailing list