summaryrefslogtreecommitdiff
path: root/AK/FileSystemPath.cpp
diff options
context:
space:
mode:
authorConrad Pankoff <deoxxa@fknsrs.biz>2020-01-07 22:35:45 +1100
committerAndreas Kling <awesomekling@gmail.com>2020-01-07 12:36:30 +0100
commitc7fd39f3b1029877279cfe8a59a4e2df01488eaf (patch)
tree3f7c5968ea685084ea06df91e74cb8dc62f791c4 /AK/FileSystemPath.cpp
parent3f3169c225059146ad16495ed3f77c515c9b50e6 (diff)
downloadserenity-c7fd39f3b1029877279cfe8a59a4e2df01488eaf.zip
AK: Add dirname() to FileSystemPath
Diffstat (limited to 'AK/FileSystemPath.cpp')
-rw-r--r--AK/FileSystemPath.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp
index 8c95da826d..753c8d6603 100644
--- a/AK/FileSystemPath.cpp
+++ b/AK/FileSystemPath.cpp
@@ -45,10 +45,19 @@ void FileSystemPath::canonicalize()
}
}
if (canonical_parts.is_empty()) {
- m_string = m_basename = "/";
+ m_string = m_basename = m_dirname = "/";
return;
}
+ StringBuilder dirname_builder(approximate_canonical_length);
+ for (int i = 0; i < canonical_parts.size() - 1; ++i) {
+ auto& canonical_part = canonical_parts[i];
+ if (is_absolute_path || i != 0)
+ dirname_builder.append('/');
+ dirname_builder.append(canonical_part);
+ }
+ m_dirname = dirname_builder.to_string();
+
m_basename = canonical_parts.last();
auto name_parts = m_basename.split('.');
m_title = name_parts[0];