diff options
author | Linus Groh <mail@linusgroh.de> | 2022-07-11 21:44:43 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-14 00:42:26 +0100 |
commit | 1748362e05a520986039f25968880260067bf5f7 (patch) | |
tree | 29b8734e01b410b8130ab8f8c6cece273b849642 | |
parent | 3953004e609ca6099bdc09d0e118ff083cce2b34 (diff) | |
download | serenity-1748362e05a520986039f25968880260067bf5f7.zip |
LibWeb: Add 'byte-{lower,upper}case' operations from the Infra spec
Usually operations that mirror AOs from the Infra spec are simply part
of the underlying data structures in AK directly, but these don't seem
generally useful enough to add them as ByteBuffer methods.
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Infra/ByteSequences.cpp | 28 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Infra/ByteSequences.h | 16 |
3 files changed, 45 insertions, 0 deletions
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 <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/CharacterTypes.h> +#include <LibWeb/Infra/ByteSequences.h> + +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 <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/ByteBuffer.h> + +namespace Web::Infra { + +void byte_lowercase(ByteBuffer&); +void byte_uppercase(ByteBuffer&); + +} |