27 lines
949 B
Dart
27 lines
949 B
Dart
// Paths relative to the WebDAV root, as used by `CacheableFile.path`: no
|
|
// leading slash, folders end with '/', the root folder is ''.
|
|
|
|
final RegExp _edgeSlashes = RegExp(r'^/+|/+$');
|
|
|
|
List<String> webdavSegmentsOf(String path) {
|
|
final stripped = path.replaceAll(_edgeSlashes, '');
|
|
return stripped.isEmpty ? [] : stripped.split('/');
|
|
}
|
|
|
|
List<String> webdavParentSegmentsOf(String path) {
|
|
final segments = webdavSegmentsOf(path);
|
|
if (segments.isNotEmpty) segments.removeLast();
|
|
return segments;
|
|
}
|
|
|
|
String webdavFolderPath(List<String> segments) =>
|
|
segments.isEmpty ? '' : '${segments.join('/')}/';
|
|
|
|
String webdavJoin(String folder, String name, {required bool isDirectory}) =>
|
|
isDirectory ? '$folder$name/' : '$folder$name';
|
|
|
|
/// Folder key used by `ListFilesCache` and `FilesBloc`: no leading or
|
|
/// trailing slash, root is '/'.
|
|
String listFilesCacheKey(List<String> segments) =>
|
|
segments.isEmpty ? '/' : segments.join('/');
|