mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
9b8f35259c
commit
fc6d051dfd
Notes:
sideshowbarker
2024-07-18 11:13:39 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/fc6d051dfdd Pull-request: https://github.com/SerenityOS/serenity/pull/8320 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
43 changed files with 80 additions and 56 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -91,7 +91,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
|
|||
if (!custody_or_error.is_error()) {
|
||||
new_unveiled_path = custody_or_error.value()->absolute_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?
|
||||
|
|
|
@ -204,7 +204,7 @@ int main(int argc, char** argv)
|
|||
auto& icon_image_widget = *widget.find_descendant_of_type_named<GUI::ImageWidget>("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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ void delete_paths(const Vector<String>& 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());
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ void do_paste(const String& target_directory, GUI::Window* window)
|
|||
void do_create_link(const Vector<String>& 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<Core::ConfigFile> 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<Core::ConfigFile> 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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -300,7 +300,7 @@ void SoundPlayerWidgetAdvancedView::try_fill_missing_info(Vector<M3UEntry>& 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();
|
||||
|
|
|
@ -300,7 +300,7 @@ Result<void, String> 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; };
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -252,7 +252,7 @@ Result<NonnullRefPtrVector<Sheet>, 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; };
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -169,7 +169,7 @@ static HashMap<String, String>& 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<ProjectFile> get_file(const String& path) const;
|
||||
|
|
|
@ -38,7 +38,7 @@ RefPtr<ProjectTemplate> 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);
|
||||
|
|
|
@ -255,7 +255,7 @@ Result<NonnullOwnPtr<Profile>, 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<NonnullOwnPtr<Profile>, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -332,7 +332,7 @@ Result<void, File::CopyError> 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 };
|
||||
|
|
|
@ -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(" => ");
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -77,7 +77,7 @@ Optional<DynamicObject::SymbolLookupResult> DynamicLinker::lookup_global_symbol(
|
|||
|
||||
static String get_library_name(String path)
|
||||
{
|
||||
return LexicalPath(move(path)).basename();
|
||||
return LexicalPath::basename(move(path));
|
||||
}
|
||||
|
||||
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const String& filename, int fd)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -653,7 +653,7 @@ void FileSystemModel::set_data(const ModelIndex& index, const Variant& data)
|
|||
{
|
||||
VERIFY(is_editable(index));
|
||||
Node& node = const_cast<Node&>(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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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; });
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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\\");
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 ']'");
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue