toml11 icon indicating copy to clipboard operation
toml11 copied to clipboard

Preserve hex number format

Open ovenpasta opened this issue 1 year ago • 1 comments

I'd like to preserve the parsed format for integral numbers, like num=0x1234 should output num=0x1234

I don't see any support for this, would like to implement it, what would be a good way to do it?

ovenpasta avatar Jan 25 '24 12:01 ovenpasta

From my understanding the TOML specification requires parsing such numbers. Would it not be easier to wrap it in quotes? num="0x1234"?

robloh avatar Apr 21 '24 19:04 robloh

I have released v4.0.0 and now you can set integer_format::hex.

toml::value v(0xC0FFEE);
v.as_integer_fmt().fmt = toml::integer_format::hex;
v.as_integer_fmt().spacer = 4; // 0xc0_ffee
v.as_integer_fmt().width = 8; // 0x00c0_ffee

These parameters are also parsed from a file. You can now preserve these format information.

ToruNiina avatar Jun 17 '24 14:06 ToruNiina