splitPath static method
Implementation
static List<String> splitPath(String path) {
List<String> fragments = [];
StringBuffer buffer = StringBuffer();
bool isEscaped = false;
for (var i = 0; i < path.length; i++) {
var char = path[i];
// Add the escaped char to the buffer and reset the escape flag
if (isEscaped) {
buffer.write(char);
isEscaped = false;
continue;
}
// Begin the next fragment
if (char == "/") {
fragments.add(buffer.toString());
buffer.clear();
continue;
}
// Escape the next char if char equals '\'
if (char == "\\") {
isEscaped = true;
continue;
}
buffer.write(char);
}
// Add last fragment if buffer is not empty
if (buffer.isNotEmpty) fragments.add(buffer.toString());
return fragments;
}