diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 5c083401c0..8665b6e697 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -237,6 +237,7 @@ set(SOURCES HTML/WorkerLocation.cpp HighResolutionTime/Performance.cpp ImageDecoding.cpp + Infra/ByteSequences.cpp IntersectionObserver/IntersectionObserver.cpp Layout/BlockContainer.cpp Layout/BlockFormattingContext.cpp diff --git a/Userland/Libraries/LibWeb/Infra/ByteSequences.cpp b/Userland/Libraries/LibWeb/Infra/ByteSequences.cpp new file mode 100644 index 0000000000..f54008c0db --- /dev/null +++ b/Userland/Libraries/LibWeb/Infra/ByteSequences.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Infra { + +// https://infra.spec.whatwg.org/#byte-lowercase +void byte_lowercase(ByteBuffer& bytes) +{ + // To byte-lowercase a byte sequence, increase each byte it contains, in the range 0x41 (A) to 0x5A (Z), inclusive, by 0x20. + for (size_t i = 0; i < bytes.size(); ++i) + bytes[i] = to_ascii_lowercase(bytes[i]); +} + +// https://infra.spec.whatwg.org/#byte-uppercase +void byte_uppercase(ByteBuffer& bytes) +{ + // To byte-uppercase a byte sequence, subtract each byte it contains, in the range 0x61 (a) to 0x7A (z), inclusive, by 0x20. + for (size_t i = 0; i < bytes.size(); ++i) + bytes[i] = to_ascii_uppercase(bytes[i]); +} + +} diff --git a/Userland/Libraries/LibWeb/Infra/ByteSequences.h b/Userland/Libraries/LibWeb/Infra/ByteSequences.h new file mode 100644 index 0000000000..aac82e314e --- /dev/null +++ b/Userland/Libraries/LibWeb/Infra/ByteSequences.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Infra { + +void byte_lowercase(ByteBuffer&); +void byte_uppercase(ByteBuffer&); + +}