summaryrefslogtreecommitdiff
path: root/services/incremental/path.cpp
diff options
context:
space:
mode:
authorSteven Laver <lavers@google.com>2020-02-13 20:29:13 -0800
committerSteven Laver <lavers@google.com>2020-02-13 20:29:13 -0800
commitd28a4f6b38dbab44128b4319f665dd65c3e4ec2c (patch)
tree680912fe833379242ee026450323ed4f34a6c64b /services/incremental/path.cpp
parent029ad4fa703b5dcb74e8c4c272617464a9ba5fc8 (diff)
parent852c9950280d93875c529e4cae8396d94176f66e (diff)
Merge RP1A.200204.001
Change-Id: I1e6c199dbee77379f84675965391c839eae04961
Diffstat (limited to 'services/incremental/path.cpp')
-rw-r--r--services/incremental/path.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/services/incremental/path.cpp b/services/incremental/path.cpp
index c529d61abd15..0d86f2a984d6 100644
--- a/services/incremental/path.cpp
+++ b/services/incremental/path.cpp
@@ -44,16 +44,45 @@ bool PathLess::operator()(std::string_view l, std::string_view r) const {
PathCharsLess());
}
+static void preparePathComponent(std::string_view path, bool trimFront) {
+ if (trimFront) {
+ while (!path.empty() && path.front() == '/') {
+ path.remove_prefix(1);
+ }
+ }
+ while (!path.empty() && path.back() == '/') {
+ path.remove_suffix(1);
+ }
+}
+
void details::append_next_path(std::string& target, std::string_view path) {
+ preparePathComponent(path, true);
if (path.empty()) {
return;
}
- if (!target.empty()) {
+ if (!target.empty() && !target.ends_with('/')) {
target.push_back('/');
}
target += path;
}
+std::string_view relativize(std::string_view parent, std::string_view nested) {
+ if (!nested.starts_with(parent)) {
+ return nested;
+ }
+ if (nested.size() == parent.size()) {
+ return {};
+ }
+ if (nested[parent.size()] != '/') {
+ return nested;
+ }
+ auto relative = nested.substr(parent.size());
+ while (relative.front() == '/') {
+ relative.remove_prefix(1);
+ }
+ return relative;
+}
+
bool isAbsolute(std::string_view path) {
return !path.empty() && path[0] == '/';
}