Răsfoiți Sursa

another fix to JSONParser, need json test asap

mikymod 12 ani în urmă
părinte
comite
b5a74d35cf
2 a modificat fișierele cu 28 adăugiri și 14 ștergeri
  1. 24 10
      engine/core/json/JSONParser.cpp
  2. 4 4
      engine/core/json/JSONParser.h

+ 24 - 10
engine/core/json/JSONParser.cpp

@@ -234,7 +234,7 @@ JSONElement& JSONElement::key(const char* k)
 	TempAllocator1024 alloc;
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
 	List<JSONPair> object(alloc);
 
 
-	JSONParser::parse_object(m_begin, object);
+	JSONParser::parse_object(m_at, object);
 
 
 	bool found = false;
 	bool found = false;
 
 
@@ -262,7 +262,7 @@ bool JSONElement::has_key(const char* k) const
 {
 {
 	TempAllocator1024 alloc;
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
 	List<JSONPair> object(alloc);
-	JSONParser::parse_object(m_begin, object);
+	JSONParser::parse_object(m_at, object);
 
 
 	for (uint32_t i = 0; i < object.size(); i++)
 	for (uint32_t i = 0; i < object.size(); i++)
 	{
 	{
@@ -285,7 +285,7 @@ bool JSONElement::is_key_unique(const char* k) const
 {
 {
 	TempAllocator1024 alloc;
 	TempAllocator1024 alloc;
 	List<JSONPair> object(alloc);
 	List<JSONPair> object(alloc);
-	JSONParser::parse_object(m_begin, object);
+	JSONParser::parse_object(m_at, object);
 
 
 	bool found = false;
 	bool found = false;
 
 
@@ -311,25 +311,37 @@ bool JSONElement::is_key_unique(const char* k) const
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
-bool JSONElement::bool_value() const
+bool JSONElement::bool_value()
 {
 {
-	return JSONParser::parse_bool(m_at);
+	const bool value = JSONParser::parse_bool(m_at);
+
+	m_at = m_begin;
+
+	return value;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
-int32_t JSONElement::int_value() const
+int32_t JSONElement::int_value()
 {
 {
-	return JSONParser::parse_int(m_at);
+	const int32_t value = JSONParser::parse_int(m_at);
+
+	m_at = m_begin;
+
+	return value;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
-float JSONElement::float_value() const
+float JSONElement::float_value()
 {
 {
-	return JSONParser::parse_float(m_at);
+	const float value = JSONParser::parse_float(m_at);
+
+	m_at = m_begin;
+
+	return value;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
-const char* JSONElement::string_value() const
+const char* JSONElement::string_value()
 {
 {
 	static TempAllocator1024 alloc;
 	static TempAllocator1024 alloc;
 	static List<char> string(alloc);
 	static List<char> string(alloc);
@@ -338,6 +350,8 @@ const char* JSONElement::string_value() const
 
 
 	JSONParser::parse_string(m_at, string);
 	JSONParser::parse_string(m_at, string);
 
 
+	m_at = m_begin;
+
 	return string.begin();
 	return string.begin();
 }
 }
 
 

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

@@ -111,20 +111,20 @@ public:
 	uint32_t			size() const;
 	uint32_t			size() const;
 
 
 	/// Returns the boolean value of the element.
 	/// Returns the boolean value of the element.
-	bool				bool_value() const;
+	bool				bool_value();
 
 
 	/// Returns the integer value of the element.
 	/// Returns the integer value of the element.
-	int32_t				int_value() const;
+	int32_t				int_value();
 
 
 	/// Returns the float value of the element.
 	/// Returns the float value of the element.
-	float				float_value() const;
+	float				float_value();
 
 
 	/// Returns the string value of the element.
 	/// Returns the string value of the element.
 	/// @warning
 	/// @warning
 	/// The returned string is kept internally until the next call to
 	/// The returned string is kept internally until the next call to
 	/// this function, so it is highly unsafe to just keep the pointer
 	/// this function, so it is highly unsafe to just keep the pointer
 	/// instead of copying its content somewhere else.
 	/// instead of copying its content somewhere else.
-	const char*			string_value() const;
+	const char*			string_value();
 
 
 private:
 private: