Skip to content

hex and octal integer parsing #73

Open
wants to merge 2 commits into from

1 participant

@philtre
philtre commented Feb 22, 2012

Added a few lines to enable parsing of hexadecimal and octal numbers. It needs a few more corrections, specifically to enable this functionality only when a certain parse flag is present.

@philtre philtre commented on the diff Feb 23, 2012
JSONKit.m
@@ -1687,7 +1692,7 @@ static int jk_parse_number(JKParseState *parseState) {
parseState->token.value.ptrRange.length = sizeof(long long);
parseState->token.value.hash = (JK_HASH_INIT + parseState->token.value.type) + (JKHash)parseState->token.value.number.longLongValue;
} else {
- parseState->token.value.number.unsignedLongLongValue = strtoull((const char *)numberTempBuf, (char **)&endOfNumber, 10);
+ parseState->token.value.number.unsignedLongLongValue = strtoull((const char *)numberTempBuf, (char **)&endOfNumber, 0);
@philtre
philtre added a note Feb 23, 2012

by passing 0 as base, strtoull will decide which base to use based on the prefix (hex if prefix is 0x and octal if prefix is 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.