mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
AK+LibTimeZone: Add debug only formatter for Optional
I found this handy for debugging, and so might others. This now also adds a formatter for TimeZone::TimeZone. This is needed for FormatIfSupported<Optional<TimeZone::TimeZone>> to compile. As FormatIfSupported sees a formatter for Optional exists, but not that there's not one for TimeZone::TimeZone.
This commit is contained in:
parent
fc1fd907b4
commit
454ecf24ea
Notes:
sideshowbarker
2024-07-17 00:25:35 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/454ecf24ea Pull-request: https://github.com/SerenityOS/serenity/pull/18473 Reviewed-by: https://github.com/nico
12
AK/Format.h
12
AK/Format.h
@ -715,6 +715,18 @@ struct Formatter<ErrorOr<T, ErrorType>> : Formatter<FormatString> {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Formatter<Optional<T>> : Formatter<FormatString> {
|
||||
static constexpr bool is_debug_only() { return true; }
|
||||
|
||||
ErrorOr<void> format(FormatBuilder& builder, Optional<T> const& optional)
|
||||
{
|
||||
if (optional.has_value())
|
||||
return Formatter<FormatString>::format(builder, "Optional({})"sv, *optional);
|
||||
return builder.put_literal("OptionalNone"sv);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace AK
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <AK/Array.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Time.h>
|
||||
@ -74,3 +75,11 @@ StringView region_to_string(Region region);
|
||||
Vector<StringView> time_zones_in_region(StringView region);
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<TimeZone::TimeZone> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, TimeZone::TimeZone const& time_zone)
|
||||
{
|
||||
return Formatter<FormatString>::format(builder, TimeZone::time_zone_to_string(time_zone));
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user