config icon indicating copy to clipboard operation
config copied to clipboard

Support Java7's Underscores in Numeric Literals

Open vitamon opened this issue 11 years ago • 6 comments

Would be great to support numbers like this:

long creditCardNumber = 1234_5678_9012_3456L;

http://docs.oracle.com/javase/8/docs/technotes/guides/language/underscores-literals.html

vitamon avatar Jul 28 '14 14:07 vitamon

+1

analytically avatar Jul 31 '14 13:07 analytically

Does it work to just remove underscores before doing the new BigInteger("123")? should be a simple patch. though I admit confusion on the credit card number example, aren't those usually treated as strings?

A PR for this should also have a patch to the HOCON.md spec probably with a link to the relevant java spec.

havocp avatar Jul 31 '14 15:07 havocp

I think this is a semantic break unfortunately (because right now this will get parsed as a string). If you have 1_0 now and getString you could get "1_0", but with this change you would get "10". So this would have to be in an ABI-breaking (spec-breaking even) release, which we don't have a current concrete plan for but I have a github issues label to track such requests.

havocp avatar Aug 11 '14 15:08 havocp

Since it's somewhat related (and has the same breaking problem), I decided to comment here instead of creating a new issue: is there a chance to get support for specifying integer settings in hexadecimal notation? I.e. "background = 0x00FF00". Would be really nice for color settings - sure I can do Integer.decode(config.getString(...)) (and will, for now), but having this integrated in the library for more homogenous errors would be neat.

fnuecke avatar Aug 15 '14 11:08 fnuecke

Yeah basically that's an analogous situation with breaking things; but would be a simple change to make.

havocp avatar Aug 18 '14 16:08 havocp

I don't think the getString should be modified and the original, raw value should be returned. This would match the behavior of using scientific notation:

# The maximum number of entries in the cache
maximum-size = 1e8

config.getString("maximum-size")
> 1e8
config.getLong("maximum-size");
> 100000000

ben-manes avatar Nov 23 '20 20:11 ben-manes