From 0396f400a97f71bf743d584acc71a0cdbc155566 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 30 Jun 2023 11:07:10 +0200 Subject: * Added Guid::FromString * Added LoadCompactBinaryObject from file to compactbinaryfile.cpp/h * Added SaveCompactBinary(BinaryWriter& Ar, ...) functions * Added ZEN_PLATFORM_NAME define * Added SystemMetrics functionality to query system properties (see zencore/system.h) --- src/zencore/compactbinary.cpp | 48 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/zencore/compactbinary.cpp') diff --git a/src/zencore/compactbinary.cpp b/src/zencore/compactbinary.cpp index 0db9f02ea..5b599dda3 100644 --- a/src/zencore/compactbinary.cpp +++ b/src/zencore/compactbinary.cpp @@ -358,6 +358,34 @@ Guid::ToString(StringBuilderBase& Sb) const return Sb; } +Guid +Guid::FromString(std::string_view InString) +{ + if (InString.size() != 36) + { + } + + bool Ok = true; + + uint32_t V0 = 0, V5 = 0; + uint16_t V1 = 0, V2 = 0, V3 = 0, V4 = 0; + + Ok = Ok && ParseHexNumber(InString.substr(0, 8), /* out */ V0); + Ok = Ok && ParseHexNumber(InString.substr(9, 4), /* out */ V1); + Ok = Ok && ParseHexNumber(InString.substr(14, 4), /* out */ V2); + Ok = Ok && ParseHexNumber(InString.substr(19, 4), /* out */ V3); + Ok = Ok && ParseHexNumber(InString.substr(24, 4), /* out */ V4); + Ok = Ok && ParseHexNumber(InString.substr(28, 8), /* out */ V5); + + Guid Value; + Value.A = V0; + Value.B = V1 << 16 | V2; + Value.C = V3 << 16 | V4; + Value.D = V5; + + return Value; +} + ////////////////////////////////////////////////////////////////////////// namespace CompactBinaryPrivate { @@ -1943,6 +1971,22 @@ uson_forcelink() { } +TEST_CASE("guid") +{ + using namespace std::literals; + + const Guid A = Guid::FromString("03000c43-d267-36fd-9164-a7555824822b"sv); + + StringBuilder<40> GuidStr; + A.ToString(GuidStr); + + CHECK(std::string_view(GuidStr) == "03000c43-d267-36fd-9164-a7555824822b"sv); + + const Guid B = Guid::FromString(GuidStr); + + CHECK(A == B); +} + TEST_CASE("uson") { using namespace std::literals; @@ -2142,8 +2186,8 @@ TEST_CASE("uson.json") SUBCASE("number.nan") { - const float FloatNan = std::numeric_limits::quiet_NaN(); - const double DoubleNan = std::numeric_limits::quiet_NaN(); + constexpr float FloatNan = std::numeric_limits::quiet_NaN(); + constexpr double DoubleNan = std::numeric_limits::quiet_NaN(); CbObjectWriter Writer; Writer << "FloatNan" << FloatNan; -- cgit v1.2.3