RFR: JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color [v4]
ExE Boss
duke at openjdk.org
Sat Sep 17 17:16:41 UTC 2022
On Sat, 17 Sep 2022 16:33:41 GMT, ScientificWare <duke at openjdk.org> wrote:
>> This is referenced in Java Bug Database as
>> - [JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8293776)
>>
>> This is tracked in JBS as
>> - [JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://bugs.openjdk.java.net/browse/JDK-8293776)
>>
>> Adds the 4 and 8 digits color hex notations to CSS.java, as described in :
>> CSS Color Module Level 4
>> W3C Candidate Recommendation Snapshot, 5 July 2022
>> [6.2 The RGB Hexadecimal Notations: `#RRGGBB`](https://www.w3.org/TR/css-color-4/#hex-notation)
>>
>> Designed from : [ScientificWare JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://github.com/scientificware/jdk/issues/13)
>
> ScientificWare has updated the pull request incrementally with one additional commit since the last revision:
>
> Removes author name.
>
> Removes author name for JDK main-line development repository.
src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1404:
> 1402: } else if (n != 8 || !hex.matcher(digits).matches()) {
> 1403: return null;
> 1404: }
Using `charAt` avoids creating temporary strings of length `1`.
Also, using the `%[argument_index$]conversion` format specifier form allows halving the lengths of the vararg arrays.
Suggestion:
if (n == 3 && hex.matcher(digits).matches()) {
final char r = digits.charAt(0);
final char g = digits.charAt(1);
final char b = digits.charAt(2);
digits = String.format("%1$s%1$s%2$s%2$s%3$s%3$sff", r, g, b);
} else if (n == 4 && hex.matcher(digits).matches()) {
final char r = digits.charAt(0);
final char g = digits.charAt(1);
final char b = digits.charAt(2);
final char a = digits.charAt(3);
digits = String.format("%1$s%1$s%2$s%2$s%3$s%3$s%4$s%4$s", r, g, b, a);
} else if (n == 6 && hex.matcher(digits).matches()) {
digits += "ff";
} else if (n != 8 || !hex.matcher(digits).matches()) {
return null;
}
src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1407:
> 1405: try {
> 1406: Integer intValue = Integer.parseUnsignedInt(digits, 16);
> 1407: int l = intValue.intValue();
No need to box only to immediately unbox[^1]:
Suggestion:
int l = Integer.parseUnsignedInt(digits, 16);
[^1]: [`Integer.parseUnsignedInt(String, int)`] returns an unboxed `int`, not a boxed `Integer`, it’s [`Integer.valueOf(String, int)`] that does that.
[`Integer.parseUnsignedInt(String, int)`]: https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/Integer.html#parseUnsignedInt(java.lang.String,int)
[`Integer.valueOf(String, int)`]: https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/Integer.html#valueOf(java.lang.String,int)
-------------
PR: https://git.openjdk.org/jdk/pull/10317
More information about the client-libs-dev
mailing list