| 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 | ✗ | Yaml::ResultInfo Yaml::parse(String const& source, Property& target) | |
| 37 | { | ||
| 38 | ResultInfo result; | ||
| 39 | ✗ | result.chars_processed = 0; | |
| 40 | ✗ | result.succeeded = false; | |
| 41 | ✗ | Property tmp; | |
| 42 | ✗ | result_t ret = gate_yaml_parse_string(source.c_impl(), tmp.c_impl(), &result); | |
| 43 | ✗ | if (ret == GATE_RESULT_OUTOFMEMORY) | |
| 44 | { | ||
| 45 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 46 | } | ||
| 47 | ✗ | target.swap(tmp); | |
| 48 | ✗ | return result; | |
| 49 | } | ||
| 50 | ✗ | Yaml::ResultInfo Yaml::parse(Stream& source, Property& target) | |
| 51 | { | ||
| 52 | ResultInfo result; | ||
| 53 | ✗ | result.chars_processed = 0; | |
| 54 | ✗ | result.succeeded = false; | |
| 55 | ✗ | Property tmp; | |
| 56 | ✗ | result_t ret = gate_yaml_parse(source.c_impl(), tmp.c_impl(), &result); | |
| 57 | ✗ | if (ret == GATE_RESULT_OUTOFMEMORY) | |
| 58 | { | ||
| 59 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 60 | } | ||
| 61 | ✗ | target.swap(tmp); | |
| 62 | ✗ | return result; | |
| 63 | } | ||
| 64 | ✗ | Property Yaml::parse(String const& source) | |
| 65 | { | ||
| 66 | ✗ | Property prop; | |
| 67 | ✗ | ResultInfo info = Yaml::parse(source, prop); | |
| 68 | ✗ | if (!info.succeeded) | |
| 69 | { | ||
| 70 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse YAML content", (int32_t)info.lines_processed); | |
| 71 | } | ||
| 72 | ✗ | return prop; | |
| 73 | } | ||
| 74 | ✗ | Property Yaml::parse(Stream& source) | |
| 75 | { | ||
| 76 | ✗ | Property prop; | |
| 77 | ✗ | ResultInfo info = Yaml::parse(source, prop); | |
| 78 | ✗ | if (!info.succeeded) | |
| 79 | { | ||
| 80 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidContent, "Failed to parse YAML content", (int32_t)info.lines_processed); | |
| 81 | } | ||
| 82 | ✗ | return prop; | |
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | ✗ | void Yaml::build(Property const& sourceProp, Stream& stream) | |
| 87 | { | ||
| 88 | ✗ | result_t result = gate_yaml_build(sourceProp.c_impl(), stream.c_impl()); | |
| 89 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 90 | ✗ | } | |
| 91 | |||
| 92 | ✗ | String Yaml::build(Property const& sourceProp) | |
| 93 | { | ||
| 94 | ✗ | gate_string_t text = GATE_STRING_INIT_EMPTY; | |
| 95 | ✗ | result_t result = gate_yaml_build_string(sourceProp.c_impl(), &text); | |
| 96 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 97 | ✗ | return String::createFrom(text); | |
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | } // end of namespace enc | ||
| 102 | } // end of namespace gate | ||
| 103 |