git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / include / formats / rjson_helpers.h
CommitLineData
3719602c
PC
1/* Copyright (C) 2010-2020 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (rjson.h).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef __LIBRETRO_SDK_FORMAT_RJSON_HELPERS_H__
24#define __LIBRETRO_SDK_FORMAT_RJSON_HELPERS_H__
25
26#include <retro_common_api.h>
27#include <retro_inline.h> /* INLINE */
28#include <boolean.h> /* bool */
29#include <stddef.h> /* size_t */
30
31RETRO_BEGIN_DECLS
32
33/* Functions to add JSON token characters */
34static INLINE void rjsonwriter_add_start_object(rjsonwriter_t *writer)
35 { rjsonwriter_raw(writer, "{", 1); }
36
37static INLINE void rjsonwriter_add_end_object(rjsonwriter_t *writer)
38 { rjsonwriter_raw(writer, "}", 1); }
39
40static INLINE void rjsonwriter_add_start_array(rjsonwriter_t *writer)
41 { rjsonwriter_raw(writer, "[", 1); }
42
43static INLINE void rjsonwriter_add_end_array(rjsonwriter_t *writer)
44 { rjsonwriter_raw(writer, "]", 1); }
45
46static INLINE void rjsonwriter_add_colon(rjsonwriter_t *writer)
47 { rjsonwriter_raw(writer, ":", 1); }
48
49static INLINE void rjsonwriter_add_comma(rjsonwriter_t *writer)
50 { rjsonwriter_raw(writer, ",", 1); }
51
52/* Functions to add whitespace characters */
53/* These do nothing with the option RJSONWRITER_OPTION_SKIP_WHITESPACE */
54static INLINE void rjsonwriter_add_newline(rjsonwriter_t *writer)
55 { rjsonwriter_raw(writer, "\n", 1); }
56
57static INLINE void rjsonwriter_add_space(rjsonwriter_t *writer)
58 { rjsonwriter_raw(writer, " ", 1); }
59
60static INLINE void rjsonwriter_add_tab(rjsonwriter_t *writer)
61 { rjsonwriter_raw(writer, "\t", 1); }
62
63static INLINE void rjsonwriter_add_unsigned(rjsonwriter_t *writer, unsigned value)
64 { rjsonwriter_rawf(writer, "%u", value); }
65
66/* Add a signed or unsigned integer or a double number */
67static INLINE void rjsonwriter_add_int(rjsonwriter_t *writer, int value)
68 { rjsonwriter_rawf(writer, "%d", value); }
69
70static INLINE void rjsonwriter_add_bool(rjsonwriter_t *writer, bool value)
71 { rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); }
72
73static INLINE void rjsonwriter_add_null(rjsonwriter_t *writer)
74 { rjsonwriter_raw(writer, "null", 4); }
75
76RETRO_END_DECLS
77
78#endif