mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 09:20:28 +03:00
AK: Add argument to LexicalPath::basename to strip the extension
This commit is contained in:
parent
cc3e179b23
commit
f5e8bba092
Notes:
sideshowbarker
2024-07-17 21:26:19 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/f5e8bba092 Pull-request: https://github.com/SerenityOS/serenity/pull/20244 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/nico ✅ Reviewed-by: https://github.com/shannonbooth
@ -19,13 +19,18 @@ namespace AK {
|
||||
|
||||
class LexicalPath {
|
||||
public:
|
||||
enum StripExtension {
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
explicit LexicalPath(DeprecatedString);
|
||||
|
||||
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
|
||||
DeprecatedString const& string() const { return m_string; }
|
||||
|
||||
StringView dirname() const { return m_dirname; }
|
||||
StringView basename() const { return m_basename; }
|
||||
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_basename.substring_view(0, m_basename.length() - m_extension.length() - 1); }
|
||||
StringView title() const { return m_title; }
|
||||
StringView extension() const { return m_extension; }
|
||||
|
||||
@ -59,10 +64,10 @@ public:
|
||||
return lexical_path.dirname();
|
||||
}
|
||||
|
||||
[[nodiscard]] static DeprecatedString basename(DeprecatedString path)
|
||||
[[nodiscard]] static DeprecatedString basename(DeprecatedString path, StripExtension s = StripExtension::No)
|
||||
{
|
||||
auto lexical_path = LexicalPath(move(path));
|
||||
return lexical_path.basename();
|
||||
return lexical_path.basename(s);
|
||||
}
|
||||
|
||||
[[nodiscard]] static DeprecatedString title(DeprecatedString path)
|
||||
|
Loading…
Reference in New Issue
Block a user