json: Add helper for quoted numbers
The JSON specification technically disallows maps with numeric keys, so we'll want to slowly migrate away from using them. This helper extracts the numeric value from a quoted number, which is a legal representation of the same in JSON.
This commit is contained in:
parent
f158b529d3
commit
83beaa5396
|
@ -88,6 +88,19 @@ bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
|
||||
{
|
||||
jsmntok_t temp;
|
||||
if (tok->type != JSMN_STRING)
|
||||
return false;
|
||||
|
||||
temp = *tok;
|
||||
temp.start += 1;
|
||||
temp.end -= 1;
|
||||
|
||||
return json_to_u64(buffer, &temp, num);
|
||||
}
|
||||
|
||||
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num)
|
||||
{
|
||||
uint64_t u64;
|
||||
|
|
|
@ -35,6 +35,10 @@ char *json_strdup(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);
|
|||
/* Extract number from this (may be a string, or a number literal) */
|
||||
bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num);
|
||||
|
||||
/* Extract number from string. The number must be the entirety of the
|
||||
* string between the '"' */
|
||||
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num);
|
||||
|
||||
/* Extract number from this (may be a string, or a number literal) */
|
||||
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num);
|
||||
|
||||
|
|
Loading…
Reference in New Issue