mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05: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
2 changed files with 21 additions and 0 deletions
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…
Add table
Reference in a new issue