I have an utf-8 string like this:
=C3=A0=C3=A8=C3=AC=C3=B2=C3=B9
I need to decode the string to latin1. The expected result is:
àèìòù
This is what I tried without success:
utf8.decode(stringData.runes.toList())
I have an utf-8 string like this:
=C3=A0=C3=A8=C3=AC=C3=B2=C3=B9
I need to decode the string to latin1. The expected result is:
àèìòù
This is what I tried without success:
utf8.decode(stringData.runes.toList())
I solved.
Thanks to @lenz comment and the js function found here I solved with this function:
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);
});
}
and with this code:
var output = decodeQuotedPrintable(input);
output = utf8.decode(latin1.encode(input));