-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
unique_string.cpp
42 lines (35 loc) · 900 Bytes
/
unique_string.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// unique_string.cpp - unique string implementation
//
// lecui user interface library, part of the liblec library
// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
//
// Released under the MIT license. For full details see the
// file LICENSE.txt
//
#include "lecui.h"
// for UuidToString, RpcStringFree
#include <rpc.h>
#pragma comment(lib, "rpcrt4.lib")
namespace liblec {
namespace lecui {
std::string unique_string() {
std::string unique;
UUID uuid;
UuidCreate(&uuid);
RPC_CSTR uuidStr;
RPC_STATUS status = UuidToStringA(&uuid, &uuidStr);
unique += reinterpret_cast<char*>(uuidStr);
RpcStringFreeA(&uuidStr);
return unique;
}
std::string unique_string_short() {
std::string unique = unique_string();
const auto idx = unique.find('-');
if (idx != std::string::npos)
return unique.substr(0, idx);
else
return unique;
}
}
}