On Thu, 18 Jan 2024 19:25:28 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> wrote:
>> Currently String::translateEscapes does not support unicode escapes, >> reported as a IllegalArgumentException("Invalid escape sequence: ..."). >> String::translateEscapes should translate unicode escape sequences to >> provide full coverage, > > src/java.base/share/classes/java/lang/String.java line 4274: > >> 4272: break; >> 4273: case 'u': >> 4274: if (from + 4 <= length) { > > Avoids a potential overflow > Suggestion: > > if (from <= length - 4) { Good. > src/java.base/share/classes/java/lang/String.java line 4281: > >> 4279: } catch (NumberFormatException ex) { >> 4280: throw new >> IllegalArgumentException("Invalid unicode sequence: " + hex); >> 4281: } > > Avoids an allocation on a valid sequence, but is perhaps slower. > Suggestion: > > from += 4; > try { > ch = (char) Integer.parseInt(this, from - 4, > from, 16); > } catch (NumberFormatException ex) { > throw new IllegalArgumentException("Invalid > unicode sequence: " + substring(from - 4, from)); > } Good. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/17491#discussion_r1457941024 PR Review Comment: https://git.openjdk.org/jdk/pull/17491#discussion_r1457941676