From 0f205863465e88335d782e2e9c9ace81c9878727 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 20 Feb 2023 08:08:40 -0500 Subject: [PATCH] AK: Add formatters for Utf8View and Utf32View Useful for debugging, especially in templated contexts. --- AK/CMakeLists.txt | 1 + AK/Utf32View.cpp | 17 +++++++++++++++++ AK/Utf32View.h | 6 ++++++ AK/Utf8View.cpp | 5 +++++ AK/Utf8View.h | 6 ++++++ 5 files changed, 35 insertions(+) create mode 100644 AK/Utf32View.cpp diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 1188c0f916..72e513c60a 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -33,6 +33,7 @@ set(AK_SOURCES URL.cpp URLParser.cpp Utf16View.cpp + Utf32View.cpp Utf8View.cpp UUID.cpp ) diff --git a/AK/Utf32View.cpp b/AK/Utf32View.cpp new file mode 100644 index 0000000000..de18abb958 --- /dev/null +++ b/AK/Utf32View.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace AK { + +ErrorOr Formatter::format(FormatBuilder& builder, Utf32View const& string) +{ + return builder.builder().try_append(string); +} + +} diff --git a/AK/Utf32View.h b/AK/Utf32View.h index 9c116954c4..2c3c122f99 100644 --- a/AK/Utf32View.h +++ b/AK/Utf32View.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace AK { @@ -119,6 +120,11 @@ private: size_t m_length { 0 }; }; +template<> +struct Formatter : Formatter { + ErrorOr format(FormatBuilder&, Utf32View const&); +}; + } #if USING_AK_GLOBALLY diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index 5ebfccedfd..27f44e0b26 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -303,4 +303,9 @@ Optional Utf8CodePointIterator::peek(size_t offset) const return *new_iterator; } +ErrorOr Formatter::format(FormatBuilder& builder, Utf8View const& string) +{ + return Formatter::format(builder, string.as_string()); +} + } diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 624eab7cbd..e9f7e7635c 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -164,6 +165,11 @@ private: Utf8CodePointIterator m_it; }; +template<> +struct Formatter : Formatter { + ErrorOr format(FormatBuilder&, Utf8View const&); +}; + } #if USING_AK_GLOBALLY