Метод parentOf
String parentOf(Удаляет последнюю компонент пути, используя разделитель путей платформы для разделения пути. Не будет удалять корневую компоненту пути Windows, например, "C:\" или "\\server_name\". Игнорирует заключительные разделители путей и не оставляет заключительных разделителей путей.
Исходный код
static String parentOf(String path) {
int rootEnd = -1;
if (Platform.isWindows) {
if (path.startsWith(_absoluteWindowsPathPattern)) {
// Root ends at first / or \ after the first two characters.
rootEnd = path.indexOf(new RegExp(r'[/\\]'), 2);
if (rootEnd == -1) return path;
} else if (path.startsWith('\\') || path.startsWith('/')) {
rootEnd = 0;
}
} else if (path.startsWith('/')) {
rootEnd = 0;
}
// Ignore trailing slashes.
// All non-trivial cases have separators between two non-separators.
int pos = path.lastIndexOf(_parentRegExp);
if (pos > rootEnd) {
return path.substring(0, pos + 1);
} else if (rootEnd > -1) {
return path.substring(0, rootEnd + 1);
} else {
return '.';
}
}
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-io/FileSystemEntity/parentOf.html