blob: 96c00efc5de7335260434954bedf8446014e9b8e (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* ========================================================
*
* HCore
* Copyright Mahrouss Logic, all rights reserved.
*
* ========================================================
*/
#include <CFKit/GUIDWizard.hpp>
#include <NewKit/Ref.hpp>
// begin of ascii 'readable' characters. (A, C, C, 1, 2)
#define kAsciiBegin 47
// @brief Size of UUID.
#define kUUIDSize 37
namespace HCore::XRN::Version1 {
auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> {
GUIDSequence* seq = new GUIDSequence();
MUST_PASS(seq);
Ref<GUIDSequence*> sequenceReference{seq, true};
sequenceReference->m_Ms1 |= uuidSeq[0];
sequenceReference->m_Ms2 |= uuidSeq[1];
sequenceReference->m_Ms3 |= uuidSeq[2];
sequenceReference->m_Ms3 |= uuidSeq[3];
return sequenceReference;
}
// @brief Tries to make a guid out of a string.
// This function is not complete for now
auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> {
Char buf[kUUIDSize];
for (SizeT index = 0; index < 16; ++index) {
buf[index] = seq->u8[index] + kAsciiBegin;
}
for (SizeT index = 16; index < 24; ++index) {
buf[index] = seq->u16[index] + kAsciiBegin;
}
for (SizeT index = 24; index < 28; ++index) {
buf[index] = seq->u32[index] + kAsciiBegin;
}
auto view = StringBuilder::Construct(buf);
if (view) return ErrorOr<Ref<StringView>>{view.Leak()};
return ErrorOr<Ref<StringView>>{-1};
}
} // namespace HCore::XRN::Version1
|