AK: Add formatters for Utf8View and Utf32View

Useful for debugging, especially in templated contexts.
This commit is contained in:
Timothy Flynn 2023-02-20 08:08:40 -05:00 committed by Andreas Kling
parent 385b880862
commit 0f20586346
Notes: sideshowbarker 2024-07-17 08:43:11 +09:00
5 changed files with 35 additions and 0 deletions

View file

@ -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
View 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);
}
}

View file

@ -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

View file

@ -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());
}
}

View file

@ -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