mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-04 09:14:21 +03:00
AK: Add FileSystemPath::is_absolute()
This commit is contained in:
parent
6fd7966d81
commit
cd81aa41f0
Notes:
sideshowbarker
2024-07-19 07:14:38 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/cd81aa41f0d Pull-request: https://github.com/SerenityOS/serenity/pull/1985
@ -45,10 +45,10 @@ void FileSystemPath::canonicalize()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_absolute_path = m_string[0] == '/';
|
m_is_absolute = m_string[0] == '/';
|
||||||
auto parts = m_string.split_view('/');
|
auto parts = m_string.split_view('/');
|
||||||
|
|
||||||
if (!is_absolute_path)
|
if (!m_is_absolute)
|
||||||
parts.prepend(".");
|
parts.prepend(".");
|
||||||
|
|
||||||
size_t approximate_canonical_length = 0;
|
size_t approximate_canonical_length = 0;
|
||||||
@ -56,7 +56,7 @@ void FileSystemPath::canonicalize()
|
|||||||
|
|
||||||
for (size_t i = 0; i < parts.size(); ++i) {
|
for (size_t i = 0; i < parts.size(); ++i) {
|
||||||
auto& part = parts[i];
|
auto& part = parts[i];
|
||||||
if (is_absolute_path || i != 0) {
|
if (m_is_absolute || i != 0) {
|
||||||
if (part == ".")
|
if (part == ".")
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ void FileSystemPath::canonicalize()
|
|||||||
StringBuilder dirname_builder(approximate_canonical_length);
|
StringBuilder dirname_builder(approximate_canonical_length);
|
||||||
for (size_t i = 0; i < canonical_parts.size() - 1; ++i) {
|
for (size_t i = 0; i < canonical_parts.size() - 1; ++i) {
|
||||||
auto& canonical_part = canonical_parts[i];
|
auto& canonical_part = canonical_parts[i];
|
||||||
if (is_absolute_path || i != 0)
|
if (m_is_absolute || i != 0)
|
||||||
dirname_builder.append('/');
|
dirname_builder.append('/');
|
||||||
dirname_builder.append(canonical_part);
|
dirname_builder.append(canonical_part);
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ void FileSystemPath::canonicalize()
|
|||||||
StringBuilder builder(approximate_canonical_length);
|
StringBuilder builder(approximate_canonical_length);
|
||||||
for (size_t i = 0; i < canonical_parts.size(); ++i) {
|
for (size_t i = 0; i < canonical_parts.size(); ++i) {
|
||||||
auto& canonical_part = canonical_parts[i];
|
auto& canonical_part = canonical_parts[i];
|
||||||
if (is_absolute_path || i != 0)
|
if (m_is_absolute || i != 0)
|
||||||
builder.append('/');
|
builder.append('/');
|
||||||
builder.append(canonical_part);
|
builder.append(canonical_part);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
explicit FileSystemPath(const StringView&);
|
explicit FileSystemPath(const StringView&);
|
||||||
|
|
||||||
bool is_valid() const { return m_is_valid; }
|
bool is_valid() const { return m_is_valid; }
|
||||||
|
bool is_absolute() const { return m_is_absolute; }
|
||||||
const String& string() const { return m_string; }
|
const String& string() const { return m_string; }
|
||||||
|
|
||||||
const String& dirname() const { return m_dirname; }
|
const String& dirname() const { return m_dirname; }
|
||||||
@ -58,6 +59,7 @@ private:
|
|||||||
String m_title;
|
String m_title;
|
||||||
String m_extension;
|
String m_extension;
|
||||||
bool m_is_valid { false };
|
bool m_is_valid { false };
|
||||||
|
bool m_is_absolute { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
String canonicalized_path(const StringView&);
|
String canonicalized_path(const StringView&);
|
||||||
|
Loading…
Reference in New Issue
Block a user