|
|
@@ -48,43 +48,92 @@ struct JSONPair
|
|
|
const char* val;
|
|
|
};
|
|
|
|
|
|
+/// Parses JSON documents.
|
|
|
class JSONParser
|
|
|
{
|
|
|
public:
|
|
|
|
|
|
+ /// Read the JSON document contained in the non-null @a s string.
|
|
|
+ /// @note
|
|
|
+ /// The @a s string has to remain valid for the whole parser's
|
|
|
+ /// existence scope.
|
|
|
JSONParser(const char* s);
|
|
|
|
|
|
+ /// Returns the root element of the JSON document.
|
|
|
JSONParser& root();
|
|
|
|
|
|
+ /// Returns the @a i -th item of the current array.
|
|
|
JSONParser& operator[](uint32_t i);
|
|
|
+
|
|
|
+ /// Returns the element corresponding to key @a k of the
|
|
|
+ /// current object.
|
|
|
+ /// @note
|
|
|
+ /// If the key is not unique in the object scope, the last
|
|
|
+ /// key in order of appearance will be selected.
|
|
|
JSONParser& key(const char* k);
|
|
|
|
|
|
+ /// Returns true wheter the current element is the JSON nil special value.
|
|
|
bool is_nil() const;
|
|
|
+
|
|
|
+ /// Returns true wheter the current element is a JSON boolean (true or false).
|
|
|
bool is_bool() const;
|
|
|
+
|
|
|
+ /// Returns true wheter the current element is a JSON number.
|
|
|
bool is_number() const;
|
|
|
+
|
|
|
+ /// Returns true whether the current element is a JSON string.
|
|
|
bool is_string() const;
|
|
|
+
|
|
|
+ /// Returns true whether the current element is a JSON array.
|
|
|
bool is_array() const;
|
|
|
+
|
|
|
+ /// Returns true whether the current element is a JSON object.
|
|
|
bool is_object() const;
|
|
|
|
|
|
+ /// Returns the size of the current element based on the
|
|
|
+ /// element's type:
|
|
|
+ /// * nil, bool, number: 1
|
|
|
+ /// * string: length of the string
|
|
|
+ /// * array: number of elements in the array
|
|
|
+ /// * object: number of keys in the object
|
|
|
uint32_t size();
|
|
|
|
|
|
+ /// Returns the boolean value of the current element.
|
|
|
bool bool_value() const;
|
|
|
+
|
|
|
+ /// Returns the integer value of the current element.
|
|
|
int32_t int_value() const;
|
|
|
+
|
|
|
+ /// Returns the float value of the current element.
|
|
|
float float_value() const;
|
|
|
|
|
|
public:
|
|
|
|
|
|
+ /// Returns the type of the @a s JSON text.
|
|
|
static JSONType type(const char* s);
|
|
|
|
|
|
+ /// Parses the @a s JSON string a puts its C representation into @a str.
|
|
|
static void parse_string(const char* s, List<char>& str);
|
|
|
+
|
|
|
+ /// Returns the value of the @a s JSON number as double.
|
|
|
static double parse_number(const char* s);
|
|
|
|
|
|
+ /// Returns the value of the @a s JSON boolean.
|
|
|
static bool parse_bool(const char* s);
|
|
|
+
|
|
|
+ /// Returns the value of the @a s JSON number as signed integer.
|
|
|
static int32_t parse_int(const char* s);
|
|
|
+
|
|
|
+ /// Returns the value of the @a s JSON number as float.
|
|
|
static float parse_float(const char* s);
|
|
|
|
|
|
+ /// Parses the @a s JSON array and puts it into @a array as pointers to
|
|
|
+ /// the corresponding items into the original @a s string.
|
|
|
static void parse_array(const char* s, List<const char*>& array);
|
|
|
- static void parse_object(const char* s, List<JSONPair>& map);
|
|
|
+
|
|
|
+ /// Parses the @a s JSON object and puts it into @a object as pointers to
|
|
|
+ /// the corresponding key/value pairs into the original @a s string.
|
|
|
+ static void parse_object(const char* s, List<JSONPair>& object);
|
|
|
|
|
|
private:
|
|
|
|