simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// 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('/');
|
||||
Reference in New Issue
Block a user