rootPrefix method Null safety
- String path
Returns the root of path
if it's absolute, or an empty string if it's
relative.
// Unix
context.rootPrefix('path/to/foo'); // -> ''
context.rootPrefix('/path/to/foo'); // -> '/'
// Windows
context.rootPrefix(r'path\to\foo'); // -> ''
context.rootPrefix(r'C:\path\to\foo'); // -> r'C:\'
context.rootPrefix(r'\\server\share\a\b'); // -> r'\\server\share'
// URL
context.rootPrefix('path/to/foo'); // -> ''
context.rootPrefix('https://dart.dev/path/to/foo');
// -> 'https://dart.dev'
Implementation
String rootPrefix(String path) => path.substring(0, style.rootLength(path));