trimAround method
String
trimAround(
- dynamic characters, {
- bool trimStart = true,
- bool trimEnd = true,
- bool trimWhitespace = true,
})
Implementation
String trimAround(dynamic characters,
{bool trimStart = true,
bool trimEnd = true,
bool trimWhitespace = true}) {
final target = this;
var manipulated = target;
if (trimWhitespace) {
manipulated = manipulated.trim();
}
final chars = characters is List<String> ? characters : ["$characters"];
int i = 0;
while (true && i++ < 30) {
bool done = true;
for (final c in chars) {
if (trimEnd && manipulated.endsWith(c)) {
manipulated = manipulated.substring(0, manipulated.length - c.length);
done = false;
}
if (trimStart && manipulated.startsWith(c)) {
manipulated = manipulated.substring(1);
done = false;
}
}
if (done) break;
}
return manipulated;
}