mirror of
https://github.com/rafagafe/tiny-json.git
synced 2025-03-12 19:25:30 +00:00
Refactor
This commit is contained in:
parent
4b5187975e
commit
cac8c847b7
18
tiny-json.c
18
tiny-json.c
@ -102,7 +102,7 @@ static bool isHexaDigit( unsigned char nibble ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Parse 4 charcters.
|
||||
/** Parse 4 characters.
|
||||
* @Param str Pointer to first digit.
|
||||
* @retval '?' If the four characters are hexadecimal digits.
|
||||
* @retcal '\0' In other cases. */
|
||||
@ -176,7 +176,7 @@ static char* textValue( char* ptr, json_t* property ) {
|
||||
/** Compare two strings until get the null character in the second one.
|
||||
* @param ptr sub string
|
||||
* @param str main string
|
||||
* @retval Pointer to next chraracter.
|
||||
* @retval Pointer to next character.
|
||||
* @retval Null pointer if any error occur. */
|
||||
static char* checkStr( char* ptr, char const* str ) {
|
||||
while( *str )
|
||||
@ -186,7 +186,7 @@ static char* checkStr( char* ptr, char const* str ) {
|
||||
}
|
||||
|
||||
/** Parser a string to get a primitive value.
|
||||
* If the first character after the value is diferent of '}' or ']' is set to '\0'.
|
||||
* If the first character after the value is different of '}' or ']' is set to '\0'.
|
||||
* @param str Pointer to first character.
|
||||
* @param property Property handler to set the value and the type, (true, false or null).
|
||||
* @param value String with the primitive literal.
|
||||
@ -202,7 +202,7 @@ static char* primitiveValue( char* ptr, json_t* property, char const* value, jso
|
||||
}
|
||||
|
||||
/** Parser a string to get a true value.
|
||||
* If the first character after the value is diferent of '}' or ']' is set to '\0'.
|
||||
* If the first character after the value is different of '}' or ']' is set to '\0'.
|
||||
* @param str Pointer to first character.
|
||||
* @param property Property handler to set the value and the type, (true, false or null).
|
||||
* @retval Pointer to first non white space after the string. If success.
|
||||
@ -212,7 +212,7 @@ static char* trueValue( char* ptr, json_t* property ) {
|
||||
}
|
||||
|
||||
/** Parser a string to get a false value.
|
||||
* If the first character after the value is diferent of '}' or ']' is set to '\0'.
|
||||
* If the first character after the value is different of '}' or ']' is set to '\0'.
|
||||
* @param str Pointer to first character.
|
||||
* @param property Property handler to set the value and the type, (true, false or null).
|
||||
* @retval Pointer to first non white space after the string. If success.
|
||||
@ -222,7 +222,7 @@ static char* falseValue( char* ptr, json_t* property ) {
|
||||
}
|
||||
|
||||
/** Parser a string to get a null value.
|
||||
* If the first character after the value is diferent of '}' or ']' is set to '\0'.
|
||||
* If the first character after the value is different of '}' or ']' is set to '\0'.
|
||||
* @param str Pointer to first character.
|
||||
* @param property Property handler to set the value and the type, (true, false or null).
|
||||
* @retval Pointer to first non white space after the string. If success.
|
||||
@ -254,7 +254,7 @@ static char* fraqValue( char* ptr ) {
|
||||
}
|
||||
|
||||
/** Parser a string to get a numerical value.
|
||||
* If the first character after the value is diferent of '}' or ']' is set to '\0'.
|
||||
* If the first character after the value is different of '}' or ']' is set to '\0'.
|
||||
* @param str Pointer to first character.
|
||||
* @param property Property handler to set the value and the type: JSON_REAL or JSON_INTEGER.
|
||||
* @retval Pointer to first non white space after the string. If success.
|
||||
@ -375,7 +375,7 @@ static char* objValue( char* ptr, json_t* obj, jsonPool_t* pool ) {
|
||||
|
||||
/** Initialize a json pool.
|
||||
* @param pool The handler of the pool.
|
||||
* @return a instace of a json. */
|
||||
* @return a instance of a json. */
|
||||
static json_t* poolInit( jsonPool_t* pool ) {
|
||||
pool->nextFree = 1;
|
||||
return &pool->mem[0];
|
||||
@ -442,7 +442,7 @@ static char* goNum( char* str ) {
|
||||
/** Set of characters that defines the end of an array or a JSON object. */
|
||||
static char const* const endofblock = "}]";
|
||||
|
||||
/** Set a char to '\0' and increase its pointer if the char is diferent to '}' or ']'.
|
||||
/** Set a char to '\0' and increase its pointer if the char is different to '}' or ']'.
|
||||
* @param ch Pointer to character.
|
||||
* @return Final value pointer. */
|
||||
static char* setToNull( char* ch ) {
|
||||
|
10
tiny-json.h
10
tiny-json.h
@ -31,7 +31,7 @@ extern "C" {
|
||||
/** @defgroup tinyJson Tiny JSON parser.
|
||||
* @{ */
|
||||
|
||||
/** Enumeration of codes of suported JSON properties types. */
|
||||
/** Enumeration of codes of supported JSON properties types. */
|
||||
typedef enum {
|
||||
JSON_OBJ, JSON_ARRAY, JSON_TEXT, JSON_BOOLEAN,
|
||||
JSON_INTEGER, JSON_REAL, JSON_NULL
|
||||
@ -51,7 +51,7 @@ typedef struct json_s {
|
||||
/** Parse a string to get a json.
|
||||
* @param str String pointer with a JSON object. It will be modified.
|
||||
* @param mem Array of json properties to allocate.
|
||||
* @param qty Number of elementes of mem.
|
||||
* @param qty Number of elements of mem.
|
||||
* @retval Null pointer if any was wrong in the parse process.
|
||||
* @retval If the parser process was successfully a valid handler of a json.
|
||||
* This property is always unnamed and its type is JSON_OBJ. */
|
||||
@ -82,7 +82,7 @@ static inline jsonType_t json_getType( json_t const* json ) {
|
||||
|
||||
/** Get the next sibling of a JSON property that is within a JSON object or array.
|
||||
* @param json A valid handler of a json property.
|
||||
* @retval The handler of the next sbling if found.
|
||||
* @retval The handler of the next sibling if found.
|
||||
* @retval Null pointer if the json property is the last one. */
|
||||
static inline json_t const* json_getSibling( json_t const* json ) {
|
||||
return json->sibling;
|
||||
@ -107,7 +107,7 @@ char const* json_getPropertyValue( json_t const* obj, char const* property );
|
||||
* @param json A valid handler of a json property.
|
||||
* Its type must be JSON_OBJ or JSON_ARRAY.
|
||||
* @retval The handler of the first property if there is.
|
||||
* @retval Null pointer if the json object has not porperties. */
|
||||
* @retval Null pointer if the json object has not properties. */
|
||||
static inline json_t const* json_getChild( json_t const* json ) {
|
||||
return json->u.child;
|
||||
}
|
||||
@ -127,7 +127,7 @@ static inline int64_t json_getInteger( json_t const* property ) {
|
||||
}
|
||||
|
||||
/** Get the value of a json real property.
|
||||
* @param property A valid handler of a json object.
|
||||
* @param property A valid handler of a json object.
|
||||
* Its type must be JSON_REAL or JSON_SCIENTIFIC.
|
||||
* @return The value. */
|
||||
static inline double json_getReal( json_t const* property ) {
|
||||
|
Loading…
Reference in New Issue
Block a user