Przeglądaj źródła

Hopefully fix JSONParser

Daniele Bartolini 12 lat temu
rodzic
commit
c5e67a391c
3 zmienionych plików z 26 dodań i 15 usunięć
  1. 2 1
      engine/Device.cpp
  2. 20 12
      engine/core/json/JSONParser.cpp
  3. 4 2
      engine/core/json/JSONParser.h

+ 2 - 1
engine/Device.cpp

@@ -542,7 +542,8 @@ void Device::read_engine_settings()
 	// Parse crown.config
 	JSONParser parser(json_string);
 
-	JSONElement root = parser.root();
+	JSONElement root;
+	root = parser.root();
 
 	// Boot
 	if (root.has_key("boot"))

+ 20 - 12
engine/core/json/JSONParser.cpp

@@ -192,28 +192,36 @@ static bool is_escapee(char c)
 }
 
 //--------------------------------------------------------------------------
-JSONElement::JSONElement() :
-	m_parser(NULL),
-	m_at(NULL),
-	m_begin(NULL)
+JSONElement::JSONElement()
+	: m_parser(NULL), m_begin(NULL), m_at(NULL)
 {
 }
 
 //--------------------------------------------------------------------------
-JSONElement::JSONElement(JSONParser& parser, const char* at) :
-	m_parser(&parser),
-	m_at(at),
-	m_begin(at)
+JSONElement::JSONElement(JSONParser& parser, const char* at)
+	: m_parser(&parser), m_begin(at), m_at(at)
 {
 }
 
+//--------------------------------------------------------------------------
+JSONElement& JSONElement::operator=(const JSONElement& other)
+{
+	m_parser = other.m_parser;
+
+	// Our begin is the other's at
+	m_begin = other.m_at;
+	m_at = other.m_at;
+
+	return *this;
+}
+
 //--------------------------------------------------------------------------
 JSONElement& JSONElement::operator[](uint32_t i)
 {
 	TempAllocator1024 alloc;
 	List<const char*> array(alloc);
 
-	JSONParser::parse_array(m_at, array);
+	JSONParser::parse_array(m_begin, array);
 
 	CE_ASSERT(i < array.size(), "Index out of bounds");
 
@@ -234,7 +242,7 @@ JSONElement& JSONElement::key(const char* k)
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
 
-	JSONParser::parse_object(m_at, object);
+	JSONParser::parse_object(m_begin, object);
 
 	bool found = false;
 
@@ -262,7 +270,7 @@ bool JSONElement::has_key(const char* k) const
 {
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
-	JSONParser::parse_object(m_at, object);
+	JSONParser::parse_object(m_begin, object);
 
 	for (uint32_t i = 0; i < object.size(); i++)
 	{
@@ -285,7 +293,7 @@ bool JSONElement::is_key_unique(const char* k) const
 {
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
-	JSONParser::parse_object(m_at, object);
+	JSONParser::parse_object(m_begin, object);
 
 	bool found = false;
 

+ 4 - 2
engine/core/json/JSONParser.h

@@ -64,6 +64,8 @@ public:
 	/// already existent and valid element.
 						JSONElement();
 
+	JSONElement&		operator=(const JSONElement& other);
+
 	/// Returns the @a i -th item of the current array.
 	JSONElement&		operator[](uint32_t i);
 
@@ -128,11 +130,11 @@ public:
 
 private:
 
-						JSONElement(JSONParser& parser, const char* at);
+	explicit			JSONElement(JSONParser& parser, const char* at);
 
 	JSONParser*			m_parser;
-	const char*			m_at;
 	const char*			m_begin;
+	const char*			m_at;
 
 	friend class 		JSONParser;
 };