yaml-cpp

FORK: A YAML parser and emitter in C++
git clone https://git.neptards.moe/neptards/yaml-cpp.git
Log | Files | Refs | README | LICENSE

parse.cpp (1408B)


      1 #include "yaml-cpp/node/parse.h"
      2 
      3 #include <fstream>
      4 #include <sstream>
      5 
      6 #include "nodebuilder.h"
      7 #include "yaml-cpp/node/impl.h"
      8 #include "yaml-cpp/node/node.h"
      9 #include "yaml-cpp/parser.h"
     10 
     11 namespace YAML {
     12 Node Load(const std::string& input) {
     13   std::stringstream stream(input);
     14   return Load(stream);
     15 }
     16 
     17 Node Load(const char* input) {
     18   std::stringstream stream(input);
     19   return Load(stream);
     20 }
     21 
     22 Node Load(std::istream& input) {
     23   Parser parser(input);
     24   NodeBuilder builder;
     25   if (!parser.HandleNextDocument(builder)) {
     26     return Node();
     27   }
     28 
     29   return builder.Root();
     30 }
     31 
     32 Node LoadFile(const std::string& filename) {
     33   std::ifstream fin(filename);
     34   if (!fin) {
     35     throw BadFile(filename);
     36   }
     37   return Load(fin);
     38 }
     39 
     40 std::vector<Node> LoadAll(const std::string& input) {
     41   std::stringstream stream(input);
     42   return LoadAll(stream);
     43 }
     44 
     45 std::vector<Node> LoadAll(const char* input) {
     46   std::stringstream stream(input);
     47   return LoadAll(stream);
     48 }
     49 
     50 std::vector<Node> LoadAll(std::istream& input) {
     51   std::vector<Node> docs;
     52 
     53   Parser parser(input);
     54   while (true) {
     55     NodeBuilder builder;
     56     if (!parser.HandleNextDocument(builder)) {
     57       break;
     58     }
     59     docs.push_back(builder.Root());
     60   }
     61 
     62   return docs;
     63 }
     64 
     65 std::vector<Node> LoadAllFromFile(const std::string& filename) {
     66   std::ifstream fin(filename);
     67   if (!fin) {
     68     throw BadFile(filename);
     69   }
     70   return LoadAll(fin);
     71 }
     72 }  // namespace YAML