RFR 8057113: (fs) Path should have a method to test the filename extension
Daniel Fuchs
daniel.fuchs at oracle.com
Fri Feb 16 18:32:41 UTC 2018
Hi Brian,
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
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 ""
best regards,
-- daniel
On 16/02/2018 18:06, Brian Burkhalter wrote:
> On Feb 16, 2018, at 8:48 AM, Brian Burkhalter
> <brian.burkhalter at oracle.com <mailto:brian.burkhalter at oracle.com>> wrote:
>
>> On Feb 16, 2018, at 6:26 AM, David Lloyd <david.lloyd at redhat.com
>> <mailto:david.lloyd at redhat.com>> wrote:
>>
>>> If lastDot is 0 or all the characters preceding lastDot are '.' then
>>> "" should be returned as well; this for example will not only return
>>> wrong results for ".." but also e.g. ".vimrc".
>>
>> You are correct about “.vimrc” but the other cases appear to pass
>> (expected result in the test is “” for these four cases):
>
> This seems to be getting too complicated with all the special cases.
> Perhaps this should just be re-specified simply always to return
>
> getFileName().substring(getFileName().lastIndexOf(‘.”) + 1)
>
> unless getFileName() returns null or lastIndexOf(‘.’) returns -1 in
> which cases “” would be returned?
>
> Thanks,
>
> Brian
More information about the nio-dev
mailing list