summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-06-29 16:46:16 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-30 11:13:54 +0200
commitfc6d051dfdddc13835548537d025e760ba186b5b (patch)
tree12a5602dd4efc20f023fea95d390f3e241f6f9cf /Userland/Services
parent9b8f35259c375f6911b76c38ec37e6d422b26bbe (diff)
downloadserenity-fc6d051dfdddc13835548537d025e760ba186b5b.zip
AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and extension() will be changed to return StringView const& in a further commit. Due to this, users creating temporary LexicalPath objects just to call one of those getters will recieve a StringView const& pointing to a possible freed buffer. To avoid this, static methods for those APIs have been added, which will return a String by value to avoid those problems. All cases where temporary LexicalPath objects have been used as described above haven been changed to use the static APIs.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/FileOperation/main.cpp6
-rw-r--r--Userland/Services/LaunchServer/Launcher.cpp2
-rw-r--r--Userland/Services/Taskbar/main.cpp2
3 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp
index 44919a9a5f..ae05ac45da 100644
--- a/Userland/Services/FileOperation/main.cpp
+++ b/Userland/Services/FileOperation/main.cpp
@@ -70,7 +70,7 @@ static bool collect_work_items(const String& source, const String& destination,
items.append(WorkItem {
.type = WorkItem::Type::CopyFile,
.source = source,
- .destination = String::formatted("{}/{}", destination, LexicalPath(source).basename()),
+ .destination = String::formatted("{}/{}", destination, LexicalPath::basename(source)),
.size = st.st_size,
});
return true;
@@ -80,7 +80,7 @@ static bool collect_work_items(const String& source, const String& destination,
items.append(WorkItem {
.type = WorkItem::Type::CreateDirectory,
.source = {},
- .destination = String::formatted("{}/{}", destination, LexicalPath(source).basename()),
+ .destination = String::formatted("{}/{}", destination, LexicalPath::basename(source)),
.size = 0,
});
@@ -89,7 +89,7 @@ static bool collect_work_items(const String& source, const String& destination,
auto name = dt.next_path();
if (!collect_work_items(
String::formatted("{}/{}", source, name),
- String::formatted("{}/{}", destination, LexicalPath(source).basename()),
+ String::formatted("{}/{}", destination, LexicalPath::basename(source)),
items)) {
return false;
}
diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp
index c8765c26d6..96985375b2 100644
--- a/Userland/Services/LaunchServer/Launcher.cpp
+++ b/Userland/Services/LaunchServer/Launcher.cpp
@@ -269,7 +269,7 @@ void Launcher::for_each_handler_for_path(const String& path, Function<bool(const
if ((st.st_mode & S_IFMT) == S_IFREG && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
f(get_handler_for_executable(Handler::Type::Application, path));
- auto extension = LexicalPath(path).extension().to_lowercase();
+ auto extension = LexicalPath::extension(path).to_lowercase();
for_each_handler(extension, m_file_handlers, [&](const auto& handler) -> bool {
if (handler.handler_type != Handler::Type::Default || handler.file_types.contains(extension))
diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp
index 76f0c11094..da61801013 100644
--- a/Userland/Services/Taskbar/main.cpp
+++ b/Userland/Services/Taskbar/main.cpp
@@ -198,7 +198,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
while (dt.has_next()) {
auto theme_name = dt.next_path();
auto theme_path = String::formatted("/res/themes/{}", theme_name);
- g_themes.append({ LexicalPath(theme_name).title(), theme_path });
+ g_themes.append({ LexicalPath::title(theme_name), theme_path });
}
quick_sort(g_themes, [](auto& a, auto& b) { return a.name < b.name; });
}