removeInvalidUnicode method

  1. @useResult
String removeInvalidUnicode()

Returns a new string with all invalid Unicode replacement characters removed.

Implementation

@useResult
String removeInvalidUnicode() {
  if (isEmpty) {
    return this;
  }

  final StringBuffer buffer = StringBuffer();
  for (int r in runes.where((int e) => e != _invalidUnicodeReplacementRuneCode)) {
    buffer.write(String.fromCharCode(r));
  }

  return buffer.toString();
}