Daniele Bartolini 9 лет назад
Родитель
Сommit
4081cacb10
3 измененных файлов с 17 добавлено и 0 удалено
  1. 8 0
      src/core/json/sjson.cpp
  2. 4 0
      src/core/json/sjson.h
  3. 5 0
      src/core/unit_tests.cpp

+ 8 - 0
src/core/json/sjson.cpp

@@ -480,6 +480,14 @@ namespace sjson
 		sjson::parse_string(json, str);
 		return ResourceId(str.c_str());
 	}
+
+	Guid parse_guid(const char* json)
+	{
+		TempAllocator64 ta;
+		DynamicString str(ta);
+		sjson::parse_string(json, str);
+		return guid::parse(str.c_str());
+	}
 } // namespace json
 
 } // namespace crown

+ 4 - 0
src/core/json/sjson.h

@@ -5,6 +5,7 @@
 
 #pragma once
 
+#include "guid.h"
 #include "json_types.h"
 #include "math_types.h"
 #include "string_types.h"
@@ -73,6 +74,9 @@ namespace sjson
 
 	/// Returns the string @a json as ResourceId.
 	ResourceId parse_resource_id(const char* json);
+
+	/// Returns the string @a json as Guid.
+	Guid parse_guid(const char* json);
 } // namespace sjson
 
 } // namespace crown

+ 5 - 0
src/core/unit_tests.cpp

@@ -1127,6 +1127,11 @@ static void test_sjson()
 		const ResourceId a = sjson::parse_resource_id("\"murmur64\"");
 		ENSURE(a._id == 0x90631502d1a3432bu);
 	}
+	{
+		const Guid guid = guid::parse("0f6c3b1c-9cba-4282-9096-2a77ca047b1b");
+		const Guid parsed = sjson::parse_guid("\"0f6c3b1c-9cba-4282-9096-2a77ca047b1b\"");
+		ENSURE(guid == parsed);
+	}
 	memory_globals::shutdown();
 }