Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | #include "gate/encode/json.hpp" | ||
29 | #include "gate/exceptions.hpp" | ||
30 | |||
31 | namespace gate | ||
32 | { | ||
33 | namespace enc | ||
34 | { | ||
35 | |||
36 | 1 | Json::ResultInfo Json::parse(String const& source, Property& target) | |
37 | { | ||
38 | ResultInfo result; | ||
39 | 1 | result.chars_processed = 0; | |
40 | 1 | result.succeeded = false; | |
41 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property tmp; |
42 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | result_t ret = gate_json_parse_string(source.c_impl(), tmp.c_impl(), &result); |
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret == GATE_RESULT_OUTOFMEMORY) |
44 | { | ||
45 | ✗ | raiseException(ret, NULL, "Json::parse"); | |
46 | } | ||
47 | 1 | target.swap(tmp); | |
48 | 2 | return result; | |
49 | } | ||
50 | |||
51 | ✗ | Json::ResultInfo Json::parse(Stream& source, Property& target) | |
52 | { | ||
53 | ResultInfo result; | ||
54 | ✗ | result.chars_processed = 0; | |
55 | ✗ | result.succeeded = false; | |
56 | ✗ | Property tmp; | |
57 | ✗ | result_t ret = gate_json_parse(source.c_impl(), tmp.c_impl(), &result); | |
58 | ✗ | if (ret == GATE_RESULT_OUTOFMEMORY) | |
59 | { | ||
60 | ✗ | raiseException(ret, NULL, "Json::parse"); | |
61 | } | ||
62 | ✗ | target.swap(tmp); | |
63 | ✗ | return result; | |
64 | } | ||
65 | |||
66 | 1 | Property Json::parse(String const& source) | |
67 | { | ||
68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property ret; |
69 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ResultInfo result = Json::parse(source, ret); |
70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!result.succeeded) |
71 | { | ||
72 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse JSON content", (int32_t)result.chars_processed); | |
73 | } | ||
74 | 2 | return ret; | |
75 | } | ||
76 | ✗ | Property Json::parse(Stream& source) | |
77 | { | ||
78 | ✗ | Property ret; | |
79 | ✗ | ResultInfo result = Json::parse(source, ret); | |
80 | ✗ | if (!result.succeeded) | |
81 | { | ||
82 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse JSON content", (int32_t)result.chars_processed); | |
83 | } | ||
84 | ✗ | return ret; | |
85 | } | ||
86 | |||
87 | 1 | void Json::build(Property const& sourceProp, StringBuilder& builder, uint32_t lineIndent) | |
88 | { | ||
89 | 1 | result_t result = gate_json_build_string(sourceProp.c_impl(), builder.c_impl(), lineIndent); | |
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
91 | 1 | } | |
92 | |||
93 | 1 | String Json::build(Property const& sourceProp, uint32_t lineIndent) | |
94 | { | ||
95 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder; |
96 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Json::build(sourceProp, builder, lineIndent); |
97 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
98 | } | ||
99 | |||
100 | ✗ | void Json::build(Property const& sourceProp, Stream& target, uint32_t lineIndent) | |
101 | { | ||
102 | ✗ | result_t result = gate_json_build(sourceProp.c_impl(), target.c_impl(), lineIndent); | |
103 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
104 | ✗ | } | |
105 | |||
106 | } // end of namespace enc | ||
107 | } // end of namespace gate | ||
108 |