从utf8到latin1

时间:2020-09-05 18:19:32

标签: dart utf-8 decode

我有一个这样的utf-8字符串:

=C3=A0=C3=A8=C3=AC=C3=B2=C3=B9

我需要将字符串解码为latin1。预期结果是:

àèìòù

这是我尝试失败的尝试:

utf8.decode(stringData.runes.toList())

1 个答案:

答案 0 :(得分:0)

我解决了。
感谢@lenz注释和发现的here js函数,我使用以下函数解决了这个问题:

 Audit.Core.Configuration.Setup()
  .UseEntityFramework(_ => _
  .AuditTypeMapper(t => typeof(AuditLog))
  .AuditEntityAction<AuditLog>((ev, entry, entity) =>
   {
      var x = ev.CustomFields["User"];
      ...
   })
   .IgnoreMatchedProperties());

,并带有以下代码:

String decodeQuotedPrintable(String input) {
  return input
      // https://tools.ietf.org/html/rfc2045#section-6.7, rule 3:
      // “Therefore, when decoding a `Quoted-Printable` body, any trailing white
      // space on a line must be deleted, as it will necessarily have been added
      // by intermediate transport agents.”
      .replaceAll(RegExp(r'[\t\x20]$', multiLine: true), '')
      // Remove hard line breaks preceded by `=`. Proper `Quoted-Printable`-
      // encoded data only contains CRLF line endings, but for compatibility
      // reasons we support separate CR and LF too.
      .replaceAll(RegExp(r'=(?:\r\n?|\n|$)', multiLine: true), '')
      // Decode escape sequences of the form `=XX` where `XX` is any
      // combination of two hexidecimal digits. For optimal compatibility,
      // lowercase hexadecimal digits are supported as well. See
      // https://tools.ietf.org/html/rfc2045#section-6.7, note 1.
      .replaceAllMapped(RegExp(r'=([a-fA-F\d]{2})'), (match) {
        var codePoint = int.parse(match[1], radix: 16);
        return String.fromCharCode(codePoint);
      });
}
相关问题