keepOnlyLetters function
Returns a simple path with only /, numbers and letters
Implementation
String keepOnlyLetters(String path) {
for (var i = 0; i < path.length; i++) {
if (!_isLetterOrSlash(path.codeUnitAt(i))) {
// Rewrite the rest of the string starting at the first dropped char
final buffer = StringBuffer(path.substring(0, i));
for (var j = i + 1; j < path.length; j++) {
final codeUnit = path.codeUnitAt(j);
if (_isLetterOrSlash(codeUnit)) {
buffer.writeCharCode(codeUnit);
}
}
return buffer.toString();
}
}
// Nothing to remove: return the original string without any allocation
return path;
}