diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/yaml-cpp/src/parse.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/yaml-cpp/src/parse.cpp')
-rw-r--r-- | contrib/libs/yaml-cpp/src/parse.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/libs/yaml-cpp/src/parse.cpp b/contrib/libs/yaml-cpp/src/parse.cpp new file mode 100644 index 00000000000..0b2ae4a4f6e --- /dev/null +++ b/contrib/libs/yaml-cpp/src/parse.cpp @@ -0,0 +1,72 @@ +#include "yaml-cpp/node/parse.h" + +#include <fstream> +#include <sstream> + +#include "yaml-cpp/node/node.h" +#include "yaml-cpp/node/impl.h" +#include "yaml-cpp/parser.h" +#include "nodebuilder.h" + +namespace YAML { +Node Load(const std::string& input) { + std::stringstream stream(input); + return Load(stream); +} + +Node Load(const char* input) { + std::stringstream stream(input); + return Load(stream); +} + +Node Load(std::istream& input) { + Parser parser(input); + NodeBuilder builder; + if (!parser.HandleNextDocument(builder)) { + return Node(); + } + + return builder.Root(); +} + +Node LoadFile(const std::string& filename) { + std::ifstream fin(filename.c_str()); + if (!fin) { + throw BadFile(); + } + return Load(fin); +} + +std::vector<Node> LoadAll(const std::string& input) { + std::stringstream stream(input); + return LoadAll(stream); +} + +std::vector<Node> LoadAll(const char* input) { + std::stringstream stream(input); + return LoadAll(stream); +} + +std::vector<Node> LoadAll(std::istream& input) { + std::vector<Node> docs; + + Parser parser(input); + while (1) { + NodeBuilder builder; + if (!parser.HandleNextDocument(builder)) { + break; + } + docs.push_back(builder.Root()); + } + + return docs; +} + +std::vector<Node> LoadAllFromFile(const std::string& filename) { + std::ifstream fin(filename.c_str()); + if (!fin) { + throw BadFile(); + } + return LoadAll(fin); +} +} // namespace YAML |