decodeUtf8HmDu function Null safety

String? decodeUtf8HmDu(
  1. String input
)

Convert specially UTF-8 encoded non ASCII characters into real UTF-8. hmdu is a program which encodes "more byte" UTF-8 characters into the form "^

Implementation

String? decodeUtf8HmDu(String input) {
  String? rc;
  _regExpUtfPattern ??= RegExp(r'\^(([0-9A-F][0-9A-F]){2,4})#');
  var it = _regExpUtfPattern?.allMatches(input).iterator;
  if (it != null) {
    while (it.moveNext()) {
      rc ??= input;
      final hex = it.current.group(1);
      var replacement;
      switch (hex) {
        case 'C384':
          replacement = 'Ä';
          break;
        case 'C396':
          replacement = 'Ö';
          break;
        case 'C39C':
          replacement = 'Ü';
          break;
        case 'C3A4':
          replacement = 'ä';
          break;
        case 'C3B6':
          replacement = 'ö';
          break;
        case 'C3BC':
          replacement = 'ü';
          break;
        case 'C39F':
          replacement = 'ß';
          break;
        case 'E282AC':
          replacement = '€';
          break;
        default:
          break;
      }
      if (replacement != null) {
        rc = rc.replaceAll(it.current.group(0)!, replacement);
      }
    }
  }
  return rc ?? input;
}