kazuho/picojson

Hexadecimal support

Closed this issue · 5 comments

m1tk4 commented

JSON strings like:

{ "a": 0x123 } are not parsed correctly.

The patch fixing the issue is below

m1tk4 commented

`==== //depot/sw_eng/crystal_vision/cv7-3-3/src/include/picojson/picojson.h#3 - /root/p4main/src/include/picojson/picojson.h ====


*** 753,759 ****
while (1) {
int ch = in.getc();
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-'
! || ch == 'e' || ch == 'E' || ch =='X' || ch == 'x' ) {
num_str.push_back(ch);
} else if (ch == '.') {
#if PICOJSON_USE_LOCALE
--- 753,759 ----
while (1) {
int ch = in.getc();
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-'
! || ch == 'e' || ch == 'E' || ch =='X' || ch == 'x' || ('A' <= ch && ch <='F') || ('a'<=ch && ch <='f') ) {
num_str.push_back(ch);
} else if (ch == '.') {
#if PICOJSON_USE_LOCALE
`

Thank you for the suggestion.

Unfortunately, hexadecimal numbers are not part of the JSON specification. Therefore, you cannot expect picojson to support hexadecimal numbers (of course you are free to create a custom version for yourself though).

m1tk4 commented

good point.

OTOH, decimal points other than . are not in the spec either, however you do support them through PICOJSON_USE_LOCALE, sooo maybe??? ;)

OTOH, decimal points other than . are not in the spec either, however you do support them through PICOJSON_USE_LOCALE, sooo maybe??? ;)

No, we don't.

Picojson only accepts numbers using . as the decimal point. Locale is being referred to in order to convert . to the decimal point of the locale, so that the input string can be converted to a number with strtod.

m1tk4 commented

You are right. Apologies and thank you for your work!