Skip to content

Commit c59b06c

Browse files
committed
Renamed cJSON_DataType_t Null to NullType. Removed cJSON_UnknownValueType_Error and replaced it with cJSON_InvalidCharacterSequence_Error. Changed dict/list append functions' return type from cJSON_Result_t to void. Changed generic object malloc function to not allocate memory for string type generic objects. Added parser flags. Added parser's number parser. Worked on string parser function implementation. TODO: Bool behavior, dict/list start behavior in string parser.
1 parent b93e478 commit c59b06c

File tree

7 files changed

+318
-41
lines changed

7 files changed

+318
-41
lines changed

inc/cJSON.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cJSON_Result_t cJSON_delGenObj(cJSON_Generic_t GObj);
5555
*
5656
* @param GOptr cJSON_Generic pointer, where the parsed structure will be saved in.
5757
* @param str String containing the JSON data.
58-
* @return cJSON_Result_t Returns cJSON_Ok by default. Can return the following errors: cJSON_Structure_Error, cJSON_DepthOutOfRange_Error.
58+
* @return cJSON_Result_t Returns cJSON_Ok by default. Can return one of the following errors: cJSON_DepthOutOfRange_Error, cJSON_Structure_Error, cJSON_InvalidCharacterSequence_Error.
5959
*/
6060
cJSON_Result_t cJSON_parseStr(cJSON_Generic_t *GObjPtr, char *str);
6161

inc/cJSON_Parser_Util.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,28 @@
1515
#include "../inc/cJSON_Types.h"
1616
#include "../inc/cJSON_Util.h"
1717

18+
// --- Defines ---
19+
20+
// - Flag Defines -
21+
#pragma region Flag Defines
22+
23+
#define CJP_DICT_END_POSSIBLE 0x01 // "}" possible
24+
#define CJP_LIST_END_POSSIBLE 0x02 // "]" possible
25+
#define CJP_ITEM_SEPT_POSSIBLE 0x04 // "," possible
26+
#define CJP_DICT_KEY_POSSIBLE 0x08 // Dictionary key (string) possible
27+
#define CJP_DICT_SEPT_POSSIBLE 0x10 // ":" possible
28+
#define CJP_DICT_VALUE_POSSIBLE 0x20 // Value possible (top of object stack is a dictionary)
29+
#define CJP_LIST_VALUE_POSSIBLE 0x40 // Value possible (top of object stack is a list)
30+
31+
#pragma endregion
32+
33+
34+
1835
// --- Macros ---
1936

37+
// - Character Case Macros -
38+
#pragma region Character Case Macros
39+
2040
/**
2141
* @brief Macro used to change an alphabetical character to lower case
2242
*
@@ -28,6 +48,8 @@
2848
*/
2949
#define UPPER_CASE_CHAR(c) ((((c) > 0x40) && ((c) < 0x5B)) ? ((c) & 0xDF) : (c))
3050

51+
#pragma endregion
52+
3153

3254

3355
// --- Typedefs ---
@@ -63,7 +85,7 @@ typedef struct cJSON_StringBuilder_DoubleBuffer
6385
* @param outputStrPtr Pointer to a string pointer variable where the extracted and formatted string should be stored.
6486
* @return char* Returns
6587
*/
66-
static cJSON_Result_t cJSON_Parser_StringBuilder(char **refStrPtr, char **outputStrPtr);
88+
cJSON_Result_t cJSON_Parser_StringBuilder(char **refStrPtr, char **outputStrPtr);
6789

6890
/**
6991
* @brief Function used to add a character to a double buffer.
@@ -75,4 +97,17 @@ static void SB_DB_AddChar(cJSON_SB_DB_t *SbDb, const char c);
7597

7698
#pragma endregion
7799

100+
// - Number Parser Function Prototypes -
101+
#pragma region Number Parser Function Prototypes
102+
103+
/**
104+
* @brief Function used to extract a number from the current location of the refStrPtr
105+
*
106+
* @param refStrPtr Pointer to the start location of the number that is to be extracted inside of the original string that is to be parsed. Pointer pointer is also used to skip that segment of the string by incrementing the original string pointer.
107+
* @return cJSON_Generic_t Generic object containing the parsed integer or float.
108+
*/
109+
cJSON_Generic_t cJSON_Parser_NumParser(char **refStrPtr);
110+
111+
#pragma endregion
112+
78113
#endif

inc/cJSON_Types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ typedef bool cJSON_Bool_t;
132132
*/
133133
typedef enum cJSON_DataType
134134
{
135-
Null = 0,
135+
NullType = 0,
136136
Dictionary,
137137
List,
138138
String,
@@ -145,10 +145,10 @@ typedef enum cJSON_Result
145145
{
146146
cJSON_Ok,
147147
cJSON_Datatype_Error,
148-
cJSON_Structure_Error,
149148
cJSON_DepthOutOfRange_Error,
149+
cJSON_InvalidCharacterSequence_Error,
150150
cJSON_NotAllocated_Error,
151-
cJSON_UnknownValueType_Error,
151+
cJSON_Structure_Error,
152152
cJSON_Unknown_Error
153153
} cJSON_Result_t;
154154

inc/cJSON_Util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ cJSON_Generic_t mallocGenObj(cJSON_ContainerType_t containerType);
7575
* @param valObj Value cJSON generic object.
7676
* @return cJSON_Result_t
7777
*/
78-
cJSON_Result_t cJSON_appendToDict(cJSON_Dict_t *dictPtr, const cJSON_Key_t key, cJSON_Generic_t valObj);
78+
void cJSON_appendToDict(cJSON_Dict_t *dictPtr, const cJSON_Key_t key, cJSON_Generic_t valObj);
7979
/**
8080
* @brief Function to append a generic object to a list.
8181
*
8282
* @param listPtr Pointer to the list the generic object should be added to.
8383
* @param obj
8484
* @return cJSON_Result_t
8585
*/
86-
cJSON_Result_t cJSON_appendToList(cJSON_List_t *listPtr, cJSON_Generic_t obj);
86+
void cJSON_appendToList(cJSON_List_t *listPtr, cJSON_Generic_t obj);
8787

8888
#pragma endregion
8989

0 commit comments

Comments
 (0)