mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add formatters for Utf8View and Utf32View
Useful for debugging, especially in templated contexts.
This commit is contained in:
parent
385b880862
commit
0f20586346
Notes:
sideshowbarker
2024-07-17 08:43:11 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0f20586346 Pull-request: https://github.com/SerenityOS/serenity/pull/17558
5 changed files with 35 additions and 0 deletions
|
@ -33,6 +33,7 @@ set(AK_SOURCES
|
|||
URL.cpp
|
||||
URLParser.cpp
|
||||
Utf16View.cpp
|
||||
Utf32View.cpp
|
||||
Utf8View.cpp
|
||||
UUID.cpp
|
||||
)
|
||||
|
|
17
AK/Utf32View.cpp
Normal file
17
AK/Utf32View.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
ErrorOr<void> Formatter<Utf32View>::format(FormatBuilder& builder, Utf32View const& string)
|
||||
{
|
||||
return builder.builder().try_append(string);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Checked.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -119,6 +120,11 @@ private:
|
|||
size_t m_length { 0 };
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Utf32View> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder&, Utf32View const&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
|
|
@ -303,4 +303,9 @@ Optional<u32> Utf8CodePointIterator::peek(size_t offset) const
|
|||
return *new_iterator;
|
||||
}
|
||||
|
||||
ErrorOr<void> Formatter<Utf8View>::format(FormatBuilder& builder, Utf8View const& string)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, string.as_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
|
@ -164,6 +165,11 @@ private:
|
|||
Utf8CodePointIterator m_it;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Utf8View> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder&, Utf8View const&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
|
Loading…
Reference in a new issue