From ae047649db575eb76274b8475eadfaee7bffc674 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 May 2020 23:56:35 +0200 Subject: [PATCH] AK: Add URL::basename() --- AK/URL.cpp | 7 +++++++ AK/URL.h | 1 + 2 files changed, 8 insertions(+) diff --git a/AK/URL.cpp b/AK/URL.cpp index bf8b70045d..1b063bb5e7 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -366,4 +366,11 @@ URL URL::create_with_url_or_path(const String& url_or_path) return URL::create_with_file_protocol(path); } +String URL::basename() const +{ + if (!m_valid) + return {}; + return FileSystemPath(m_path).basename(); +} + } diff --git a/AK/URL.h b/AK/URL.h index 4c47f0368e..bb5c320335 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -61,6 +61,7 @@ public: void set_fragment(const String& fragment); void set_port(u16 port) { m_port = port; } + String basename() const; String to_string() const; URL complete_url(const String&) const;