diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index 7efbe04b1a9..257b39963b5 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -44,6 +44,30 @@ public: return LexicalPath { builder.to_string() }; } + static String dirname(String path) + { + auto lexical_path = LexicalPath(move(path)); + return lexical_path.dirname(); + } + + static String basename(String path) + { + auto lexical_path = LexicalPath(move(path)); + return lexical_path.basename(); + } + + static String title(String path) + { + auto lexical_path = LexicalPath(move(path)); + return lexical_path.title(); + } + + static String extension(String path) + { + auto lexical_path = LexicalPath(move(path)); + return lexical_path.extension(); + } + private: void canonicalize(); diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 621ec6a7793..1002b9f67b9 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -533,7 +533,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) if (old_parent_custody->is_readonly() || new_parent_custody->is_readonly()) return EROFS; - auto new_basename = LexicalPath(new_path).basename(); + auto new_basename = LexicalPath::basename(new_path); if (!new_custody_or_error.is_error()) { auto& new_custody = *new_custody_or_error.value(); @@ -554,7 +554,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) if (auto result = new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()); result.is_error()) return result; - if (auto result = old_parent_inode.remove_child(LexicalPath(old_path).basename()); result.is_error()) + if (auto result = old_parent_inode.remove_child(LexicalPath::basename(old_path)); result.is_error()) return result; return KSuccess; @@ -656,7 +656,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base) if (!hard_link_allowed(old_inode)) return EPERM; - return parent_inode.add_child(old_inode, LexicalPath(new_path).basename(), old_inode.mode()); + return parent_inode.add_child(old_inode, LexicalPath::basename(new_path), old_inode.mode()); } KResult VFS::unlink(StringView path, Custody& base) @@ -689,7 +689,7 @@ KResult VFS::unlink(StringView path, Custody& base) if (parent_custody->is_readonly()) return EROFS; - if (auto result = parent_inode.remove_child(LexicalPath(path).basename()); result.is_error()) + if (auto result = parent_inode.remove_child(LexicalPath::basename(path)); result.is_error()) return result; return KSuccess; @@ -771,7 +771,7 @@ KResult VFS::rmdir(StringView path, Custody& base) if (auto result = inode.remove_child(".."); result.is_error()) return result; - return parent_inode.remove_child(LexicalPath(path).basename()); + return parent_inode.remove_child(LexicalPath::basename(path)); } VFS::Mount::Mount(FS& guest_fs, Custody* host_custody, int flags) diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp index 0cb102ae742..409c0df71e0 100644 --- a/Kernel/Syscalls/unveil.cpp +++ b/Kernel/Syscalls/unveil.cpp @@ -91,7 +91,7 @@ KResultOr Process::sys$unveil(Userspaceabsolute_path(); } else if (custody_or_error.error() == -ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) { - String basename = LexicalPath(path.view()).basename(); + String basename = LexicalPath::basename(path.view()); new_unveiled_path = String::formatted("{}/{}", parent_custody->absolute_path(), basename); } else { // FIXME Should this be EINVAL? diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index 1a9dedff279..acca4a13852 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -204,7 +204,7 @@ int main(int argc, char** argv) auto& icon_image_widget = *widget.find_descendant_of_type_named("icon"); icon_image_widget.set_bitmap(GUI::FileIconProvider::icon_for_executable(executable_path).bitmap_for_size(32)); - auto app_name = LexicalPath(executable_path).basename(); + auto app_name = LexicalPath::basename(executable_path); auto af = Desktop::AppFile::get_for_app(app_name); if (af->is_valid()) app_name = af->name(); diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 1efde7e7b3d..8dcb7bd20ba 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -55,7 +55,7 @@ static void run_file_operation([[maybe_unused]] FileOperation operation, const S perror("dup2"); _exit(1); } - if (execlp("/bin/FileOperation", "/bin/FileOperation", "Copy", source.characters(), LexicalPath(destination).dirname().characters(), nullptr) < 0) { + if (execlp("/bin/FileOperation", "/bin/FileOperation", "Copy", source.characters(), LexicalPath::dirname(destination).characters(), nullptr) < 0) { perror("execlp"); _exit(1); } @@ -609,7 +609,7 @@ void DirectoryView::handle_drop(const GUI::ModelIndex& index, const GUI::DropEve for (auto& url_to_copy : urls) { if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path()) continue; - auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath(url_to_copy.path()).basename()); + auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath::basename(url_to_copy.path())); if (url_to_copy.path() == new_path) continue; diff --git a/Userland/Applications/FileManager/FileUtils.cpp b/Userland/Applications/FileManager/FileUtils.cpp index ff2fb4f67a2..db92e5b6b62 100644 --- a/Userland/Applications/FileManager/FileUtils.cpp +++ b/Userland/Applications/FileManager/FileUtils.cpp @@ -47,7 +47,7 @@ void delete_paths(const Vector& paths, bool should_confirm, GUI::Window* { String message; if (paths.size() == 1) { - message = String::formatted("Really delete {}?", LexicalPath(paths[0]).basename()); + message = String::formatted("Really delete {}?", LexicalPath::basename(paths[0])); } else { message = String::formatted("Really delete {} files?", paths.size()); } diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 2fac159fcd6..3133a647bc5 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -187,7 +187,7 @@ void do_paste(const String& target_directory, GUI::Window* window) void do_create_link(const Vector& selected_file_paths, GUI::Window* window) { auto path = selected_file_paths.first(); - auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath { path }.basename()); + auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath::basename(path)); if (auto result = Core::File::link_file(destination, path); result.is_error()) { GUI::MessageBox::show(window, String::formatted("Could not create desktop shortcut:\n{}", result.error()), "File Manager", GUI::MessageBox::Type::Error); @@ -736,7 +736,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio selected = directory_view.selected_file_paths(); } else { path = directories_model->full_path(tree_view.selection().first()); - container_dir_path = LexicalPath(path).basename(); + container_dir_path = LexicalPath::basename(path); selected = tree_view_selected_file_paths(); } @@ -1115,7 +1115,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio for (auto& url_to_copy : urls) { if (!url_to_copy.is_valid() || url_to_copy.path() == directory) continue; - auto new_path = String::formatted("{}/{}", directory, LexicalPath(url_to_copy.path()).basename()); + auto new_path = String::formatted("{}/{}", directory, LexicalPath::basename(url_to_copy.path())); if (url_to_copy.path() == new_path) continue; diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 61e77129343..6e4067c0f1b 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -432,7 +432,7 @@ void Image::set_title(String title) void Image::set_path(String path) { m_path = move(path); - set_title(LexicalPath(m_path).basename()); + set_title(LexicalPath::basename(m_path)); } } diff --git a/Userland/Applications/SoundPlayer/PlaylistWidget.cpp b/Userland/Applications/SoundPlayer/PlaylistWidget.cpp index e0c2ce6e527..e4d2b1032c4 100644 --- a/Userland/Applications/SoundPlayer/PlaylistWidget.cpp +++ b/Userland/Applications/SoundPlayer/PlaylistWidget.cpp @@ -36,7 +36,7 @@ GUI::Variant PlaylistModel::data(const GUI::ModelIndex& index, GUI::ModelRole ro if (role == GUI::ModelRole::Display) { switch (index.column()) { case 0: - return m_playlist_items[index.row()].extended_info->track_display_title.value_or(LexicalPath(m_playlist_items[index.row()].path).title()); + return m_playlist_items[index.row()].extended_info->track_display_title.value_or(LexicalPath::title(m_playlist_items[index.row()].path)); case 1: return format_duration(m_playlist_items[index.row()].extended_info->track_length_in_seconds.value_or(0)); case 2: diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index c4728c5774a..b3f87ffdfe0 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -300,7 +300,7 @@ void SoundPlayerWidgetAdvancedView::try_fill_missing_info(Vector& entr } if (!entry.extended_info->track_display_title.has_value()) - entry.extended_info->track_display_title = LexicalPath(entry.path).title(); + entry.extended_info->track_display_title = LexicalPath::title(entry.path); if (!entry.extended_info->track_length_in_seconds.has_value()) { if (auto reader = Audio::Loader::create(entry.path); !reader->has_error()) entry.extended_info->track_length_in_seconds = reader->total_samples() / reader->sample_rate(); diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp index c648e8c4eda..dd1f251d053 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp @@ -300,7 +300,7 @@ Result ExportDialog::make_and_run_for(StringView mime, Core::File& } else { auto page = GUI::WizardPage::construct( "Export File Format", - String::formatted("Select the format you wish to export to '{}' as", LexicalPath { file.filename() }.basename())); + String::formatted("Select the format you wish to export to '{}' as", LexicalPath::basename(file.filename()))); page->on_next_page = [] { return nullptr; }; diff --git a/Userland/Applications/Spreadsheet/HelpWindow.cpp b/Userland/Applications/Spreadsheet/HelpWindow.cpp index 247ef762734..e3310546692 100644 --- a/Userland/Applications/Spreadsheet/HelpWindow.cpp +++ b/Userland/Applications/Spreadsheet/HelpWindow.cpp @@ -82,7 +82,7 @@ HelpWindow::HelpWindow(GUI::Window* parent) m_webview->on_link_click = [this](auto& url, auto&, auto&&) { VERIFY(url.protocol() == "spreadsheet"); if (url.host() == "example") { - auto entry = LexicalPath(url.path()).basename(); + auto entry = LexicalPath::basename(url.path()); auto doc_option = m_docs.get(entry); if (!doc_option.is_object()) { GUI::MessageBox::show_error(this, String::formatted("No documentation entry found for '{}'", url.path())); @@ -120,7 +120,7 @@ HelpWindow::HelpWindow(GUI::Window* parent) widget.add_sheet(sheet.release_nonnull()); window->show(); } else if (url.host() == "doc") { - auto entry = LexicalPath(url.path()).basename(); + auto entry = LexicalPath::basename(url.path()); m_webview->load(URL::create_with_data("text/html", render(entry))); } else { dbgln("Invalid spreadsheet action domain '{}'", url.host()); diff --git a/Userland/Applications/Spreadsheet/ImportDialog.cpp b/Userland/Applications/Spreadsheet/ImportDialog.cpp index 7e95c4ea959..0839da13648 100644 --- a/Userland/Applications/Spreadsheet/ImportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ImportDialog.cpp @@ -252,7 +252,7 @@ Result, String> ImportDialog::make_and_run_for(String } else { auto page = GUI::WizardPage::construct( "Import File Format", - String::formatted("Select the format you wish to import '{}' as", LexicalPath { file.filename() }.basename())); + String::formatted("Select the format you wish to import '{}' as", LexicalPath::basename(file.filename()))); page->on_next_page = [] { return nullptr; }; diff --git a/Userland/DevTools/HackStudio/CodeDocument.cpp b/Userland/DevTools/HackStudio/CodeDocument.cpp index bc08806b595..330f3ffdee0 100644 --- a/Userland/DevTools/HackStudio/CodeDocument.cpp +++ b/Userland/DevTools/HackStudio/CodeDocument.cpp @@ -22,7 +22,7 @@ CodeDocument::CodeDocument(const String& file_path, Client* client) : TextDocument(client) , m_file_path(file_path) { - m_language = language_from_file_extension(LexicalPath { file_path }.extension()); + m_language = language_from_file_extension(LexicalPath::extension(file_path)); } CodeDocument::CodeDocument(Client* client) diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index 69ee6a536fb..6b181eda5fd 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -169,7 +169,7 @@ static HashMap& man_paths() Core::DirIterator it("/usr/share/man/man2", Core::DirIterator::Flags::SkipDots); while (it.has_next()) { auto path = it.next_full_path(); - auto title = LexicalPath(path).title(); + auto title = LexicalPath::title(path); paths.set(title, path); } } diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 3d6a35143ab..dd86ecd1fa9 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -733,7 +733,7 @@ String HackStudioWidget::get_project_executable_path() const // FIXME: Dumb heuristic ahead! // e.g /my/project => /my/project/project // TODO: Perhaps a Makefile rule for getting the value of $(PROGRAM) would be better? - return String::formatted("{}/{}", m_project->root_path(), LexicalPath(m_project->root_path()).basename()); + return String::formatted("{}/{}", m_project->root_path(), LexicalPath::basename(m_project->root_path())); } void HackStudioWidget::build(TerminalWrapper& wrapper) diff --git a/Userland/DevTools/HackStudio/Project.h b/Userland/DevTools/HackStudio/Project.h index 28c1918977d..88fd68f680b 100644 --- a/Userland/DevTools/HackStudio/Project.h +++ b/Userland/DevTools/HackStudio/Project.h @@ -23,7 +23,7 @@ public: GUI::FileSystemModel& model() { return *m_model; } const GUI::FileSystemModel& model() const { return *m_model; } - String name() const { return LexicalPath(m_root_path).basename(); } + String name() const { return LexicalPath::basename(m_root_path); } String root_path() const { return m_root_path; } NonnullRefPtr get_file(const String& path) const; diff --git a/Userland/DevTools/HackStudio/ProjectTemplate.cpp b/Userland/DevTools/HackStudio/ProjectTemplate.cpp index 77c186af497..12ca28d24f4 100644 --- a/Userland/DevTools/HackStudio/ProjectTemplate.cpp +++ b/Userland/DevTools/HackStudio/ProjectTemplate.cpp @@ -38,7 +38,7 @@ RefPtr ProjectTemplate::load_from_manifest(const String& manife || !config->has_key("HackStudioTemplate", "IconName32x")) return {}; - auto id = LexicalPath(manifest_path).title(); + auto id = LexicalPath::title(manifest_path); auto name = config->read_entry("HackStudioTemplate", "Name"); auto description = config->read_entry("HackStudioTemplate", "Description"); int priority = config->read_num_entry("HackStudioTemplate", "Priority", 0); diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 587fda18983..dacce6f7a66 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -255,7 +255,7 @@ Result, String> Profile::load_from_perfcore_file(const St auto sampled_process = adopt_own(*new Process { .pid = event.pid, .executable = event.executable, - .basename = LexicalPath(event.executable).basename(), + .basename = LexicalPath::basename(event.executable), .start_valid = event.serial, .end_valid = {}, }); @@ -274,7 +274,7 @@ Result, String> Profile::load_from_perfcore_file(const St auto sampled_process = adopt_own(*new Process { .pid = event.pid, .executable = event.executable, - .basename = LexicalPath(event.executable).basename(), + .basename = LexicalPath::basename(event.executable), .start_valid = event.serial, .end_valid = {}, }); @@ -498,7 +498,7 @@ ProfileNode::ProfileNode(Process const& process, const String& object_name, Stri } else { object = object_name; } - m_object_name = LexicalPath(object).basename(); + m_object_name = LexicalPath::basename(object); } } diff --git a/Userland/DevTools/Profiler/TimelineHeader.cpp b/Userland/DevTools/Profiler/TimelineHeader.cpp index e6fa5ba6c09..98d3d8b1a04 100644 --- a/Userland/DevTools/Profiler/TimelineHeader.cpp +++ b/Userland/DevTools/Profiler/TimelineHeader.cpp @@ -26,7 +26,7 @@ TimelineHeader::TimelineHeader(Profile& profile, Process const& process) update_selection(); m_icon = GUI::FileIconProvider::icon_for_executable(m_process.executable).bitmap_for_size(32); - m_text = String::formatted("{} ({})", LexicalPath(m_process.executable).basename(), m_process.pid); + m_text = String::formatted("{} ({})", LexicalPath::basename(m_process.executable), m_process.pid); } TimelineHeader::~TimelineHeader() diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.cpp b/Userland/DevTools/UserspaceEmulator/Emulator.cpp index 239f8e6a2cd..4529bcb1a64 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator.cpp @@ -426,7 +426,7 @@ String Emulator::create_backtrace_line(FlatPtr address) auto source_position = it->value.debug_info->get_source_position(address - region->base()); if (source_position.has_value()) - return String::formatted("=={{{}}}== {:p} [{}]: {} (\e[34;1m{}\e[0m:{})", getpid(), (void*)address, lib_name, symbol, LexicalPath(source_position.value().file_path).basename(), source_position.value().line_number); + return String::formatted("=={{{}}}== {:p} [{}]: {} (\e[34;1m{}\e[0m:{})", getpid(), (void*)address, lib_name, symbol, LexicalPath::basename(source_position.value().file_path), source_position.value().line_number); return line_without_source_info; } @@ -464,7 +464,7 @@ String Emulator::create_instruction_line(FlatPtr address, X86::Instruction insn) if (!source_position.has_value()) return minimal; - return String::formatted("{:p}: {} \e[34;1m{}\e[0m:{}", (void*)address, insn.to_string(address), LexicalPath(source_position.value().file_path).basename(), source_position.value().line_number); + return String::formatted("{:p}: {} \e[34;1m{}\e[0m:{}", (void*)address, insn.to_string(address), LexicalPath::basename(source_position.value().file_path), source_position.value().line_number); } static void emulator_signal_handler(int signum) diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp index aafc1bfc8e1..fc7f6fefa39 100644 --- a/Userland/DevTools/UserspaceEmulator/main.cpp +++ b/Userland/DevTools/UserspaceEmulator/main.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv, char** env) StringBuilder builder; builder.append("(UE) "); - builder.append(LexicalPath(arguments[0]).basename()); + builder.append(LexicalPath::basename(arguments[0])); if (set_process_name(builder.string_view().characters_without_null_termination(), builder.string_view().length()) < 0) { perror("set_process_name"); return 1; diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index d4ab87a7f1e..0a08414396f 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -332,7 +332,7 @@ Result File::copy_file(const String& dst_path, const stru if (errno != EISDIR) return CopyError { OSError(errno), false }; - auto dst_dir_path = String::formatted("{}/{}", dst_path, LexicalPath(source.filename()).basename()); + auto dst_dir_path = String::formatted("{}/{}", dst_path, LexicalPath::basename(source.filename())); dst_fd = creat(dst_dir_path.characters(), 0666); if (dst_fd < 0) return CopyError { OSError(errno), false }; diff --git a/Userland/Libraries/LibCoreDump/Backtrace.cpp b/Userland/Libraries/LibCoreDump/Backtrace.cpp index a20f721666b..e96b396050b 100644 --- a/Userland/Libraries/LibCoreDump/Backtrace.cpp +++ b/Userland/Libraries/LibCoreDump/Backtrace.cpp @@ -139,7 +139,7 @@ String Backtrace::Entry::to_string(bool color) const for (size_t i = 0; i < source_positions.size(); ++i) { auto& position = source_positions[i]; auto fmt = color ? "\033[34;1m{}\033[0m:{}" : "{}:{}"; - builder.appendff(fmt, LexicalPath(position.file_path).basename(), position.line_number); + builder.appendff(fmt, LexicalPath::basename(position.file_path), position.line_number); if (i != source_positions.size() - 1) { builder.append(" => "); } diff --git a/Userland/Libraries/LibDebug/DebugSession.cpp b/Userland/Libraries/LibDebug/DebugSession.cpp index 96aca1d8945..766aad2fffd 100644 --- a/Userland/Libraries/LibDebug/DebugSession.cpp +++ b/Userland/Libraries/LibDebug/DebugSession.cpp @@ -438,7 +438,7 @@ void DebugSession::update_loaded_libs() String lib_name = object_path.value(); if (lib_name.ends_with(".so")) - lib_name = LexicalPath(object_path.value()).basename(); + lib_name = LexicalPath::basename(object_path.value()); // FIXME: DebugInfo currently cannot parse the debug information of libgcc_s.so if (lib_name == "libgcc_s.so") diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp index bafb7029c54..3c7482aba3b 100644 --- a/Userland/Libraries/LibELF/DynamicLinker.cpp +++ b/Userland/Libraries/LibELF/DynamicLinker.cpp @@ -77,7 +77,7 @@ Optional DynamicLinker::lookup_global_symbol( static String get_library_name(String path) { - return LexicalPath(move(path)).basename(); + return LexicalPath::basename(move(path)); } static Result, DlErrorMessage> map_library(const String& filename, int fd) diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index 7ac35eb8510..d4209c89d36 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -222,7 +222,7 @@ Icon FileIconProvider::icon_for_path(const String& path, mode_t mode) if (raw_symlink_target.starts_with('/')) { target_path = raw_symlink_target; } else { - target_path = Core::File::real_path_for(String::formatted("{}/{}", LexicalPath(path).dirname(), raw_symlink_target)); + target_path = Core::File::real_path_for(String::formatted("{}/{}", LexicalPath::dirname(path), raw_symlink_target)); } auto target_icon = icon_for_path(target_path); diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 3ee912cd2b8..71e08653f73 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -653,7 +653,7 @@ void FileSystemModel::set_data(const ModelIndex& index, const Variant& data) { VERIFY(is_editable(index)); Node& node = const_cast(this->node(index)); - auto dirname = LexicalPath(node.full_path()).dirname(); + auto dirname = LexicalPath::dirname(node.full_path()); auto new_full_path = String::formatted("{}/{}", dirname, data.to_string()); int rc = rename(node.full_path().characters(), new_full_path.characters()); if (rc < 0) { diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp index 2ec64d8a705..b1c95bbd002 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp +++ b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) { g_test_argc = argc; g_test_argv = argv; - auto program_name = LexicalPath { argv[0] }.basename(); + auto program_name = LexicalPath::basename(argv[0]); g_program_name = program_name; struct sigaction act; diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index d004a78985f..aadb1e5ebf8 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -1064,7 +1064,7 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) // Then add them to the context menu. // FIXME: Adapt this code when we actually support calling LaunchServer with a specific handler in mind. for (auto& handler : handlers) { - auto af = Desktop::AppFile::get_for_app(LexicalPath(handler).basename()); + auto af = Desktop::AppFile::get_for_app(LexicalPath::basename(handler)); if (!af->is_valid()) continue; auto action = GUI::Action::create(String::formatted("&Open in {}", af->name()), af->icon().bitmap_for_size(16), [this, handler](auto&) { @@ -1084,7 +1084,7 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) // file://courage/home/anon/something -> /home/anon/something auto path = URL(m_context_menu_href).path(); // /home/anon/something -> something - auto name = LexicalPath(path).basename(); + auto name = LexicalPath::basename(path); GUI::Clipboard::the().set_plain_text(name); })); m_context_menu_for_hyperlink->add_separator(); diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 8e6065deb6b..6db5f9b13c4 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -81,7 +81,7 @@ static bool build_image_document(DOM::Document& document, const ByteBuffer& data auto title_element = document.create_element("title"); head_element->append_child(title_element); - auto basename = LexicalPath(document.url().path()).basename(); + auto basename = LexicalPath::basename(document.url().path()); auto title_text = adopt_ref(*new DOM::Text(document, String::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height()))); title_element->append_child(title_text); diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp index 44919a9a5f7..ae05ac45da2 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 c8765c26d6e..96985375b2d 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 { 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 76f0c110948..da618010134 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -198,7 +198,7 @@ NonnullRefPtr 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; }); } diff --git a/Userland/Utilities/basename.cpp b/Userland/Utilities/basename.cpp index ee54a200f8a..4b6031715ec 100644 --- a/Userland/Utilities/basename.cpp +++ b/Userland/Utilities/basename.cpp @@ -24,7 +24,7 @@ int main(int argc, char** argv) args_parser.add_positional_argument(suffix, "Suffix to strip from name", "suffix", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); - auto result = LexicalPath(path).basename(); + auto result = LexicalPath::basename(path); if (!suffix.is_null() && result.length() != suffix.length() && result.ends_with(suffix)) result = result.substring(0, result.length() - suffix.length()); diff --git a/Userland/Utilities/bt.cpp b/Userland/Utilities/bt.cpp index 18d56bdc005..c291894dbc2 100644 --- a/Userland/Utilities/bt.cpp +++ b/Userland/Utilities/bt.cpp @@ -65,7 +65,7 @@ int main(int argc, char** argv) out("\033]8;;{}\033\\", url.serialize()); } - out("\033[34;1m{}:{}\033[0m", LexicalPath(source_position.file_path).basename(), source_position.line_number); + out("\033[34;1m{}:{}\033[0m", LexicalPath::basename(source_position.file_path), source_position.line_number); if (linked) out("\033]8;;\033\\"); diff --git a/Userland/Utilities/cp.cpp b/Userland/Utilities/cp.cpp index 86a08e6877c..3f6803e674f 100644 --- a/Userland/Utilities/cp.cpp +++ b/Userland/Utilities/cp.cpp @@ -36,7 +36,7 @@ int main(int argc, char** argv) for (auto& source : sources) { auto destination_path = destination_is_existing_dir - ? String::formatted("{}/{}", destination, LexicalPath(source).basename()) + ? String::formatted("{}/{}", destination, LexicalPath::basename(source)) : destination; auto result = Core::File::copy_file_or_directory( diff --git a/Userland/Utilities/dirname.cpp b/Userland/Utilities/dirname.cpp index 05edc7d5517..313c532a5a7 100644 --- a/Userland/Utilities/dirname.cpp +++ b/Userland/Utilities/dirname.cpp @@ -14,6 +14,6 @@ int main(int argc, char** argv) args_parser.add_positional_argument(path, "Path", "path"); args_parser.parse(argc, argv); - outln("{}", LexicalPath(path).dirname()); + outln("{}", LexicalPath::dirname(path)); return 0; } diff --git a/Userland/Utilities/du.cpp b/Userland/Utilities/du.cpp index 0034ef97141..eb007193e08 100644 --- a/Userland/Utilities/du.cpp +++ b/Userland/Utilities/du.cpp @@ -151,7 +151,7 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep } } - const auto basename = LexicalPath(path).basename(); + const auto basename = LexicalPath::basename(path); for (const auto& pattern : du_option.excluded_patterns) { if (basename.matches(pattern, CaseSensitivity::CaseSensitive)) return 0; diff --git a/Userland/Utilities/ln.cpp b/Userland/Utilities/ln.cpp index 7525e042c9e..ece88fb9479 100644 --- a/Userland/Utilities/ln.cpp +++ b/Userland/Utilities/ln.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) String path_buffer; if (!path) { - path_buffer = LexicalPath(target).basename(); + path_buffer = LexicalPath::basename(target); path = path_buffer.characters(); } diff --git a/Userland/Utilities/mv.cpp b/Userland/Utilities/mv.cpp index 6962a6a3e75..1e917f69b72 100644 --- a/Userland/Utilities/mv.cpp +++ b/Userland/Utilities/mv.cpp @@ -59,7 +59,7 @@ int main(int argc, char** argv) String combined_new_path; const char* new_path = original_new_path; if (S_ISDIR(st.st_mode)) { - auto old_basename = LexicalPath(old_path).basename(); + auto old_basename = LexicalPath::basename(old_path); combined_new_path = String::formatted("{}/{}", original_new_path, old_basename); new_path = combined_new_path.characters(); } diff --git a/Userland/Utilities/test.cpp b/Userland/Utilities/test.cpp index aea9d67c7b0..a8683484116 100644 --- a/Userland/Utilities/test.cpp +++ b/Userland/Utilities/test.cpp @@ -498,7 +498,7 @@ int main(int argc, char* argv[]) return 126; } - if (LexicalPath { argv[0] }.basename() == "[") { + if (LexicalPath::basename(argv[0]) == "[") { --argc; if (StringView { argv[argc] } != "]") fatal_error("test invoked as '[' requires a closing bracket ']'"); diff --git a/Userland/Utilities/tree.cpp b/Userland/Utilities/tree.cpp index a6a3f2c78be..e31522b2a2c 100644 --- a/Userland/Utilities/tree.cpp +++ b/Userland/Utilities/tree.cpp @@ -36,7 +36,7 @@ static void print_directory_tree(const String& root_path, int depth, const Strin out("{}|-- ", root_indent_string); } - String root_dir_name = LexicalPath(root_path).basename(); + String root_dir_name = LexicalPath::basename(root_path); out("\033[34;1m{}\033[0m\n", root_dir_name); if (depth >= max_depth) {