diff options
author | iddqd <iddqd@yandex-team.ru> | 2022-02-10 16:49:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:46 +0300 |
commit | ff241e1daf76d79ed38015cdb76d55eb3a33ac27 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic | |
parent | 07fce9c5f7771600d0b3d70e1f88fd8a7e164d85 (diff) | |
download | ydb-ff241e1daf76d79ed38015cdb76d55eb3a33ac27.tar.gz |
Restoring authorship annotation for <iddqd@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/guid.cpp | 72 | ||||
-rw-r--r-- | util/generic/guid.h | 24 | ||||
-rw-r--r-- | util/generic/guid_ut.cpp | 50 |
3 files changed, 73 insertions, 73 deletions
diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 11434ed80b..8b907457bc 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -3,44 +3,44 @@ #include "string.h" #include <util/string/ascii.h> -#include <util/string/builder.h> +#include <util/string/builder.h> #include <util/stream/format.h> #include <util/system/unaligned_mem.h> #include <util/random/easy.h> -namespace { - inline void LowerCaseHex(TString& s) { - for (auto&& c : s) { - c = AsciiToLower(c); - } - } -} - -TString TGUID::AsGuidString() const { - TStringBuilder s; - s.reserve(50); - s << Hex(dw[0], 0) << '-' << Hex(dw[1], 0) << '-' << Hex(dw[2], 0) << '-' << Hex(dw[3], 0); - LowerCaseHex(s); - return std::move(s); -} - -TString TGUID::AsUuidString() const { - TStringBuilder s; - s.reserve(50); - s << Hex(dw[0], HF_FULL) << '-'; - s << Hex(static_cast<ui16>(dw[1] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[1]), HF_FULL) << '-'; - s << Hex(static_cast<ui16>(dw[2] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[2]), HF_FULL); - s << Hex(dw[3], HF_FULL); - LowerCaseHex(s); - return std::move(s); -} - -TGUID TGUID::Create() { - TGUID result; - CreateGuid(&result); - return result; -} - +namespace { + inline void LowerCaseHex(TString& s) { + for (auto&& c : s) { + c = AsciiToLower(c); + } + } +} + +TString TGUID::AsGuidString() const { + TStringBuilder s; + s.reserve(50); + s << Hex(dw[0], 0) << '-' << Hex(dw[1], 0) << '-' << Hex(dw[2], 0) << '-' << Hex(dw[3], 0); + LowerCaseHex(s); + return std::move(s); +} + +TString TGUID::AsUuidString() const { + TStringBuilder s; + s.reserve(50); + s << Hex(dw[0], HF_FULL) << '-'; + s << Hex(static_cast<ui16>(dw[1] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[1]), HF_FULL) << '-'; + s << Hex(static_cast<ui16>(dw[2] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[2]), HF_FULL); + s << Hex(dw[3], HF_FULL); + LowerCaseHex(s); + return std::move(s); +} + +TGUID TGUID::Create() { + TGUID result; + CreateGuid(&result); + return result; +} + void CreateGuid(TGUID* res) { ui64* dw = reinterpret_cast<ui64*>(res->dw); @@ -66,11 +66,11 @@ TGUID TGUID::CreateTimebased() { } TString GetGuidAsString(const TGUID& g) { - return g.AsGuidString(); + return g.AsGuidString(); } TString CreateGuidAsString() { - return TGUID::Create().AsGuidString(); + return TGUID::Create().AsGuidString(); } static bool GetDigit(const char c, ui32& digit) { diff --git a/util/generic/guid.h b/util/generic/guid.h index d6259a8942..2bf6c8ad99 100644 --- a/util/generic/guid.h +++ b/util/generic/guid.h @@ -24,18 +24,18 @@ struct TGUID { constexpr explicit operator bool() const noexcept { return !IsEmpty(); } - - // xxxx-xxxx-xxxx-xxxx - TString AsGuidString() const; - - /** - * RFC4122 GUID, which described in - * https://en.wikipedia.org/wiki/Universally_unique_identifier - * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - **/ - TString AsUuidString() const; - - static TGUID Create(); + + // xxxx-xxxx-xxxx-xxxx + TString AsGuidString() const; + + /** + * RFC4122 GUID, which described in + * https://en.wikipedia.org/wiki/Universally_unique_identifier + * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + **/ + TString AsUuidString() const; + + static TGUID Create(); /** * Generate time based UUID version 1 RFC4122 GUID diff --git a/util/generic/guid_ut.cpp b/util/generic/guid_ut.cpp index fdcb723ee8..048354ff39 100644 --- a/util/generic/guid_ut.cpp +++ b/util/generic/guid_ut.cpp @@ -94,31 +94,31 @@ Y_UNIT_TEST_SUITE(TGuidTest) { UNIT_ASSERT_EQUAL(t.G, GetUuid(t.S)); } } - - Y_UNIT_TEST(DoubleConvert) { - /** - * test print and parsing RFC4122 GUID, which described in - * https://en.wikipedia.org/wiki/Universally_unique_identifier - * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - **/ - auto guid = TGUID::Create(); - auto printed = guid.AsUuidString(); - - TGUID read; - UNIT_ASSERT(GetUuid(printed, read)); - - UNIT_ASSERT_VALUES_EQUAL(guid.dw[0], read.dw[0]); - UNIT_ASSERT_VALUES_EQUAL(guid.dw[1], read.dw[1]); - UNIT_ASSERT_VALUES_EQUAL(guid.dw[2], read.dw[2]); - UNIT_ASSERT_VALUES_EQUAL(guid.dw[3], read.dw[3]); - } - - Y_UNIT_TEST(OutputFormat) { - TGUID guid = Construct(0x00005612U, 0x12000000U, 0x00000123U, 0x00000000U); - - UNIT_ASSERT_VALUES_EQUAL(guid.AsGuidString(), "5612-12000000-123-0"); - UNIT_ASSERT_VALUES_EQUAL(guid.AsUuidString(), "00005612-1200-0000-0000-012300000000"); - } + + Y_UNIT_TEST(DoubleConvert) { + /** + * test print and parsing RFC4122 GUID, which described in + * https://en.wikipedia.org/wiki/Universally_unique_identifier + * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + **/ + auto guid = TGUID::Create(); + auto printed = guid.AsUuidString(); + + TGUID read; + UNIT_ASSERT(GetUuid(printed, read)); + + UNIT_ASSERT_VALUES_EQUAL(guid.dw[0], read.dw[0]); + UNIT_ASSERT_VALUES_EQUAL(guid.dw[1], read.dw[1]); + UNIT_ASSERT_VALUES_EQUAL(guid.dw[2], read.dw[2]); + UNIT_ASSERT_VALUES_EQUAL(guid.dw[3], read.dw[3]); + } + + Y_UNIT_TEST(OutputFormat) { + TGUID guid = Construct(0x00005612U, 0x12000000U, 0x00000123U, 0x00000000U); + + UNIT_ASSERT_VALUES_EQUAL(guid.AsGuidString(), "5612-12000000-123-0"); + UNIT_ASSERT_VALUES_EQUAL(guid.AsUuidString(), "00005612-1200-0000-0000-012300000000"); + } Y_UNIT_TEST(TimeBased) { TString guid = TGUID::CreateTimebased().AsUuidString(); |