// https://wicg.github.io/entries-api/#resolve-a-relative-path static String resolveRelativeVirtualPath(StringView baseVirtualPath, StringView relativeVirtualPath) { ASSERT(baseVirtualPath[0] == '/'); if (!relativeVirtualPath.isEmpty() && relativeVirtualPath[0] == '/') return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath("/", relativeVirtualPath.substring(1)); Vector<StringView> virtualPathSegments; for (auto segment : baseVirtualPath.split('/')) virtualPathSegments.append(segment); for (auto segment : relativeVirtualPath.split('/')) { ASSERT(!segment.isEmpty()); if (segment == ".") continue; if (segment == "..") { if (!virtualPathSegments.isEmpty()) virtualPathSegments.removeLast(); continue; } virtualPathSegments.append(segment); } if (virtualPathSegments.isEmpty()) return "/"_s; StringBuilder builder; for (auto& segment : virtualPathSegments) { builder.append('/'); builder.append(segment); } return builder.toString(); }
static bool isZeroOrMorePathSegmentsSeparatedBySlashes(StringView string) { auto segments = string.split('/'); for (auto segment : segments) { if (!isValidPathSegment(segment)) return false; } return true; }
// https://wicg.github.io/entries-api/#evaluate-a-path String DOMFileSystem::evaluatePath(StringView virtualPath) { ASSERT(virtualPath[0] == '/'); Vector<StringView> resolvedComponents; for (auto component : virtualPath.split('/')) { if (component == ".") continue; if (component == "..") { if (!resolvedComponents.isEmpty()) resolvedComponents.removeLast(); continue; } resolvedComponents.append(component); } return FileSystem::pathByAppendingComponents(m_rootPath, resolvedComponents); }