mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
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.
This commit is contained in:
parent
3953004e60
commit
1748362e05
3 changed files with 45 additions and 0 deletions
28
Userland/Libraries/LibWeb/Infra/ByteSequences.cpp
Normal file
28
Userland/Libraries/LibWeb/Infra/ByteSequences.cpp
Normal file
|
@ -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]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue