mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Remove unused UUID class
This commit is contained in:
parent
47287d2cf1
commit
7f5e960b72
Notes:
sideshowbarker
2024-07-17 05:01:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/7f5e960b72 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/197 Reviewed-by: https://github.com/ADKaster
4 changed files with 0 additions and 149 deletions
|
@ -33,7 +33,6 @@ set(AK_SOURCES
|
|||
StringUtils.cpp
|
||||
StringView.cpp
|
||||
Time.cpp
|
||||
UUID.cpp
|
||||
Utf16View.cpp
|
||||
Utf32View.cpp
|
||||
Utf8View.cpp
|
||||
|
|
100
AK/UUID.cpp
100
AK/UUID.cpp
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/AllOf.h>
|
||||
#include <AK/Hex.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/UUID.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
UUID::UUID(Array<u8, 16> uuid_buffer)
|
||||
{
|
||||
uuid_buffer.span().copy_to(m_uuid_buffer);
|
||||
}
|
||||
|
||||
void UUID::convert_string_view_to_little_endian_uuid(StringView uuid_string_view)
|
||||
{
|
||||
VERIFY(uuid_string_view.length() == 36);
|
||||
auto first_unit = MUST(decode_hex(uuid_string_view.substring_view(0, 8)));
|
||||
auto second_unit = MUST(decode_hex(uuid_string_view.substring_view(9, 4)));
|
||||
auto third_unit = MUST(decode_hex(uuid_string_view.substring_view(14, 4)));
|
||||
auto fourth_unit = MUST(decode_hex(uuid_string_view.substring_view(19, 4)));
|
||||
auto fifth_unit = MUST(decode_hex(uuid_string_view.substring_view(24, 12)));
|
||||
|
||||
VERIFY(first_unit.size() == 4 && second_unit.size() == 2
|
||||
&& third_unit.size() == 2 && fourth_unit.size() == 2
|
||||
&& fifth_unit.size() == 6);
|
||||
|
||||
m_uuid_buffer.span().overwrite(0, first_unit.data(), first_unit.size());
|
||||
m_uuid_buffer.span().overwrite(4, second_unit.data(), second_unit.size());
|
||||
m_uuid_buffer.span().overwrite(6, third_unit.data(), third_unit.size());
|
||||
m_uuid_buffer.span().overwrite(8, fourth_unit.data(), fourth_unit.size());
|
||||
m_uuid_buffer.span().overwrite(10, fifth_unit.data(), fifth_unit.size());
|
||||
}
|
||||
|
||||
void UUID::convert_string_view_to_mixed_endian_uuid(StringView uuid_string_view)
|
||||
{
|
||||
VERIFY(uuid_string_view.length() == 36);
|
||||
auto first_unit = MUST(decode_hex(uuid_string_view.substring_view(0, 8)));
|
||||
auto second_unit = MUST(decode_hex(uuid_string_view.substring_view(9, 4)));
|
||||
auto third_unit = MUST(decode_hex(uuid_string_view.substring_view(14, 4)));
|
||||
auto fourth_unit = MUST(decode_hex(uuid_string_view.substring_view(19, 4)));
|
||||
auto fifth_unit = MUST(decode_hex(uuid_string_view.substring_view(24, 12)));
|
||||
|
||||
VERIFY(first_unit.size() == 4 && second_unit.size() == 2
|
||||
&& third_unit.size() == 2 && fourth_unit.size() == 2
|
||||
&& fifth_unit.size() == 6);
|
||||
|
||||
// Revert endianness for first 4 bytes
|
||||
for (size_t index = 0; index < 4; index++) {
|
||||
m_uuid_buffer[3 - index] = first_unit[index];
|
||||
}
|
||||
|
||||
// Revert endianness for second 2 bytes and again for 2 bytes
|
||||
for (size_t index = 0; index < 2; index++) {
|
||||
m_uuid_buffer[3 + 2 - index] = second_unit[index];
|
||||
m_uuid_buffer[5 + 2 - index] = third_unit[index];
|
||||
}
|
||||
|
||||
m_uuid_buffer.span().overwrite(8, fourth_unit.data(), fourth_unit.size());
|
||||
m_uuid_buffer.span().overwrite(10, fifth_unit.data(), fifth_unit.size());
|
||||
}
|
||||
|
||||
UUID::UUID(StringView uuid_string_view, Endianness endianness)
|
||||
{
|
||||
if (endianness == Endianness::Little) {
|
||||
convert_string_view_to_little_endian_uuid(uuid_string_view);
|
||||
return;
|
||||
} else if (endianness == Endianness::Mixed) {
|
||||
convert_string_view_to_mixed_endian_uuid(uuid_string_view);
|
||||
return;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<String> UUID::to_string() const
|
||||
{
|
||||
auto buffer_span = m_uuid_buffer.span();
|
||||
StringBuilder builder(36);
|
||||
TRY(builder.try_append(encode_hex(buffer_span.trim(4))));
|
||||
TRY(builder.try_append('-'));
|
||||
TRY(builder.try_append(encode_hex(buffer_span.slice(4, 2))));
|
||||
TRY(builder.try_append('-'));
|
||||
TRY(builder.try_append(encode_hex(buffer_span.slice(6, 2))));
|
||||
TRY(builder.try_append('-'));
|
||||
TRY(builder.try_append(encode_hex(buffer_span.slice(8, 2))));
|
||||
TRY(builder.try_append('-'));
|
||||
TRY(builder.try_append(encode_hex(buffer_span.slice(10, 6))));
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
bool UUID::is_zero() const
|
||||
{
|
||||
return all_of(m_uuid_buffer, [](auto const octet) { return octet == 0; });
|
||||
}
|
||||
|
||||
}
|
45
AK/UUID.h
45
AK/UUID.h
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class UUID {
|
||||
public:
|
||||
enum class Endianness {
|
||||
Mixed,
|
||||
Little
|
||||
};
|
||||
|
||||
UUID() = default;
|
||||
UUID(Array<u8, 16> uuid_buffer);
|
||||
UUID(StringView, Endianness endianness = Endianness::Little);
|
||||
~UUID() = default;
|
||||
|
||||
bool operator==(const UUID&) const = default;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
bool is_zero() const;
|
||||
|
||||
private:
|
||||
void convert_string_view_to_little_endian_uuid(StringView);
|
||||
void convert_string_view_to_mixed_endian_uuid(StringView);
|
||||
|
||||
Array<u8, 16> m_uuid_buffer {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::UUID;
|
||||
#endif
|
|
@ -193,10 +193,7 @@ shared_library("AK") {
|
|||
"Types.h",
|
||||
"UFixedBigInt.h",
|
||||
"UFixedBigIntDivision.h",
|
||||
"UUID.cpp",
|
||||
"UUID.h",
|
||||
"UnicodeUtils.h",
|
||||
"Userspace.h",
|
||||
"Utf16View.cpp",
|
||||
"Utf16View.h",
|
||||
"Utf32View.cpp",
|
||||
|
|
Loading…
Reference in a new issue