mirror of
https://github.com/nini22P/iris.git
synced 2026-05-09 06:59:38 +08:00
36 lines
793 B
Dart
36 lines
793 B
Dart
import 'package:iris/utils/logger.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
List<String> pathConv(String path) {
|
|
try {
|
|
String normalizedPath = p.normalize(path.trim());
|
|
|
|
if (normalizedPath.isEmpty || normalizedPath == '.') {
|
|
return [];
|
|
}
|
|
|
|
if (normalizedPath == '/' || normalizedPath == '\\') {
|
|
return ['/'];
|
|
}
|
|
|
|
final List<String> result = normalizedPath
|
|
.replaceAll('\\', '/')
|
|
.split('/')
|
|
.where((element) => element.isNotEmpty)
|
|
.toList();
|
|
|
|
if (path.startsWith('\\\\')) {
|
|
return ['\\\\${result[0]}', ...result.sublist(1)];
|
|
}
|
|
|
|
if (path.startsWith('/')) {
|
|
return ['/', ...result];
|
|
}
|
|
|
|
return result;
|
|
} on FormatException catch (e) {
|
|
logger("Error decoding: $e");
|
|
return [];
|
|
}
|
|
}
|