mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +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
5 changed files with 35 additions and 0 deletions
|
@ -33,6 +33,7 @@ set(AK_SOURCES
|
||||||
URL.cpp
|
URL.cpp
|
||||||
URLParser.cpp
|
URLParser.cpp
|
||||||
Utf16View.cpp
|
Utf16View.cpp
|
||||||
|
Utf32View.cpp
|
||||||
Utf8View.cpp
|
Utf8View.cpp
|
||||||
UUID.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/Assertions.h>
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -119,6 +120,11 @@ private:
|
||||||
size_t m_length { 0 };
|
size_t m_length { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Formatter<Utf32View> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder&, Utf32View const&);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
|
|
|
@ -303,4 +303,9 @@ Optional<u32> Utf8CodePointIterator::peek(size_t offset) const
|
||||||
return *new_iterator;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
@ -164,6 +165,11 @@ private:
|
||||||
Utf8CodePointIterator m_it;
|
Utf8CodePointIterator m_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Formatter<Utf8View> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder&, Utf8View const&);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue