]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/parser.cpp
Use nullptr instead of 0 for pointers
[libs/datafile.git] / source / parser.cpp
index a9bbbf22fe8ccb52cf8a60ede5d914f581fdcf04..7d0bb3b465d7d2f1a8c36db3826aa60bdcdc90f8 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/strings/format.h>
 #include "binaryparser.h"
-#include "dataerror.h"
+#include "except.h"
+#include "jsonparser.h"
 #include "parser.h"
 #include "statement.h"
 #include "textparser.h"
@@ -14,9 +15,14 @@ Parser::Parser(IO::Base &i, const string &s):
        in(i),
        main_src(s),
        src(s),
-       good(true),
-       mode(new TextParser(in, src))
-{ }
+       good(true)
+{
+       char c = in.peek();
+       if(c=='{' || c=='[')
+               mode = new JsonParser(in, src);
+       else
+               mode = new TextParser(in, src);
+}
 
 Parser::~Parser()
 {
@@ -97,7 +103,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)