summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/FileWatcher.h
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-17 17:14:40 -0500
committerTim Flynn <trflynn89@pm.me>2023-01-18 06:46:12 -0500
commit8419ca8b78a181731e7f32b90208599eac6e79a4 (patch)
tree93ab64f77fc965f962850c7b82cfb53a3a0a4e7e /Userland/Libraries/LibCore/FileWatcher.h
parent5bfc9daba13501308a607307ba09ae341012accc (diff)
downloadserenity-8419ca8b78a181731e7f32b90208599eac6e79a4.zip
LibCore: Handle multiple events in the FileWatcher event mask formatter
Diffstat (limited to 'Userland/Libraries/LibCore/FileWatcher.h')
-rw-r--r--Userland/Libraries/LibCore/FileWatcher.h46
1 files changed, 24 insertions, 22 deletions
diff --git a/Userland/Libraries/LibCore/FileWatcher.h b/Userland/Libraries/LibCore/FileWatcher.h
index 48f82de398..2a0ece2df8 100644
--- a/Userland/Libraries/LibCore/FileWatcher.h
+++ b/Userland/Libraries/LibCore/FileWatcher.h
@@ -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();
- }
-
- return builder.put_string(type);
+ bool had_any_flag = false;
+
+ 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 {};
}
};