-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
243 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// Copyright(C) 2024 Roman Fomin | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// as published by the Free Software Foundation; either version 2 | ||
// of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
#include "m_json.h" | ||
|
||
#include "cjson/cJSON.h" | ||
|
||
json_t *JS_Open(const char *data) | ||
{ | ||
return cJSON_Parse(data); | ||
} | ||
|
||
void JS_Close(json_t *json) | ||
{ | ||
cJSON_Delete(json); | ||
} | ||
|
||
boolean JS_IsNull(json_t *json) | ||
{ | ||
return cJSON_IsNull(json); | ||
} | ||
|
||
boolean JS_IsNumber(json_t *json) | ||
{ | ||
return cJSON_IsNumber(json); | ||
} | ||
|
||
boolean JS_IsString(json_t *json) | ||
{ | ||
return cJSON_IsString(json); | ||
} | ||
|
||
boolean JS_IsArray(json_t *json) | ||
{ | ||
return cJSON_IsArray(json); | ||
} | ||
|
||
json_t *JS_GetObject(json_t *json, const char *string) | ||
{ | ||
return cJSON_GetObjectItemCaseSensitive(json, string); | ||
} | ||
|
||
int JS_GetArraySize(json_t *json) | ||
{ | ||
return cJSON_GetArraySize(json); | ||
} | ||
|
||
json_t *JS_GetArrayItem(json_t *json, int index) | ||
{ | ||
return cJSON_GetArrayItem(json, index); | ||
} | ||
|
||
double JS_GetNumber(json_t *json) | ||
{ | ||
return json->valuedouble; | ||
} | ||
|
||
int JS_GetInteger(json_t *json) | ||
{ | ||
return json->valueint; | ||
} | ||
|
||
const char *JS_GetString(json_t *json) | ||
{ | ||
return json->valuestring; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright(C) 2024 Roman Fomin | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// as published by the Free Software Foundation; either version 2 | ||
// of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
#ifndef M_JSON_H | ||
#define M_JSON_H | ||
|
||
#include "doomtype.h" | ||
|
||
typedef struct cJSON json_t; | ||
|
||
json_t *JS_Open(const char *data); | ||
void JS_Close(json_t *json); | ||
|
||
json_t *JS_GetObject(json_t *json, const char *string); | ||
|
||
boolean JS_IsNull(json_t *json); | ||
boolean JS_IsNumber(json_t *json); | ||
boolean JS_IsString(json_t *json); | ||
boolean JS_IsArray(json_t *json); | ||
|
||
double JS_GetNumber(json_t *json); | ||
int JS_GetInteger(json_t *json); | ||
const char *JS_GetString(json_t *json); | ||
|
||
int JS_GetArraySize(json_t *json); | ||
json_t *JS_GetArrayItem(json_t *json, int index); | ||
|
||
#define JS_ArrayForEach(element, array) \ | ||
for (int __index = 0, __size = JS_GetArraySize((array)); \ | ||
__index < __size && ((element) = JS_GetArrayItem((array), __index)); \ | ||
++__index) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.