RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v18]
Brian Burkhalter
bpb at openjdk.org
Mon Oct 17 17:12:12 UTC 2022
On Wed, 3 Aug 2022 22:30:53 GMT, Stuart Marks <smarks at openjdk.org> wrote:
>> src/java.base/share/classes/java/nio/file/Path.java line 297:
>>
>>> 295: if (lastPeriodIndex == length - 1) {
>>> 296: // null if all period characters, otherwise empty
>>> 297: return fileNameString.matches("\\.{" + length + "}") ?
>>
>> Using a regular expression here is probably okay for the initial PR but I could imagine this show up in profiles and needing to be re-implemented.
>
> Yeah I don't think we want to use regex here. I'd suggest something like this:
>
> int lastDot = fileNameString.lastIndexOf('.');
> for (int j = lastDot - 1; j >= 0; j--) {
> if (fileNameString.charAt(j) != '.') {
> return fileNameString.substring(lastDot + 1);
> }
> }
> return null;
No longer relevant.
-------------
PR: https://git.openjdk.org/jdk/pull/8066
More information about the nio-dev
mailing list