MCPcopy Create free account
hub / github.com/catboost/catboost / GetGuid

Function GetGuid

util/generic/guid.cpp:90–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90bool GetGuid(const TStringBuf s, TGUID& result) {
91 size_t partId = 0;
92 ui64 partValue = 0;
93 bool isEmptyPart = true;
94
95 for (size_t i = 0; i != s.size(); ++i) {
96 const char c = s[i];
97
98 if (c == '-') {
99 if (isEmptyPart || partId == 3) { // x-y--z, -x-y-z or x-y-z-m-...
100 return false;
101 }
102 result.dw[partId] = static_cast<ui32>(partValue);
103 ++partId;
104 partValue = 0;
105 isEmptyPart = true;
106 continue;
107 }
108
109 ui32 digit = 0;
110 if (!GetDigit(c, digit)) {
111 return false;
112 }
113
114 partValue = partValue * 16 + digit;
115 isEmptyPart = false;
116
117 // overflow check
118 if (partValue > Max<ui32>()) {
119 return false;
120 }
121 }
122
123 if (partId != 3 || isEmptyPart) { // x-y or x-y-z-
124 return false;
125 }
126 result.dw[partId] = static_cast<ui32>(partValue);
127 return true;
128}
129
130// Parses GUID from s and checks that it's valid.
131// In case of error returns TGUID().

Callers 4

StepMethod · 0.85
GetDebugInfoMethod · 0.85
Y_UNIT_TESTFunction · 0.85

Calls 3

GetDigitFunction · 0.85
TGUIDClass · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected