| 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/yaml.hpp" | ||
| 29 | #include "gate/exceptions.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace enc | ||
| 34 | { | ||
| 35 | |||
| 36 | 1 | Yaml::ResultInfo Yaml::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.
|
2 | 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_yaml_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 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 46 | } | ||
| 47 | 1 | target.swap(tmp); | |
| 48 | 2 | return result; | |
| 49 | } | ||
| 50 | 1 | Yaml::ResultInfo Yaml::parse(Stream& source, Property& target) | |
| 51 | { | ||
| 52 | ResultInfo result; | ||
| 53 | 1 | result.chars_processed = 0; | |
| 54 | 1 | result.succeeded = false; | |
| 55 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property tmp; |
| 56 |
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_yaml_parse(source.c_impl(), tmp.c_impl(), &result); |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret == GATE_RESULT_OUTOFMEMORY) |
| 58 | { | ||
| 59 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 60 | } | ||
| 61 | 1 | target.swap(tmp); | |
| 62 | 2 | return result; | |
| 63 | } | ||
| 64 | 1 | Property Yaml::parse(String const& source) | |
| 65 | { | ||
| 66 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property prop; |
| 67 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ResultInfo info = Yaml::parse(source, prop); |
| 68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!info.succeeded) |
| 69 | { | ||
| 70 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse YAML content", (int32_t)info.lines_processed); | |
| 71 | } | ||
| 72 | 2 | return prop; | |
| 73 | } | ||
| 74 | 1 | Property Yaml::parse(Stream& source) | |
| 75 | { | ||
| 76 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property prop; |
| 77 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ResultInfo info = Yaml::parse(source, prop); |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!info.succeeded) |
| 79 | { | ||
| 80 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse YAML content", (int32_t)info.lines_processed); | |
| 81 | } | ||
| 82 | 2 | return prop; | |
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | 1 | void Yaml::build(Property const& sourceProp, Stream& stream) | |
| 87 | { | ||
| 88 | 1 | result_t result = gate_yaml_build(sourceProp.c_impl(), stream.c_impl()); | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 90 | 1 | } | |
| 91 | |||
| 92 | 1 | String Yaml::build(Property const& sourceProp) | |
| 93 | { | ||
| 94 | 1 | gate_string_t text = GATE_STRING_INIT_EMPTY; | |
| 95 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | result_t result = gate_yaml_build_string(sourceProp.c_impl(), &text); |
| 96 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 97 | 2 | return String::createFrom(text); | |
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | } // end of namespace enc | ||
| 102 | } // end of namespace gate | ||
| 103 |