Skip to content

Commit

Permalink
Update doc, formatting for parse.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeder committed May 13, 2016
1 parent 6c569e5 commit 3392ab9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
50 changes: 49 additions & 1 deletion include/yaml-cpp/node/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,63 @@
namespace YAML {
class Node;

/**
* Loads the input string as a single YAML document.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API Node Load(const std::string& input);

/**
* Loads the input string as a single YAML document.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API Node Load(const char* input);

/**
* Loads the input stream as a single YAML document.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API Node Load(std::istream& input);

/**
* Loads the input file as a single YAML document.
*
* @throws {@link ParserException} if it is malformed.
* @throws {@link BadFile} if the file cannot be loaded.
*/
YAML_CPP_API Node LoadFile(const std::string& filename);

/**
* Loads the input string as a list of YAML documents.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API std::vector<Node> LoadAll(const std::string& input);

/**
* Loads the input string as a list of YAML documents.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API std::vector<Node> LoadAll(const char* input);

/**
* Loads the input stream as a list of YAML documents.
*
* @throws {@link ParserException} if it is malformed.
*/
YAML_CPP_API std::vector<Node> LoadAll(std::istream& input);

/**
* Loads the input file as a list of YAML documents.
*
* @throws {@link ParserException} if it is malformed.
* @throws {@link BadFile} if the file cannot be loaded.
*/
YAML_CPP_API std::vector<Node> LoadAllFromFile(const std::string& filename);
}
} // namespace YAML

#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
14 changes: 9 additions & 5 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ Node Load(const char* input) {
Node Load(std::istream& input) {
Parser parser(input);
NodeBuilder builder;
if (!parser.HandleNextDocument(builder))
if (!parser.HandleNextDocument(builder)) {
return Node();
}

return builder.Root();
}

Node LoadFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if (!fin)
if (!fin) {
throw BadFile();
}
return Load(fin);
}

Expand All @@ -51,8 +53,9 @@ std::vector<Node> LoadAll(std::istream& input) {
Parser parser(input);
while (1) {
NodeBuilder builder;
if (!parser.HandleNextDocument(builder))
if (!parser.HandleNextDocument(builder)) {
break;
}
docs.push_back(builder.Root());
}

Expand All @@ -61,8 +64,9 @@ std::vector<Node> LoadAll(std::istream& input) {

std::vector<Node> LoadAllFromFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if (!fin)
if (!fin) {
throw BadFile();
}
return LoadAll(fin);
}
}
} // namespace YAML

0 comments on commit 3392ab9

Please sign in to comment.