trim function

String? trim(
  1. String? target,
  2. List<String>? chars, {
  3. bool trimWhitespace = true,
})

Implementation

String? trim(String? target, List<String>? chars,
    {bool trimWhitespace = true}) {
  if (target == null) {
    return null;
  }
  var manipulated = target;
  if (trimWhitespace) {
    manipulated = manipulated.trim();
  }
  chars?.forEach((c) {
    if (manipulated.endsWith(c)) {
      manipulated = manipulated.substring(0, manipulated.length - c.length);
    }
    if (manipulated.startsWith(c)) {
      manipulated = manipulated.substring(1);
    }
  });
  return manipulated;
}