google / guava

Google core libraries for Java
Apache License 2.0
50.07k stars 10.87k forks source link

CharMatcher.HEXADECIMAL #1031

Open gissuebot opened 9 years ago

gissuebot commented 9 years ago

Original issue created by em...@soldal.org on 2012-06-14 at 02:14 PM


Hexadecimal checking seems to be something that I do rather often, Could we add this to CharMatcher as a standard matcher?

gissuebot commented 9 years ago

Original comment posted by kevinb@google.com on 2012-06-19 at 05:54 PM


(No comment entered for this change.)


Status: Acknowledged Labels: Type-Addition, Package-Base

gissuebot commented 9 years ago

Original comment posted by wasserman.louis on 2012-06-22 at 02:21 PM


Generalization: CharMatcher.digits(int radix), with implementation

public boolean matches(char c) {   return Character.digit(c, radix) != -1; }

gissuebot commented 9 years ago

Original comment posted by kevinb@google.com on 2012-06-22 at 06:16 PM


(No comment entered for this change.)


Status: Research

gissuebot commented 9 years ago

Original comment posted by kostmo on 2013-12-25 at 01:12 PM


Two solutions I came up with, neither very nice: CharMatcher.anyOf("0123456789abcdefABCDEF") or CharMatcher.inRange('0', '9').or(CharMatcher.inRange('a', 'f')).or(CharMatcher.inRange('A', 'F'))

gissuebot commented 9 years ago

Original comment posted by cpovirk@google.com on 2014-01-08 at 04:04 PM


The main question I have for this is "What will the code do differently if it knows the input is only hex digits?" In most cases, I would still expect for parsing to be able to fail: parseInt could be given a value that's out of range or empty. BaseEncoding could be given uppercase/lowercase when it expects the reverse, or it could be given an odd number of characters.

Another possibility is the opposite problem: parseInt also accepts negative signs (though probably some users want an unsigned parse method, anyway). BaseEncoding also accepts separators. CharMatcher.HEXADECIMAL would reject both.