summaryrefslogtreecommitdiff
path: root/Source/cmUuid.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmUuid.cxx')
-rw-r--r--Source/cmUuid.cxx30
1 files changed, 11 insertions, 19 deletions
diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx
index 201e1ccef..cd52b3f30 100644
--- a/Source/cmUuid.cxx
+++ b/Source/cmUuid.cxx
@@ -2,18 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmUuid.h"
-#include "cmCryptoHash.h"
+#include <array>
+#include <cstring>
-#include <string.h>
+#include "cmCryptoHash.h"
-cmUuid::cmUuid()
-{
- Groups.push_back(4);
- Groups.push_back(2);
- Groups.push_back(2);
- Groups.push_back(2);
- Groups.push_back(6);
-}
+static const std::array<int, 5> kUuidGroups = { { 4, 2, 2, 2, 6 } };
std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
std::string const& name) const
@@ -59,7 +53,7 @@ void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
std::string cmUuid::FromDigest(const unsigned char* digest,
unsigned char version) const
{
- typedef unsigned char byte_t;
+ using byte_t = unsigned char;
byte_t uuid[16] = { 0 };
memcpy(uuid, digest, 16);
@@ -83,11 +77,11 @@ bool cmUuid::StringToBinary(std::string const& input,
return false;
}
size_t index = 0;
- for (size_t i = 0; i < this->Groups.size(); ++i) {
+ for (size_t i = 0; i < kUuidGroups.size(); ++i) {
if (i != 0 && input[index++] != '-') {
return false;
}
- size_t digits = this->Groups[i] * 2;
+ size_t digits = kUuidGroups[i] * 2;
if (!StringToBinaryImpl(input.substr(index, digits), output)) {
return false;
}
@@ -103,12 +97,12 @@ std::string cmUuid::BinaryToString(const unsigned char* input) const
std::string output;
size_t inputIndex = 0;
- for (size_t i = 0; i < this->Groups.size(); ++i) {
+ for (size_t i = 0; i < kUuidGroups.size(); ++i) {
if (i != 0) {
output += '-';
}
- size_t bytes = this->Groups[i];
+ size_t bytes = kUuidGroups[i];
for (size_t j = 0; j < bytes; ++j) {
unsigned char byte = input[inputIndex++];
output += this->ByteToHex(byte);
@@ -120,14 +114,12 @@ std::string cmUuid::BinaryToString(const unsigned char* input) const
std::string cmUuid::ByteToHex(unsigned char byte) const
{
- std::string result;
+ std::string result(" ");
for (int i = 0; i < 2; ++i) {
unsigned char rest = byte % 16;
byte /= 16;
-
char c = (rest < 0xA) ? char('0' + rest) : char('a' + (rest - 0xA));
-
- result = c + result;
+ result.at(1 - i) = c;
}
return result;