Browse Source

Restoring authorship annotation for <rureggaeton@yandex-team.ru>. Commit 2 of 2.

rureggaeton 3 years ago
parent
commit
c51a16470c
3 changed files with 78 additions and 78 deletions
  1. 60 60
      util/generic/guid.cpp
  2. 5 5
      util/generic/guid.h
  3. 13 13
      util/generic/guid_ut.cpp

+ 60 - 60
util/generic/guid.cpp

@@ -73,20 +73,20 @@ TString CreateGuidAsString() {
     return TGUID::Create().AsGuidString();
 }
 
-static bool GetDigit(const char c, ui32& digit) { 
-    digit = 0; 
-    if ('0' <= c && c <= '9') { 
-        digit = c - '0'; 
-    } else if ('a' <= c && c <= 'f') { 
-        digit = c - 'a' + 10; 
-    } else if ('A' <= c && c <= 'F') { 
-        digit = c - 'A' + 10; 
-    } else { 
-        return false; // non-hex character 
-    } 
-    return true; 
-} 
- 
+static bool GetDigit(const char c, ui32& digit) {
+    digit = 0;
+    if ('0' <= c && c <= '9') {
+        digit = c - '0';
+    } else if ('a' <= c && c <= 'f') {
+        digit = c - 'a' + 10;
+    } else if ('A' <= c && c <= 'F') {
+        digit = c - 'A' + 10;
+    } else {
+        return false; // non-hex character
+    }
+    return true;
+}
+
 bool GetGuid(const TStringBuf s, TGUID& result) {
     size_t partId = 0;
     ui64 partValue = 0;
@@ -107,8 +107,8 @@ bool GetGuid(const TStringBuf s, TGUID& result) {
         }
 
         ui32 digit = 0;
-        if (!GetDigit(c, digit)) { 
-            return false; 
+        if (!GetDigit(c, digit)) {
+            return false;
         }
 
         partValue = partValue * 16 + digit;
@@ -138,49 +138,49 @@ TGUID GetGuid(const TStringBuf s) {
 
     return TGUID();
 }
- 
+
 bool GetUuid(const TStringBuf s, TGUID& result) {
-    if (s.size() != 36) { 
-        return false; 
-    } 
- 
-    size_t partId = 0; 
-    ui64 partValue = 0; 
-    size_t digitCount = 0; 
- 
-    for (size_t i = 0; i < s.size(); ++i) { 
-        const char c = s[i]; 
- 
-        if (c == '-') { 
-            if (i != 8 && i != 13 && i != 18 && i != 23) { 
-                return false; 
-            } 
-            continue; 
-        } 
- 
-        ui32 digit = 0; 
-        if (!GetDigit(c, digit)) { 
-            return false; 
-        } 
- 
-        partValue = partValue * 16 + digit; 
- 
-        if (++digitCount == 8) { 
-            result.dw[partId++] = partValue; 
-            digitCount = 0; 
-        } 
-    } 
-    return true; 
-} 
- 
-// Parses GUID from uuid and checks that it's valid. 
-// In case of error returns TGUID(). 
+    if (s.size() != 36) {
+        return false;
+    }
+
+    size_t partId = 0;
+    ui64 partValue = 0;
+    size_t digitCount = 0;
+
+    for (size_t i = 0; i < s.size(); ++i) {
+        const char c = s[i];
+
+        if (c == '-') {
+            if (i != 8 && i != 13 && i != 18 && i != 23) {
+                return false;
+            }
+            continue;
+        }
+
+        ui32 digit = 0;
+        if (!GetDigit(c, digit)) {
+            return false;
+        }
+
+        partValue = partValue * 16 + digit;
+
+        if (++digitCount == 8) {
+            result.dw[partId++] = partValue;
+            digitCount = 0;
+        }
+    }
+    return true;
+}
+
+// Parses GUID from uuid and checks that it's valid.
+// In case of error returns TGUID().
 TGUID GetUuid(const TStringBuf s) {
-    TGUID result; 
- 
-    if (GetUuid(s, result)) { 
-        return result; 
-    } 
- 
-    return TGUID(); 
-} 
+    TGUID result;
+
+    if (GetUuid(s, result)) {
+        return result;
+    }
+
+    return TGUID();
+}

+ 5 - 5
util/generic/guid.h

@@ -70,10 +70,10 @@ TString GetGuidAsString(const TGUID& g);
 TString CreateGuidAsString();
 TGUID GetGuid(TStringBuf s);
 bool GetGuid(TStringBuf s, TGUID& result);
- 
-/** 
-* Functions for correct parsing RFC4122 GUID, which described in 
-* https://en.wikipedia.org/wiki/Universally_unique_identifier 
-**/ 
+
+/**
+* Functions for correct parsing RFC4122 GUID, which described in
+* https://en.wikipedia.org/wiki/Universally_unique_identifier
+**/
 TGUID GetUuid(TStringBuf s);
 bool GetUuid(TStringBuf s, TGUID& result);

+ 13 - 13
util/generic/guid_ut.cpp

@@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(TGuidTest) {
             {TGUID(), "1--1-1"},
             {TGUID(), "1-1"}, // unexpected end
             {TGUID(), "1-1-"},
-            {TGUID(), "1-1-1"}, 
+            {TGUID(), "1-1-1"},
             {TGUID(), "1-1-1-"},
             {TGUID(), "1-1-1-1-"},
             {TGUID(), "1-1-1-1-1"},
@@ -79,21 +79,21 @@ Y_UNIT_TEST_SUITE(TGuidTest) {
         UNIT_ASSERT_VALUES_EQUAL(GetGuidAsString(Construct(1, 0xADE, 3, 4)), "1-ade-3-4");
         UNIT_ASSERT_VALUES_EQUAL(GetGuidAsString(Construct(1, 2, 3, 0xDEAD)), "1-2-3-dead");
     }
- 
+
     Y_UNIT_TEST(Test5) {
-        const TTest tests[] = { 
-            {TGUID(), "1-1-1-1-1"}, 
+        const TTest tests[] = {
+            {TGUID(), "1-1-1-1-1"},
             {TGUID(), "00000001-0001-0001-0001-00000000001-"},
-            {Construct(0x10000001U, 0x10011001U, 0x10011001U, 0x10000001U), "10000001-1001-1001-1001-100110000001"}, 
-            {Construct(0x550e8400U, 0xe29b41d4U, 0xa7164466U, 0x55440000U), "550e8400-e29b-41d4-a716-446655440000"}, 
-            {Construct(0xffffffffU, 0xffffffffU, 0xffffffffU, 0xffffffffU), "ffffffff-ffff-ffff-ffff-ffffffffffff"}, 
-            {TGUID(), "ffffffff-ffffff-ff-ffff-ffffffffffff"}, 
+            {Construct(0x10000001U, 0x10011001U, 0x10011001U, 0x10000001U), "10000001-1001-1001-1001-100110000001"},
+            {Construct(0x550e8400U, 0xe29b41d4U, 0xa7164466U, 0x55440000U), "550e8400-e29b-41d4-a716-446655440000"},
+            {Construct(0xffffffffU, 0xffffffffU, 0xffffffffU, 0xffffffffU), "ffffffff-ffff-ffff-ffff-ffffffffffff"},
+            {TGUID(), "ffffffff-ffffff-ff-ffff-ffffffffffff"},
             {TGUID(), "ffffffff-ffff-ffff-ff-ffffffffffffff"}};
- 
-        for (const auto& t : tests) { 
-            UNIT_ASSERT_EQUAL(t.G, GetUuid(t.S)); 
-        } 
-    } 
+
+        for (const auto& t : tests) {
+            UNIT_ASSERT_EQUAL(t.G, GetUuid(t.S));
+        }
+    }
 
     Y_UNIT_TEST(DoubleConvert) {
         /**