Daniele Bartolini il y a 9 ans
Parent
commit
ce072151d8
4 fichiers modifiés avec 106 ajouts et 112 suppressions
  1. 52 52
      src/core/json/json.cpp
  2. 3 6
      src/core/json/json.h
  3. 48 48
      src/core/json/sjson.cpp
  4. 3 6
      src/core/json/sjson.h

+ 52 - 52
src/core/json/json.cpp

@@ -74,52 +74,7 @@ namespace json
 		}
 	}
 
-	void parse_string(const char* json, DynamicString& string)
-	{
-		CE_ASSERT_NOT_NULL(json);
-
-		if (*json == '"')
-		{
-			while (*++json)
-			{
-				// Empty string
-				if (*json == '"')
-				{
-					++json;
-					return;
-				}
-				else if (*json == '\\')
-				{
-					++json;
-
-					switch (*json)
-					{
-					case '"': string += '"'; break;
-					case '\\': string += '\\'; break;
-					case '/': string += '/'; break;
-					case 'b': string += '\b'; break;
-					case 'f': string += '\f'; break;
-					case 'n': string += '\n'; break;
-					case 'r': string += '\r'; break;
-					case 't': string += '\t'; break;
-					default:
-					{
-						CE_FATAL("Bad escape character");
-						break;
-					}
-				}
-				}
-				else
-				{
-					string += *json;
-				}
-			}
-		}
-
-		CE_FATAL("Bad string");
-	}
-
-	f64 parse_number(const char* json)
+	static f64 parse_number(const char* json)
 	{
 		CE_ASSERT_NOT_NULL(json);
 
@@ -172,6 +127,16 @@ namespace json
 		return val;
 	}
 
+	s32 parse_int(const char* json)
+	{
+		return (s32)parse_number(json);
+	}
+
+	f32 parse_float(const char* json)
+	{
+		return (f32)parse_number(json);
+	}
+
 	bool parse_bool(const char* json)
 	{
 		CE_ASSERT_NOT_NULL(json);
@@ -199,14 +164,49 @@ namespace json
 		}
 	}
 
-	s32 parse_int(const char* json)
+	void parse_string(const char* json, DynamicString& string)
 	{
-		return (s32)parse_number(json);
-	}
+		CE_ASSERT_NOT_NULL(json);
 
-	f32 parse_float(const char* json)
-	{
-		return (f32)parse_number(json);
+		if (*json == '"')
+		{
+			while (*++json)
+			{
+				// Empty string
+				if (*json == '"')
+				{
+					++json;
+					return;
+				}
+				else if (*json == '\\')
+				{
+					++json;
+
+					switch (*json)
+					{
+					case '"': string += '"'; break;
+					case '\\': string += '\\'; break;
+					case '/': string += '/'; break;
+					case 'b': string += '\b'; break;
+					case 'f': string += '\f'; break;
+					case 'n': string += '\n'; break;
+					case 'r': string += '\r'; break;
+					case 't': string += '\t'; break;
+					default:
+					{
+						CE_FATAL("Bad escape character");
+						break;
+					}
+				}
+				}
+				else
+				{
+					string += *json;
+				}
+			}
+		}
+
+		CE_FATAL("Bad string");
 	}
 
 	void parse_array(const char* json, JsonArray& array)

+ 3 - 6
src/core/json/json.h

@@ -18,12 +18,6 @@ namespace json
 	/// Returns the data type of the JSON string @a json.
 	JsonValueType::Enum type(const char* json);
 
-	/// 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 json as f64.
-	f64 parse_number(const char* json);
-
 	/// Returns the JSON number @a json as int.
 	s32 parse_int(const char* json);
 
@@ -33,6 +27,9 @@ namespace json
 	/// Returns the JSON boolean @a json as bool.
 	bool parse_bool(const char* json);
 
+	/// Parses the JSON string @a json ad puts it into @a string.
+	void parse_string(const char* json, DynamicString& string);
+
 	/// 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, JsonArray& array);

+ 48 - 48
src/core/json/sjson.cpp

@@ -116,47 +116,6 @@ namespace sjson
 		}
 	}
 
-	void parse_string(const char* json, DynamicString& string)
-	{
-		CE_ASSERT_NOT_NULL(json);
-
-		if (*json == '"')
-		{
-			while (*++json)
-			{
-				// Empty string
-				if (*json == '"')
-				{
-					++json;
-					return;
-				}
-				else if (*json == '\\')
-				{
-					++json;
-
-					switch (*json)
-					{
-					case '"': string += '"'; break;
-					case '\\': string += '\\'; break;
-					case '/': string += '/'; break;
-					case 'b': string += '\b'; break;
-					case 'f': string += '\f'; break;
-					case 'n': string += '\n'; break;
-					case 'r': string += '\r'; break;
-					case 't': string += '\t'; break;
-					default: CE_FATAL("Bad escape character"); break;
-					}
-				}
-				else
-				{
-					string += *json;
-				}
-			}
-		}
-
-		CE_FATAL("Bad string");
-	}
-
 	static const char* parse_key(const char* json, DynamicString& key)
 	{
 		CE_ASSERT_NOT_NULL(json);
@@ -178,7 +137,7 @@ namespace sjson
 		return NULL;
 	}
 
-	f64 parse_number(const char* json)
+	static f64 parse_number(const char* json)
 	{
 		CE_ASSERT_NOT_NULL(json);
 
@@ -231,6 +190,16 @@ namespace sjson
 		return val;
 	}
 
+	s32 parse_int(const char* json)
+	{
+		return (s32)parse_number(json);
+	}
+
+	f32 parse_float(const char* json)
+	{
+		return (f32)parse_number(json);
+	}
+
 	bool parse_bool(const char* json)
 	{
 		CE_ASSERT_NOT_NULL(json);
@@ -258,14 +227,45 @@ namespace sjson
 		}
 	}
 
-	s32 parse_int(const char* json)
+	void parse_string(const char* json, DynamicString& string)
 	{
-		return (s32)parse_number(json);
-	}
+		CE_ASSERT_NOT_NULL(json);
 
-	f32 parse_float(const char* json)
-	{
-		return (f32)parse_number(json);
+		if (*json == '"')
+		{
+			while (*++json)
+			{
+				// Empty string
+				if (*json == '"')
+				{
+					++json;
+					return;
+				}
+				else if (*json == '\\')
+				{
+					++json;
+
+					switch (*json)
+					{
+					case '"': string += '"'; break;
+					case '\\': string += '\\'; break;
+					case '/': string += '/'; break;
+					case 'b': string += '\b'; break;
+					case 'f': string += '\f'; break;
+					case 'n': string += '\n'; break;
+					case 'r': string += '\r'; break;
+					case 't': string += '\t'; break;
+					default: CE_FATAL("Bad escape character"); break;
+					}
+				}
+				else
+				{
+					string += *json;
+				}
+			}
+		}
+
+		CE_FATAL("Bad string");
 	}
 
 	void parse_array(const char* json, JsonArray& array)

+ 3 - 6
src/core/json/sjson.h

@@ -19,12 +19,6 @@ namespace sjson
 	/// Returns the data type of the SJSON string @a json.
 	JsonValueType::Enum type(const char* json);
 
-	/// Parses the SJSON string @a json ad puts it into @a string.
-	void parse_string(const char* json, DynamicString& string);
-
-	/// Returns the SJSON number @a json as f64.
-	f64 parse_number(const char* json);
-
 	/// Returns the SJSON number @a json as int.
 	s32 parse_int(const char* json);
 
@@ -34,6 +28,9 @@ namespace sjson
 	/// Returns the SJSON boolean @a json as bool.
 	bool parse_bool(const char* json);
 
+	/// Parses the SJSON string @a json ad puts it into @a string.
+	void parse_string(const char* json, DynamicString& string);
+
 	/// Parses the SJSON 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, JsonArray& array);