AK: Add argument to LexicalPath::basename to strip the extension

This commit is contained in:
Andrew Kaster 2023-07-28 10:48:17 -06:00 committed by Andrew Kaster
parent cc3e179b23
commit f5e8bba092
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00

View file

@ -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)