mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
json: add a helper to split a json token given a specific character
credits @rustyrussell
This commit is contained in:
@@ -75,3 +75,19 @@ bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
|||||||
return bitcoin_txid_from_hex(buffer + tok->start,
|
return bitcoin_txid_from_hex(buffer + tok->start,
|
||||||
tok->end - tok->start, txid);
|
tok->end - tok->start, txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||||
|
char split,
|
||||||
|
jsmntok_t *a,
|
||||||
|
jsmntok_t *b)
|
||||||
|
{
|
||||||
|
const char *p = memchr(buffer + tok->start, split, tok->end - tok->start);
|
||||||
|
if (!p)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*a = *b = *tok;
|
||||||
|
a->end = p - buffer;
|
||||||
|
b->start = p + 1 - buffer;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,4 +39,10 @@ bool json_to_msat(const char *buffer, const jsmntok_t *tok,
|
|||||||
/* Extract a bitcoin txid from this */
|
/* Extract a bitcoin txid from this */
|
||||||
bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
||||||
struct bitcoin_txid *txid);
|
struct bitcoin_txid *txid);
|
||||||
|
|
||||||
|
/* Split a json token into 2 tokens given a splitting character */
|
||||||
|
bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||||
|
char split,
|
||||||
|
jsmntok_t *a,
|
||||||
|
jsmntok_t *b);
|
||||||
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */
|
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user