]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/parser.cpp
Cosmetic changes
[libs/datafile.git] / source / parser.cpp
index 5972e2d98f832d312afa4373bfe66d4204d10f8f..e0ad8547e84e93124e2704e851ccaceaf8615af2 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/strings/format.h>
 #include "binaryparser.h"
 #include "except.h"
+#include "jsonparser.h"
 #include "parser.h"
 #include "statement.h"
 #include "textparser.h"
@@ -13,10 +14,14 @@ namespace DataFile {
 Parser::Parser(IO::Base &i, const string &s):
        in(i),
        main_src(s),
-       src(s),
-       good(true),
-       mode(new TextParser(in, src))
-{ }
+       src(s)
+{
+       char c = in.peek();
+       if(c=='{' || c=='[')
+               mode = new JsonParser(in, src);
+       else
+               mode = new TextParser(in, src);
+}
 
 Parser::~Parser()
 {
@@ -97,7 +102,7 @@ const StatementKey *Parser::peek(unsigned level)
                        return key;
        }
 
-       return 0;
+       return nullptr;
 }
 
 bool Parser::parse_and_load(unsigned level, Loader &ldr, const LoaderAction &act)