Daniele Bartolini 12 anos atrás
pai
commit
eb77214ac8
4 arquivos alterados com 0 adições e 552 exclusões
  1. 0 1
      engine/Android.mk
  2. 0 2
      engine/CMakeLists.txt
  3. 0 481
      engine/core/json/JSON.cpp
  4. 0 68
      engine/core/json/JSON.h

+ 0 - 1
engine/Android.mk

@@ -32,7 +32,6 @@ LOCAL_SRC_FILES :=\
 	core/filesystem/TextReader.cpp\
 	core/filesystem/TextWriter.cpp\
 \
-	core/json/JSON.cpp
 	core/json/JSONParser.cpp
 \
 	core/math/Color4.cpp\

+ 0 - 2
engine/CMakeLists.txt

@@ -172,12 +172,10 @@ set (FILESYSTEM_HEADERS
 )
 
 set (JSON_SRC
-	core/json/JSON.cpp
 	core/json/JSONParser.cpp
 )
 
 set (JSON_HEADERS
-	core/json/JSON.h
 	core/json/JSONParser.h
 )
 

+ 0 - 481
engine/core/json/JSON.cpp

@@ -1,481 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Assert.h"
-#include "JSON.h"
-#include "Types.h"
-#include "List.h"
-#include "TempAllocator.h"
-#include <cstdio>
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-static const char* next(const char* str, const char c = 0)
-{
-	CE_ASSERT_NOT_NULL(str);
-
-	if (c && c != (*str))
-	{
-		CE_ASSERT(false, "Expected '%c' got '%c'", c, (*str));
-	}
-
-	return str + 1;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_whites(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	while ((*ch) && (*ch) <= ' ') ch = next(ch);
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_string(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	bool escaped = false;
-
-	if ((*ch) == '"')
-	{
-		while ((*(ch = next(ch))) != 0)
-		{
-			if ((*ch) == '"' && !escaped)
-			{
-				ch = next(ch);
-				return ch;
-			}
-			else if ((*ch) == '\\') escaped = true;
-			else escaped = false;
-		}
-	}
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_number(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	while ((*ch) && (((*ch) >= '0' && (*ch) <= '9') ||
-			(*ch) == '-' || (*ch) == '.' || (*ch) == '+' ||
-			(*ch) == 'e' || (*ch) == 'E'))
-	{
-		ch = next(ch);
-	}
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_object(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	uint32_t brackets = 1;
-
-	if ((*ch) == '{')
-	{
-		brackets++;
-		ch = next(ch, '{');
-
-		while ((*ch) && brackets != 1)
-		{
-			if ((*ch) == '}') brackets--;
-			else if ((*ch) == '{') brackets++;
-			ch = next(ch);
-		}
-	}
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_array(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	uint32_t brackets = 1;
-
-	if ((*ch) == '[')
-	{
-		brackets++;
-		ch = next(ch, '[');
-
-		while ((*ch) && brackets != 1)
-		{
-			if ((*ch) == ']') brackets--;
-			else if ((*ch) == '[') brackets++;
-			ch = next(ch);
-		}
-	}
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static const char* skip_bool(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	switch ((*ch))
-	{
-		case 't':
-		{
-			ch = next(ch, 't');
-			ch = next(ch, 'r');
-			ch = next(ch, 'u');
-			ch = next(ch, 'e');
-			break;
-		}
-		case 'f':
-		{
-			ch = next(ch, 'f');
-			ch = next(ch, 'a');
-			ch = next(ch, 'l');
-			ch = next(ch, 's');
-			ch = next(ch, 'e');
-			break;
-		}
-		default:
-		{
-			break;
-		}
-	}
-
-	return ch;
-}
-
-//-----------------------------------------------------------------------------
-static bool is_escapee(char c)
-{
-	return c == '"' || c == '\\' || c == '/' || c == '\b' || c == '\f' || c == '\n' ||
-			c == '\r' || c == '\t';
-}
-
-//-----------------------------------------------------------------------------
-JSONType JSON::type(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	switch (s[0])
-	{
-		case '{': return JT_OBJECT;
-		case '[': return JT_ARRAY;
-		case '"': return JT_STRING;
-		case '-': return JT_NUMBER;
-		default: return s[0] >= '0' && s[0] <= '9' ? JT_NUMBER : (s[0] == 'n' ? JT_NIL : JT_BOOL);
-	}
-}
-
-
-//-----------------------------------------------------------------------------
-void JSON::parse_string(const char* s, List<char>& str)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	if ((*ch) == '"')
-	{
-		while ((*(ch = next(ch))))
-		{
-			// Empty string
-			if ((*ch) == '"')
-			{
-				ch = next(ch);
-				str.push_back('\0');
-				return;
-			}
-			else if ((*ch) == '\\')
-			{
-				ch = next(ch);
-
-				if ((*ch) == 'u')
-				{
-					CE_ASSERT(false, "Not supported at the moment");
-				}
-				else if (is_escapee(*ch))
-				{
-					str.push_back('\\');
-					str.push_back(*ch);
-				}
-				else
-				{
-					// Go to invalid string
-					break;
-				}
-			}
-			else
-			{
-				str.push_back(*ch);
-			}
-		}
-	}
-
-	CE_ASSERT(false, "Not a valid string");
-}
-
-//-----------------------------------------------------------------------------
-double JSON::parse_number(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	TempAllocator1024 allocator;
- 	List<char> str(allocator);
-
-	if ((*ch) == '-')
-	{
-		str.push_back('-');
-		ch = next(ch, '-');
-	}
-	while ((*ch) >= '0' && (*ch) <= '9')
-	{
-		str.push_back((*ch));
-		ch = next(ch);
-	}
-
-	if ((*ch) == '.')
-	{
-		str.push_back('.');
-		while ((*(ch = next(ch))) && (*ch) >= '0' && (*ch) <= '9')
-		{
-			str.push_back(*ch);
-		}
-	}
-
-	if ((*ch) == 'e' || (*ch) == 'E')
-	{
-		str.push_back(*ch);
-		ch = next(ch);
-
-		if ((*ch) == '-' || (*ch) == '+')
-		{
-			str.push_back(*ch);
-			ch = next(ch);
-		}
-		while ((*ch) >= '0' && (*ch) <= '9')
-		{
-			str.push_back(*ch);
-			ch = next(ch);
-		}
-	}
-
-	// Ensure null terminated
-	str.push_back('\0');
-
-	float number = 0.0f;
-
-	// Fixme
-	sscanf(str.begin(), "%f", &number);
-
-	return number;
-}
-
-//-----------------------------------------------------------------------------
-bool JSON::parse_bool(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	switch(*ch)
-	{
-		case 't':
-		{
-			ch = next(ch, 't');
-			ch = next(ch, 'r');
-			ch = next(ch, 'u');
-			ch = next(ch, 'e');
-			return true;
-		}
-		case 'f':
-		{
-			ch = next(ch, 'f');
-			ch = next(ch, 'a');
-			ch = next(ch, 'l');
-			ch = next(ch, 's');			
-			ch = next(ch, 'e');
-			return false;
-		}
-		default: break;
-	}
-
-	CE_ASSERT(false, "Not a boolean");
-}
-
-//-----------------------------------------------------------------------------
-int32_t JSON::parse_int(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	return (int32_t) parse_number(s);
-}
-
-//-----------------------------------------------------------------------------
-float JSON::parse_float(const char* s)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	return (float) parse_number(s);
-}
-
-//-----------------------------------------------------------------------------
-void JSON::parse_array(const char* s, List<const char*>& array)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	if ((*ch) == '[')
-	{
-		ch = next(ch, '[');
-
-		// Skip whitespaces
-		while ((*ch) && (*ch) <= ' ')
-		{
-			ch = next(ch);
-		}
-
-		if ((*ch) == ']')
-		{
-			ch = next(ch, ']');
-			return;
-		}
-
-		while (*ch)
-		{
-			array.push_back(ch);
-
-			ch = skip_array(ch);
-			ch = skip_object(ch);
-			ch = skip_number(ch);
-			ch = skip_string(ch);
-			ch = skip_bool(ch);
-
-			ch = skip_whites(ch);
-
-			// Closing bracket (top-most array)
-			if ((*ch) == ']')
-			{
-				ch = next(ch, ']');
-				return;
-			}
-
-			// Skip until next ','
-			ch = next(ch, ',');
-
-			// Skip whites, eventually
-			ch = skip_whites(ch);
-		}
-	}
-
-	CE_ASSERT(false, "Not an array");
-}
-
-//-----------------------------------------------------------------------------
-void JSON::parse_object(const char* s, List<JSONPair>& map)
-{
-	CE_ASSERT_NOT_NULL(s);
-
-	const char* ch = s;
-
-	if ((*ch) == '{')
-	{
-		ch = next(ch, '{');
-
-		ch = skip_whites(ch);
-
-		if ((*ch) == '}')
-		{
-			next(ch, '}');
-			return;
-		}
-
-		while (*ch)
-		{
-			JSONPair pair;
-
-			pair.key = ch;
-
-			// Skip any value
-			ch = skip_array(ch);
-			ch = skip_object(ch);
-			ch = skip_number(ch);
-			ch = skip_string(ch);
-			ch = skip_bool(ch);
-
-			ch = skip_whites(ch);
-			ch = next(ch, ':');
-			ch = skip_whites(ch);
-
-			pair.val = ch;
-			map.push_back(pair);
-
-			// Skip any value
-			ch = skip_array(ch);
-			ch = skip_object(ch);
-			ch = skip_number(ch);
-			ch = skip_string(ch);
-			ch = skip_bool(ch);
-
-			ch = skip_whites(ch);
-
-			if ((*ch) == '}')
-			{
-				next(ch, '}');
-				return;
-			}
-
-			ch = next(ch, ',');
-			ch = skip_whites(ch);
-		}
-	}
-
-	CE_ASSERT(false, "Not an object");
-}
-
-} // namespace crown

+ 0 - 68
engine/core/json/JSON.h

@@ -1,68 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "List.h"
-
-namespace crown
-{
-
-enum JSONType
-{
-	JT_NIL,
-	JT_OBJECT,
-	JT_ARRAY,
-	JT_STRING,
-	JT_NUMBER,
-	JT_BOOL
-};
-
-struct JSONPair
-{
-	const char* key;
-	const char* val;
-};
-
-class JSON
-{
-public:
-
-	static JSONType		type(const char* s);
-
-	static void			parse_string(const char* s, List<char>& str);
-	static double		parse_number(const char* s);
-
-	static bool			parse_bool(const char* s);
-	static int32_t 		parse_int(const char* s);
-	static float		parse_float(const char* s);
-
-	static void			parse_array(const char* s, List<const char*>& array);
-	static void			parse_object(const char* s, List<JSONPair>& map);
-};
-
-} // namespace crown