Sorry, the previous simple regex was incorrect. It should have at least 1
character after the x:
0[xX][0-9a-fA-F]{1,16}Anyway, parsing a number by code or regex has a lot of cases to consider and the intent should be documented. On Thu, 4 Mar 2021 at 00:47, Alex Herbert <[email protected]> wrote: > It also makes me ask if we are adding this then why not methods to query > the other Java formats for literals: > > Binary = 0b... > Octal = 0... > Hex = 0x... > > isBinaryLiteral() > isOctalLiteral() > isHexLiteral() > > It also assumes that the number is an integer. But the binary literal > formats cover floating point too, e.g. > > float f = -0x0.1abcdefp-12f; > > Parsing this is far more complex than detecting the hex characters in a > regex type manner: 0[xX][0-9a-fA-F]{0,16}. > > > On Thu, 4 Mar 2021 at 00:31, Gary Gregory <[email protected]> wrote: > >> I am not convinced this belong in Lang. Maybe in a Math module? Maybe in >> Text? >> >> Gary >> >> On Wed, Mar 3, 2021, 19:29 GitBox <[email protected]> wrote: >> >> > >> > aherbert commented on pull request #727: >> > URL: >> > https://github.com/apache/commons-lang/pull/727#issuecomment-790185530 >> > >> > >> > Is the intention that this should match `isCreateable(String)` for >> all >> > valid hex numbers and return `true` for all hex cases where a `Number` >> is >> > returned from `createNumber(String)`? >> > ```java >> > public static boolean isCreatable(final String str) >> > public static Number createNumber(final String str) >> > ``` >> > If so then you should support the `#` character (and all the other >> hex >> > prefixes) and update the javadoc to reflect the intention. >> > >> > I would then update the test to use all the hex cases from the tests >> > for `createNumber` and `isCreateable` to ensure it returns `true` when >> > those methods succeed. >> > >> > Currently your test only covers a range of `int` and `long` values, >> no >> > hex variants and does not specify whether BigInteger values are also >> `true`. >> > >> > It will also fail on valid hex numbers such as `0x1L`. >> > >> > >> > >> > >> > ---------------------------------------------------------------- >> > This is an automated message from the Apache Git Service. >> > To respond to the message, please log on to GitHub and use the >> > URL above to go to the specific comment. >> > >> > For queries about this service, please contact Infrastructure at: >> > [email protected] >> > >> > >> > >> >
