Daniele Bartolini 11 tahun lalu
induk
melakukan
13c342b84b
5 mengubah file dengan 287 tambahan dan 287 penghapusan
  1. 109 109
      engine/core/json/json.cpp
  2. 19 19
      engine/core/json/json.h
  3. 12 12
      engine/core/json/json_parser.cpp
  4. 128 128
      engine/core/json/njson.cpp
  5. 19 19
      engine/core/json/njson.h

+ 109 - 109
engine/core/json/json.cpp

@@ -12,86 +12,86 @@ namespace crown
 {
 namespace json
 {
-	static const char* next(const char* str, const char c = 0)
+	static const char* next(const char* json, const char c = 0)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (c && c != *str)
+		if (c && c != *json)
 		{
-			CE_ASSERT(false, "Expected '%c' got '%c'", c, *str);
+			CE_ASSERT(false, "Expected '%c' got '%c'", c, *json);
 		}
 
-		return ++str;
+		return ++json;
 	}
 
-	static const char* skip_string(const char* str)
+	static const char* skip_string(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
 		bool escaped = false;
 
-		while ((*(str = next(str))) != 0)
+		while ((*(json = next(json))) != 0)
 		{
-			if (*str == '"' && !escaped)
+			if (*json == '"' && !escaped)
 			{
-				str = next(str);
-				return str;
+				json = next(json);
+				return json;
 			}
-			else if (*str == '\\') escaped = true;
+			else if (*json == '\\') escaped = true;
 			else escaped = false;
 		}
 
-		return str;
+		return json;
 	}
 
-	static const char* skip_value(const char* str)
+	static const char* skip_value(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
-			case '"': str = skip_string(str); break;
-			case '[': str = skip_block(str, '[', ']'); break;
-			case '{': str = skip_block(str, '{', '}'); break;
-			default: for (; *str != ',' && *str != '}' && *str != ']'; ++str) ; break;
+			case '"': json = skip_string(json); break;
+			case '[': json = skip_block(json, '[', ']'); break;
+			case '{': json = skip_block(json, '{', '}'); break;
+			default: for (; *json != ',' && *json != '}' && *json != ']'; ++json) ; break;
 		}
 
-		return str;
+		return json;
 	}
 
-	JSONType::Enum type(const char* str)
+	JSONValueType::Enum type(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
-			case '"': return JSONType::STRING;
-			case '{': return JSONType::OBJECT;
-			case '[': return JSONType::ARRAY;
-			case '-': return JSONType::NUMBER;
-			default: return (isdigit(*str)) ? JSONType::NUMBER : (*str == 'n' ? JSONType::NIL : JSONType::BOOL);
+			case '"': return JSONValueType::STRING;
+			case '{': return JSONValueType::OBJECT;
+			case '[': return JSONValueType::ARRAY;
+			case '-': return JSONValueType::NUMBER;
+			default: return (isdigit(*json)) ? JSONValueType::NUMBER : (*json == 'n' ? JSONValueType::NIL : JSONValueType::BOOL);
 		}
 	}
 
-	void parse_string(const char* str, DynamicString& string)
+	void parse_string(const char* json, DynamicString& string)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '"')
+		if (*json == '"')
 		{
-			while (*(str = next(str)))
+			while (*(json = next(json)))
 			{
 				// Empty string
-				if (*str == '"')
+				if (*json == '"')
 				{
-					str = next(str);
+					json = next(json);
 					return;
 				}
-				else if (*str == '\\')
+				else if (*json == '\\')
 				{
-					str = next(str);
+					json = next(json);
 
-					switch (*str)
+					switch (*json)
 					{
 						case '"': string += '"'; break;
 						case '\\': string += '\\'; break;
@@ -110,7 +110,7 @@ namespace json
 				}
 				else
 				{
-					string += *str;
+					string += *json;
 				}
 			}
 		}
@@ -118,47 +118,47 @@ namespace json
 		CE_FATAL("Bad string");
 	}
 
-	double parse_number(const char* str)
+	double parse_number(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
 		TempAllocator512 alloc;
 	 	Array<char> number(alloc);
 
-		if (*str == '-')
+		if (*json == '-')
 		{
 			array::push_back(number, '-');
-			str = next(str, '-');
+			json = next(json, '-');
 		}
-		while (isdigit(*str))
+		while (isdigit(*json))
 		{
-			array::push_back(number, *str);
-			str = next(str);
+			array::push_back(number, *json);
+			json = next(json);
 		}
 
-		if (*str == '.')
+		if (*json == '.')
 		{
 			array::push_back(number, '.');
-			while ((*(str = next(str))) && isdigit(*str))
+			while ((*(json = next(json))) && isdigit(*json))
 			{
-				array::push_back(number, *str);
+				array::push_back(number, *json);
 			}
 		}
 
-		if (*str == 'e' || *str == 'E')
+		if (*json == 'e' || *json == 'E')
 		{
-			array::push_back(number, *str);
-			str = next(str);
+			array::push_back(number, *json);
+			json = next(json);
 
-			if (*str == '-' || *str == '+')
+			if (*json == '-' || *json == '+')
 			{
-				array::push_back(number, *str);
-				str = next(str);
+				array::push_back(number, *json);
+				json = next(json);
 			}
-			while (isdigit(*str))
+			while (isdigit(*json))
 			{
-				array::push_back(number, *str);
-				str = next(str);
+				array::push_back(number, *json);
+				json = next(json);
 			}
 		}
 
@@ -167,27 +167,27 @@ namespace json
 		return parse_double(array::begin(number));
 	}
 
-	bool parse_bool(const char* str)
+	bool parse_bool(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
 			case 't':
 			{
-				str = next(str, 't');
-				str = next(str, 'r');
-				str = next(str, 'u');
-				str = next(str, 'e');
+				json = next(json, 't');
+				json = next(json, 'r');
+				json = next(json, 'u');
+				json = next(json, 'e');
 				return true;
 			}
 			case 'f':
 			{
-				str = next(str, 'f');
-				str = next(str, 'a');
-				str = next(str, 'l');
-				str = next(str, 's');
-				str = next(str, 'e');
+				json = next(json, 'f');
+				json = next(json, 'a');
+				json = next(json, 'l');
+				json = next(json, 's');
+				json = next(json, 'e');
 				return false;
 			}
 			default:
@@ -198,91 +198,91 @@ namespace json
 		}
 	}
 
-	int32_t parse_int(const char* str)
+	int32_t parse_int(const char* json)
 	{
-		return (int32_t) parse_number(str);
+		return (int32_t) parse_number(json);
 	}
 
-	float parse_float(const char* str)
+	float parse_float(const char* json)
 	{
-		return (float) parse_number(str);
+		return (float) parse_number(json);
 	}
 
-	void parse_array(const char* str, Array<const char*>& array)
+	void parse_array(const char* json, Array<const char*>& array)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '[')
+		if (*json == '[')
 		{
-			str = next(str, '[');
-			str = skip_spaces(str);
+			json = next(json, '[');
+			json = skip_spaces(json);
 
-			if (*str == ']')
+			if (*json == ']')
 			{
-				str = next(str, ']');
+				json = next(json, ']');
 				return;
 			}
 
-			while (*str)
+			while (*json)
 			{
-				array::push_back(array, str);
+				array::push_back(array, json);
 
-				str = skip_value(str);
-				str = skip_spaces(str);
+				json = skip_value(json);
+				json = skip_spaces(json);
 
-				if (*str == ']')
+				if (*json == ']')
 				{
-					str = next(str, ']');
+					json = next(json, ']');
 					return;
 				}
 
-				str = next(str, ',');
-				str = skip_spaces(str);
+				json = next(json, ',');
+				json = skip_spaces(json);
 			}
 		}
 
 		CE_FATAL("Bad array");
 	}
 
-	void parse_object(const char* str, Map<DynamicString, const char*>& object)
+	void parse_object(const char* json, Map<DynamicString, const char*>& object)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '{')
+		if (*json == '{')
 		{
-			str = next(str, '{');
+			json = next(json, '{');
 
-			str = skip_spaces(str);
+			json = skip_spaces(json);
 
-			if (*str == '}')
+			if (*json == '}')
 			{
-				next(str, '}');
+				next(json, '}');
 				return;
 			}
 
-			while (*str)
+			while (*json)
 			{
 				DynamicString key;
-				parse_string(str, key);
+				parse_string(json, key);
 
-				str = skip_string(str);
-				str = skip_spaces(str);
-				str = next(str, ':');
-				str = skip_spaces(str);
+				json = skip_string(json);
+				json = skip_spaces(json);
+				json = next(json, ':');
+				json = skip_spaces(json);
 
-				map::set(object, key, str);
+				map::set(object, key, json);
 
-				str = skip_value(str);
-				str = skip_spaces(str);
+				json = skip_value(json);
+				json = skip_spaces(json);
 
-				if (*str == '}')
+				if (*json == '}')
 				{
-					next(str, '}');
+					next(json, '}');
 					return;
 				}
 
-				str = next(str, ',');
-				str = skip_spaces(str);
+				json = next(json, ',');
+				json = skip_spaces(json);
 			}
 		}
 

+ 19 - 19
engine/core/json/json.h

@@ -16,7 +16,7 @@ namespace crown
 /// Enumerates JSON value types.
 ///
 /// @ingroup JSON
-struct JSONType
+struct JSONValueType
 {
 	enum Enum
 	{
@@ -34,30 +34,30 @@ struct JSONType
 /// @ingroup JSON
 namespace json
 {
-	/// Returns the data type of the JSON string @a str.
-	JSONType::Enum type(const char* str);
+	/// Returns the data type of the JSON string @a json.
+	JSONValueType::Enum type(const char* json);
 
-	/// Parses the JSON string @a str ad puts it into @a string.
-	void parse_string(const char* str, DynamicString& string);
+	/// Parses the JSON string @a json ad puts it into @a string.
+	void parse_string(const char* json, DynamicString& string);
 
-	/// Returns the JSON number @a str as double.
-	double parse_number(const char* str);
+	/// Returns the JSON number @a json as double.
+	double parse_number(const char* json);
 
-	/// Returns the JSON number @a str as int.
-	int32_t parse_int(const char* str);
+	/// Returns the JSON number @a json as int.
+	int32_t parse_int(const char* json);
 
-	/// Returns the JSON number @a str as float.
-	float parse_float(const char* str);
+	/// Returns the JSON number @a json as float.
+	float parse_float(const char* json);
 
-	/// Returns the JSON boolean @a str as bool.
-	bool parse_bool(const char* str);
+	/// Returns the JSON boolean @a json as bool.
+	bool parse_bool(const char* json);
 
-	/// Parses the JSON array @a str and puts it into @a array as pointers to
-	/// the corresponding items into the original @a str string.
-	void parse_array(const char* str, Array<const char*>& array);
+	/// Parses the JSON array @a json and puts it into @a array as pointers to
+	/// the corresponding items into the original @a json string.
+	void parse_array(const char* json, Array<const char*>& array);
 
-	/// Parses the JSON object @a str and puts it into @a object as map from
-	/// key to pointer to the corresponding value into the original string @a str.
-	void parse_object(const char* str, Map<DynamicString, const char*>& object);
+	/// Parses the JSON object @a json and puts it into @a object as map from
+	/// key to pointer to the corresponding value into the original string @a json.
+	void parse_object(const char* json, Map<DynamicString, const char*>& object);
 } // namespace json
 } // namespace crown

+ 12 - 12
engine/core/json/json_parser.cpp

@@ -326,7 +326,7 @@ bool JSONElement::is_nil() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::NIL;
+		return njson::type(_at) == NJSONValueType::NIL;
 	}
 
 	return true;
@@ -336,7 +336,7 @@ bool JSONElement::is_bool() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::BOOL;
+		return njson::type(_at) == NJSONValueType::BOOL;
 	}
 
 	return false;
@@ -346,7 +346,7 @@ bool JSONElement::is_number() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::NUMBER;
+		return njson::type(_at) == NJSONValueType::NUMBER;
 	}
 
 	return false;
@@ -356,7 +356,7 @@ bool JSONElement::is_string() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::STRING;
+		return njson::type(_at) == NJSONValueType::STRING;
 	}
 
 	return false;
@@ -366,7 +366,7 @@ bool JSONElement::is_array() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::ARRAY;
+		return njson::type(_at) == NJSONValueType::ARRAY;
 	}
 
 	return false;
@@ -376,7 +376,7 @@ bool JSONElement::is_object() const
 {
 	if (_at != NULL)
 	{
-		return njson::type(_at) == NJSONType::OBJECT;
+		return njson::type(_at) == NJSONValueType::OBJECT;
 	}
 
 	return false;
@@ -391,33 +391,33 @@ uint32_t JSONElement::size() const
 
 	switch(njson::type(_at))
 	{
-		case NJSONType::NIL:
+		case NJSONValueType::NIL:
 		{
 			return 1;
 		}
-		case NJSONType::OBJECT:
+		case NJSONValueType::OBJECT:
 		{
 			Map<DynamicString, const char*> object(default_allocator());
 			njson::parse_object(_at, object);
 			return map::size(object);
 		}
-		case NJSONType::ARRAY:
+		case NJSONValueType::ARRAY:
 		{
 			Array<const char*> array(default_allocator());
 			njson::parse_array(_at, array);
 			return array::size(array);
 		}
-		case NJSONType::STRING:
+		case NJSONValueType::STRING:
 		{
 			DynamicString string;
 			njson::parse_string(_at, string);
 			return string.length();
 		}
-		case NJSONType::NUMBER:
+		case NJSONValueType::NUMBER:
 		{
 			return 1;
 		}
-		case NJSONType::BOOL:
+		case NJSONValueType::BOOL:
 		{
 			return 1;
 		}

+ 128 - 128
engine/core/json/njson.cpp

@@ -12,114 +12,114 @@ namespace crown
 {
 namespace njson
 {
-	static const char* next(const char* str, const char c = 0)
+	static const char* next(const char* json, const char c = 0)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (c && c != *str)
+		if (c && c != *json)
 		{
-			CE_ASSERT(false, "Expected '%c' got '%c'", c, *str);
+			CE_ASSERT(false, "Expected '%c' got '%c'", c, *json);
 		}
 
-		return ++str;
+		return ++json;
 	}
 
-	static const char* skip_string(const char* str)
+	static const char* skip_string(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
 		bool escaped = false;
 
-		while ((*(str = next(str))) != 0)
+		while ((*(json = next(json))) != 0)
 		{
-			if (*str == '"' && !escaped)
+			if (*json == '"' && !escaped)
 			{
-				str = next(str);
-				return str;
+				json = next(json);
+				return json;
 			}
-			else if (*str == '\\') escaped = true;
+			else if (*json == '\\') escaped = true;
 			else escaped = false;
 		}
 
-		return str;
+		return json;
 	}
 
-	static const char* skip_value(const char* str)
+	static const char* skip_value(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
-			case '"': str = skip_string(str); break;
-			case '[': str = skip_block(str, '[', ']'); break;
-			case '{': str = skip_block(str, '{', '}'); break;
-			default: for (; *str != ',' && *str != '\n' && *str != ' ' && *str != '}' && *str != ']'; ++str) ; break;
+			case '"': json = skip_string(json); break;
+			case '[': json = skip_block(json, '[', ']'); break;
+			case '{': json = skip_block(json, '{', '}'); break;
+			default: for (; *json != ',' && *json != '\n' && *json != ' ' && *json != '}' && *json != ']'; ++json) ; break;
 		}
 
-		return str;
+		return json;
 	}
 
-	static const char* skip_comments(const char* str)
+	static const char* skip_comments(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '/')
+		if (*json == '/')
 		{
-			str = next(str, '/');
-			str = next(str, '/');
-			while (*str && *str != '\n') str = next(str);
+			json = next(json, '/');
+			json = next(json, '/');
+			while (*json && *json != '\n') json = next(json);
 		}
 
-		return str;
+		return json;
 	}
 
-	static const char* skip_spaces(const char* str)
+	static const char* skip_spaces(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		while (*str)
+		while (*json)
 		{
-			if (*str == '/') str = skip_comments(str);
-			else if (isspace(*str) || *str == ',') ++str;
+			if (*json == '/') json = skip_comments(json);
+			else if (isspace(*json) || *json == ',') ++json;
 			else break;
 		}
 
-		return str;
+		return json;
 	}
 
-	NJSONType::Enum type(const char* str)
+	NJSONValueType::Enum type(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
-			case '"': return NJSONType::STRING;
-			case '{': return NJSONType::OBJECT;
-			case '[': return NJSONType::ARRAY;
-			case '-': return NJSONType::NUMBER;
-			default: return (isdigit(*str)) ? NJSONType::NUMBER : (*str == 'n' ? NJSONType::NIL : NJSONType::BOOL);
+			case '"': return NJSONValueType::STRING;
+			case '{': return NJSONValueType::OBJECT;
+			case '[': return NJSONValueType::ARRAY;
+			case '-': return NJSONValueType::NUMBER;
+			default: return (isdigit(*json)) ? NJSONValueType::NUMBER : (*json == 'n' ? NJSONValueType::NIL : NJSONValueType::BOOL);
 		}
 	}
 
-	void parse_string(const char* str, DynamicString& string)
+	void parse_string(const char* json, DynamicString& string)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '"')
+		if (*json == '"')
 		{
-			while (*(str = next(str)))
+			while (*(json = next(json)))
 			{
 				// Empty string
-				if (*str == '"')
+				if (*json == '"')
 				{
-					str = next(str);
+					json = next(json);
 					return;
 				}
-				else if (*str == '\\')
+				else if (*json == '\\')
 				{
-					str = next(str);
+					json = next(json);
 
-					switch (*str)
+					switch (*json)
 					{
 						case '"': string += '"'; break;
 						case '\\': string += '\\'; break;
@@ -138,7 +138,7 @@ namespace njson
 				}
 				else
 				{
-					string += *str;
+					string += *json;
 				}
 			}
 		}
@@ -146,70 +146,70 @@ namespace njson
 		CE_FATAL("Bad string");
 	}
 
-	static const char* parse_key(const char* str, DynamicString& key)
+	static const char* parse_key(const char* json, DynamicString& key)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '"')
+		if (*json == '"')
 		{
-			parse_string(str, key);
-			return skip_string(str);
+			parse_string(json, key);
+			return skip_string(json);
 		}
-		else if (isalpha(*str))
+		else if (isalpha(*json))
 		{
 			while (true)
 			{
-				if (isspace(*str) || *str == '=') return str;
+				if (isspace(*json) || *json == '=') return json;
 
-				key += *str;
-				++str;
+				key += *json;
+				++json;
 			}
 		}
 
 		CE_FATAL("Bad key");
 	}
 
-	double parse_number(const char* str)
+	double parse_number(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
 		TempAllocator512 alloc;
 	 	Array<char> number(alloc);
 
-		if (*str == '-')
+		if (*json == '-')
 		{
 			array::push_back(number, '-');
-			str = next(str, '-');
+			json = next(json, '-');
 		}
-		while (isdigit(*str))
+		while (isdigit(*json))
 		{
-			array::push_back(number, *str);
-			str = next(str);
+			array::push_back(number, *json);
+			json = next(json);
 		}
 
-		if (*str == '.')
+		if (*json == '.')
 		{
 			array::push_back(number, '.');
-			while ((*(str = next(str))) && isdigit(*str))
+			while ((*(json = next(json))) && isdigit(*json))
 			{
-				array::push_back(number, *str);
+				array::push_back(number, *json);
 			}
 		}
 
-		if (*str == 'e' || *str == 'E')
+		if (*json == 'e' || *json == 'E')
 		{
-			array::push_back(number, *str);
-			str = next(str);
+			array::push_back(number, *json);
+			json = next(json);
 
-			if (*str == '-' || *str == '+')
+			if (*json == '-' || *json == '+')
 			{
-				array::push_back(number, *str);
-				str = next(str);
+				array::push_back(number, *json);
+				json = next(json);
 			}
-			while (isdigit(*str))
+			while (isdigit(*json))
 			{
-				array::push_back(number, *str);
-				str = next(str);
+				array::push_back(number, *json);
+				json = next(json);
 			}
 		}
 
@@ -218,27 +218,27 @@ namespace njson
 		return parse_double(array::begin(number));
 	}
 
-	bool parse_bool(const char* str)
+	bool parse_bool(const char* json)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		switch (*str)
+		switch (*json)
 		{
 			case 't':
 			{
-				str = next(str, 't');
-				str = next(str, 'r');
-				str = next(str, 'u');
-				str = next(str, 'e');
+				json = next(json, 't');
+				json = next(json, 'r');
+				json = next(json, 'u');
+				json = next(json, 'e');
 				return true;
 			}
 			case 'f':
 			{
-				str = next(str, 'f');
-				str = next(str, 'a');
-				str = next(str, 'l');
-				str = next(str, 's');
-				str = next(str, 'e');
+				json = next(json, 'f');
+				json = next(json, 'a');
+				json = next(json, 'l');
+				json = next(json, 's');
+				json = next(json, 'e');
 				return false;
 			}
 			default:
@@ -249,88 +249,88 @@ namespace njson
 		}
 	}
 
-	int32_t parse_int(const char* str)
+	int32_t parse_int(const char* json)
 	{
-		return (int32_t) parse_number(str);
+		return (int32_t) parse_number(json);
 	}
 
-	float parse_float(const char* str)
+	float parse_float(const char* json)
 	{
-		return (float) parse_number(str);
+		return (float) parse_number(json);
 	}
 
-	void parse_array(const char* str, Array<const char*>& array)
+	void parse_array(const char* json, Array<const char*>& array)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '[')
+		if (*json == '[')
 		{
-			str = next(str, '[');
-			str = skip_spaces(str);
+			json = next(json, '[');
+			json = skip_spaces(json);
 
-			if (*str == ']')
+			if (*json == ']')
 			{
-				str = next(str, ']');
+				json = next(json, ']');
 				return;
 			}
 
-			while (*str)
+			while (*json)
 			{
-				array::push_back(array, str);
+				array::push_back(array, json);
 
-				str = skip_value(str);
-				str = skip_spaces(str);
+				json = skip_value(json);
+				json = skip_spaces(json);
 
-				if (*str == ']')
+				if (*json == ']')
 				{
-					str = next(str, ']');
+					json = next(json, ']');
 					return;
 				}
 
-				str = skip_spaces(str);
+				json = skip_spaces(json);
 			}
 		}
 
 		CE_FATAL("Bad array");
 	}
 
-	void parse_object(const char* str, Map<DynamicString, const char*>& object)
+	void parse_object(const char* json, Map<DynamicString, const char*>& object)
 	{
-		CE_ASSERT_NOT_NULL(str);
+		CE_ASSERT_NOT_NULL(json);
 
-		if (*str == '{')
+		if (*json == '{')
 		{
-			str = next(str, '{');
+			json = next(json, '{');
 
-			str = skip_spaces(str);
+			json = skip_spaces(json);
 
-			if (*str == '}')
+			if (*json == '}')
 			{
-				next(str, '}');
+				next(json, '}');
 				return;
 			}
 
-			while (*str)
+			while (*json)
 			{
 				DynamicString key;
-				str = parse_key(str, key);
+				json = parse_key(json, key);
 
-				str = skip_spaces(str);
-				str = next(str, '=');
-				str = skip_spaces(str);
+				json = skip_spaces(json);
+				json = next(json, '=');
+				json = skip_spaces(json);
 
-				map::set(object, key, str);
+				map::set(object, key, json);
 
-				str = skip_value(str);
-				str = skip_spaces(str);
+				json = skip_value(json);
+				json = skip_spaces(json);
 
-				if (*str == '}')
+				if (*json == '}')
 				{
-					next(str, '}');
+					next(json, '}');
 					return;
 				}
 
-				str = skip_spaces(str);
+				json = skip_spaces(json);
 			}
 		}
 

+ 19 - 19
engine/core/json/njson.h

@@ -16,7 +16,7 @@ namespace crown
 /// Enumerates JSON value types.
 ///
 /// @ingroup JSON
-struct NJSONType
+struct NJSONValueType
 {
 	enum Enum
 	{
@@ -34,30 +34,30 @@ struct NJSONType
 /// @ingroup JSON
 namespace njson
 {
-	/// Returns the data type of the NJSON string @a str.
-	NJSONType::Enum type(const char* str);
+	/// Returns the data type of the NJSON string @a json.
+	NJSONValueType::Enum type(const char* json);
 
-	/// Parses the NJSON string @a str ad puts it into @a string.
-	void parse_string(const char* str, DynamicString& string);
+	/// Parses the NJSON string @a json ad puts it into @a string.
+	void parse_string(const char* json, DynamicString& string);
 
-	/// Returns the NJSON number @a str as double.
-	double parse_number(const char* str);
+	/// Returns the NJSON number @a json as double.
+	double parse_number(const char* json);
 
-	/// Returns the NJSON number @a str as int.
-	int32_t parse_int(const char* str);
+	/// Returns the NJSON number @a json as int.
+	int32_t parse_int(const char* json);
 
-	/// Returns the NJSON number @a str as float.
-	float parse_float(const char* str);
+	/// Returns the NJSON number @a json as float.
+	float parse_float(const char* json);
 
-	/// Returns the NJSON boolean @a str as bool.
-	bool parse_bool(const char* str);
+	/// Returns the NJSON boolean @a json as bool.
+	bool parse_bool(const char* json);
 
-	/// Parses the NJSON array @a str and puts it into @a array as pointers to
-	/// the corresponding items into the original @a str string.
-	void parse_array(const char* str, Array<const char*>& array);
+	/// Parses the NJSON array @a json and puts it into @a array as pointers to
+	/// the corresponding items into the original @a json string.
+	void parse_array(const char* json, Array<const char*>& array);
 
-	/// Parses the NJSON object @a str and puts it into @a object as map from
-	/// key to pointer to the corresponding value into the original string @a str.
-	void parse_object(const char* str, Map<DynamicString, const char*>& object);
+	/// Parses the NJSON object @a json and puts it into @a object as map from
+	/// key to pointer to the corresponding value into the original string @a json.
+	void parse_object(const char* json, Map<DynamicString, const char*>& object);
 } // namespace njson
 } // namespace crown