stringNub function

String stringNub(
  1. String s,
  2. String? charactersToNub
)

Remove duplicate characters.

Implementation

String stringNub(String s, String? charactersToNub) {
  if (charactersToNub != null && charactersToNub.isEmpty) {
    return s;
  }
  List<int> copy = s.codeUnits;
  List<int> chars = charactersToNub != null ? charactersToNub.codeUnits : [];
  if (chars.isEmpty) {
    return String.fromCharCodes(s.codeUnits.toSet().toList());
  } else {
    return String.fromCharCodes(listNub(copy, chars));
  }
}