forked from zserge/jsmn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsmn_utils.h
95 lines (81 loc) · 2.39 KB
/
jsmn_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef JSMN_UTILS_H_
#define JSMN_UTILS_H_
#include <stdarg.h>
#include <stdint.h>
#include "jsmn_defines.h"
#define JSMN_HEADER
#include "jsmn.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Return a pointer to jsmn error message
*
* @param[in] errno jsmn error number
* @return const char* jsmn error message
*/
const char *jsmn_strerror(jsmnerr errno);
/**
* @brief Tokenizes JSON string
*
* @param[in] json JSON String
* @param[in] json_len Length of JSON String
* @param[out] rv Return Value
* @return Allocated jsmntok_t array pointer
*/
jsmntok_t *jsmn_tokenize(const char *json, const size_t json_len, jsmnint_t *rv);
/**
* @brief Tokenize JSON string
*
* @param[out] tokens Pointer to preallocated Tokens
* @param[in] num_tokens Number of Tokens
* @param[in] json JSON String
* @param[in] json_len Length of JSON String
* @return Return Value
*/
jsmnint_t jsmn_tokenize_noalloc(jsmntok_t *tokens, const uint32_t num_tokens, const char *json, const size_t json_len);
/**
* @brief String comparison between token and string
*
* @param[in] json JSON String
* @param[in] tok Token to compare
* @param[in] s String to complare
* @return 0 when token string and s are equal, -1 otherwise
*/
int jsmn_streq(const char *json, const jsmntok_t *tok, const char *s);
/**
* @brief Find the previous sibling of token at position t
*
* @param[in] tokens jsmn tokens
* @param[in] t the position of the token
* @return jsmnint_t the position of t's previous sibling, else JSMN_NEG
*/
jsmnint_t jsmn_get_prev_sibling(const jsmntok_t *tokens, const jsmnint_t t);
/**
* @brief Find the next sibling of token at position t
*
* @param[in] tokens jsmn tokens
* @param[in] t the position of the token
* @return jsmnint_t the position of t's next sibling, else JSMN_NEG
*/
jsmnint_t jsmn_get_next_sibling(const jsmntok_t *tokens, const jsmnint_t t);
/**
* @brief Look for a value in a JSON string
*
* @param[in] json json string
* @param[in] tokens jsmn tokens
* @param[in] num_keys number of keys
* @return jsmnint_t position of value requested
*/
jsmnint_t jsmn_lookup(const char *json, const jsmntok_t *tokens, const size_t num_keys, ...);
/**
* @brief Print an extremely verbose description of JSON string
*
* @param[in] json JSON String
* @param[in] len Length of JSON String
*/
void jsmn_explodeJSON(const char *json, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* JSMN_UTILS_H_ */