Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
yaml-cpp/src/parse.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (63 sloc)
1.46 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 "yaml-cpp/nodebuilder.h" | |
namespace YAML { | |
Node Load(const std::string& input) { | |
Parser parser(input); | |
NodeBuilder builder; | |
if (!parser.HandleNextDocument(builder)) { | |
return Node(); | |
} | |
return builder.Root(); | |
} | |
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 |