parseArchivePathCandidates function
Splits an archive.ext:inner/path reference into every plausible
{archivePath, subPath} pair, longest archive prefix first. A path may
contain more than one archive extension, so each candidate is a guess at
where the archive ends and the member portion begins (omp's
parseArchivePathCandidates).
Implementation
List<ArchivePathCandidate> parseArchivePathCandidates(String filePath) {
final normalized = filePath.replaceAll('\\', '/');
final seen = <String>{};
final candidates = <ArchivePathCandidate>[];
for (final match in _archivePathPattern.allMatches(normalized)) {
final end = match.end;
final archivePath = filePath.substring(0, end);
final subPath = normalized.substring(end).replaceFirst(RegExp('^:+'), '');
final key = '$archivePath\x00$subPath';
if (!seen.add(key)) continue;
candidates.add(ArchivePathCandidate(archivePath, subPath));
}
candidates.sort(
(a, b) => b.archivePath.length.compareTo(a.archivePath.length),
);
return candidates;
}