2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-28 07:54:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 13:34:26 +00:00
|
|
|
#include <AK/String.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <AK/Vector.h>
|
2018-10-28 07:54:20 +00:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2020-05-26 11:52:44 +00:00
|
|
|
class LexicalPath {
|
2018-10-28 07:54:20 +00:00
|
|
|
public:
|
2021-01-10 23:29:28 +00:00
|
|
|
LexicalPath() = default;
|
2021-04-16 21:44:06 +00:00
|
|
|
explicit LexicalPath(String);
|
2018-10-28 07:54:20 +00:00
|
|
|
|
2018-12-03 00:38:22 +00:00
|
|
|
bool is_valid() const { return m_is_valid; }
|
2020-04-27 12:09:08 +00:00
|
|
|
bool is_absolute() const { return m_is_absolute; }
|
2019-06-07 18:58:12 +00:00
|
|
|
const String& string() const { return m_string; }
|
2018-10-28 07:54:20 +00:00
|
|
|
|
2020-01-07 11:35:45 +00:00
|
|
|
const String& dirname() const { return m_dirname; }
|
2019-06-07 18:58:12 +00:00
|
|
|
const String& basename() const { return m_basename; }
|
2019-07-29 04:45:50 +00:00
|
|
|
const String& title() const { return m_title; }
|
|
|
|
const String& extension() const { return m_extension; }
|
2018-11-18 13:57:41 +00:00
|
|
|
|
2019-03-30 02:27:25 +00:00
|
|
|
const Vector<String>& parts() const { return m_parts; }
|
|
|
|
|
2020-05-26 09:12:18 +00:00
|
|
|
bool has_extension(const StringView&) const;
|
2019-05-26 20:33:30 +00:00
|
|
|
|
2021-04-16 21:44:06 +00:00
|
|
|
static String canonicalized_path(String);
|
|
|
|
static String relative_path(String absolute_path, String const& prefix);
|
2020-05-26 11:52:44 +00:00
|
|
|
|
2018-10-28 07:54:20 +00:00
|
|
|
private:
|
2019-07-15 04:49:28 +00:00
|
|
|
void canonicalize();
|
2018-10-28 07:54:20 +00:00
|
|
|
|
2019-03-30 02:27:25 +00:00
|
|
|
Vector<String> m_parts;
|
2018-10-28 07:54:20 +00:00
|
|
|
String m_string;
|
2020-01-07 11:35:45 +00:00
|
|
|
String m_dirname;
|
2018-11-18 13:57:41 +00:00
|
|
|
String m_basename;
|
2019-07-29 04:45:50 +00:00
|
|
|
String m_title;
|
|
|
|
String m_extension;
|
2018-12-03 00:38:22 +00:00
|
|
|
bool m_is_valid { false };
|
2020-04-27 12:09:08 +00:00
|
|
|
bool m_is_absolute { false };
|
2018-10-28 07:54:20 +00:00
|
|
|
};
|
|
|
|
|
2020-10-08 12:09:38 +00:00
|
|
|
template<>
|
|
|
|
struct Formatter<LexicalPath> : Formatter<StringView> {
|
2020-12-30 11:14:15 +00:00
|
|
|
void format(FormatBuilder& builder, const LexicalPath& value)
|
2020-10-08 12:09:38 +00:00
|
|
|
{
|
2020-12-30 11:14:15 +00:00
|
|
|
Formatter<StringView>::format(builder, value.string());
|
2020-10-08 12:09:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-28 07:54:20 +00:00
|
|
|
};
|
|
|
|
|
2020-05-26 11:52:44 +00:00
|
|
|
using AK::LexicalPath;
|