RFR: 8251989: Hex formatting and parsing utility [v11]
Roger Riggs
rriggs at openjdk.java.net
Fri Nov 27 20:48:36 UTC 2020
> java.util.HexFormat utility:
>
> - Format and parse hexadecimal strings, with parameters for delimiter, prefix, suffix and upper/lowercase
> - Static factories and builder methods to create HexFormat copies with modified parameters.
> - Consistent naming of methods for conversion of byte arrays to formatted strings and back: formatHex and parseHex
> - Consistent naming of methods for conversion of primitive types: toHexDigits... and fromHexDigits...
> - Prefix and suffixes now apply to each formatted value, not the string as a whole
> - Using java.util.Appendable as a target for buffered conversions so output to Writers and PrintStreams
> like System.out are supported in addition to StringBuilder. (IOExceptions are converted to unchecked exceptions)
> - Immutable and thread safe, a "value-based" class
>
> See the [HexFormat javadoc](http://cr.openjdk.java.net/~rriggs/8251989-hex-formatter/java.base/java/util/HexFormat.html) for details.
>
> Review comments and suggestions welcome.
Roger Riggs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 21 additional commits since the last revision:
- Merge branch 'master' into 8251989-hex-formatter
- Addressed review comments on use of formatted hexadecimal strings, updated copyrights, etc.
- Clarified that suffix() and prefix() methods do not return null, instead the empty string is returned.
- Merge branch 'master' into 8251989-hex-formatter
- Merge branch 'master' into 8251989-hex-formatter
- Merge branch 'master' into 8251989-hex-formatter
- The HexFormat API indexing model for array and string ranges is changed
to describe the range using 'fromIndex (inclusive)' and 'toIndex (exclusive)'.
Initially, it was specified as 'index' and 'length'. However, both byte arrays
and strings used in the HexFormat API typically use fromIndex and toIndex
to describe ranges. Using the same indexing model can prevent mistakes.
The change affects the methods and corresponding tests:
formatHex(byte[] bytes, int fromIndex, int toIndex)
formatHex(A out, byte[] bytes, int fromIndex, int toIndex)
parseHex(char[] chars, int fromIndex, int toIndex)
parseHex(CharSequence string, int fromIndex, int toIndex)
fromHexDigits(CharSequence string, int fromIndex, int toIndex)
fromHexDigitsToLong(CharSequence string, int fromIndex, int toIndex)
- - Added @see and @link references to Integer.toHexString and Long.toHexString
- Clarified parsing is case insensistive in various parse and fromXXX methods
- Source level cleanup based on review comments
- Expanded some javadoc tag text to make it more descriptive
- Consistent use of 'hexadecimal' vs 'hex'
- Review comment updates to class javadoc
- Review comment updates, in the example code, and to describe the characters used to convert to hexadecimal
- ... and 11 more: https://git.openjdk.java.net/jdk/compare/6e562b1b...29f9bf7b
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/482/files
- new: https://git.openjdk.java.net/jdk/pull/482/files/b19d2827..29f9bf7b
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=482&range=10
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=482&range=09-10
Stats: 11696 lines in 333 files changed: 4100 ins; 1568 del; 6028 mod
Patch: https://git.openjdk.java.net/jdk/pull/482.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/482/head:pull/482
PR: https://git.openjdk.java.net/jdk/pull/482
More information about the core-libs-dev
mailing list