mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibCore: Handle multiple events in the FileWatcher event mask formatter
This commit is contained in:
parent
5bfc9daba1
commit
8419ca8b78
Notes:
sideshowbarker
2024-07-17 06:28:38 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/8419ca8b78 Pull-request: https://github.com/SerenityOS/serenity/pull/17063 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/gmta ✅
1 changed files with 23 additions and 21 deletions
|
@ -95,28 +95,30 @@ template<>
|
|||
struct Formatter<Core::FileWatcherEvent::Type> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Core::FileWatcherEvent::Type const& value)
|
||||
{
|
||||
StringView type;
|
||||
switch (value) {
|
||||
case Core::FileWatcherEvent::Type::ChildCreated:
|
||||
type = "ChildCreated"sv;
|
||||
break;
|
||||
case Core::FileWatcherEvent::Type::ChildDeleted:
|
||||
type = "ChildDeleted"sv;
|
||||
break;
|
||||
case Core::FileWatcherEvent::Type::Deleted:
|
||||
type = "Deleted"sv;
|
||||
break;
|
||||
case Core::FileWatcherEvent::Type::ContentModified:
|
||||
type = "ContentModified"sv;
|
||||
break;
|
||||
case Core::FileWatcherEvent::Type::MetadataModified:
|
||||
type = "MetadataModified"sv;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
bool had_any_flag = false;
|
||||
|
||||
return builder.put_string(type);
|
||||
auto put_string_if_has_flag = [&](auto mask, auto name) -> ErrorOr<void> {
|
||||
if (!has_flag(value, mask))
|
||||
return {};
|
||||
|
||||
if (had_any_flag)
|
||||
TRY(builder.put_string(", "sv));
|
||||
TRY(builder.put_string(name));
|
||||
|
||||
had_any_flag = true;
|
||||
return {};
|
||||
};
|
||||
|
||||
TRY(builder.put_string("["sv));
|
||||
TRY(put_string_if_has_flag(Core::FileWatcherEvent::Type::ChildCreated, "ChildCreated"sv));
|
||||
TRY(put_string_if_has_flag(Core::FileWatcherEvent::Type::ChildDeleted, "ChildDeleted"sv));
|
||||
TRY(put_string_if_has_flag(Core::FileWatcherEvent::Type::Deleted, "Deleted"sv));
|
||||
TRY(put_string_if_has_flag(Core::FileWatcherEvent::Type::ContentModified, "ContentModified"sv));
|
||||
TRY(put_string_if_has_flag(Core::FileWatcherEvent::Type::MetadataModified, "MetadataModified"sv));
|
||||
TRY(builder.put_string("]"sv));
|
||||
|
||||
VERIFY(had_any_flag);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue