Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string from ISO-8859-2 to UTF-8 in the Dart language

Tags:

dart

I would like to convert a string from the ISO-8859-2 character set to the UTF-8 character set, but I can't find any solution in the Dart language. Is it possible to do it?

like image 710
Adam Bernau Avatar asked Jan 15 '14 16:01

Adam Bernau


People also ask

Is ISO 8859 the same as UTF-8?

UTF-8 is a multibyte encoding that can represent any Unicode character. ISO 8859-1 is a single-byte encoding that can represent the first 256 Unicode characters. Both encode ASCII exactly the same way.

What is UTF-8 flutter?

UTF-8. A Utf8Codec encodes strings to UTF-8 code units (bytes) and decodes UTF-8 code units to strings. The utf8 is the default implementation of Utf8Codec. Example: var encoded = utf8.

What is dart convert?

dart:convert library Null safety. Encoders and decoders for converting between different data representations, including JSON and UTF-8. In addition to converters for common data representations, this library provides support for implementing converters in a way which makes them easy to chain and to use with streams.

How do you convert string to int in darts?

A string can be cast to an integer using the int. parse() method in Dart. The method takes a string as an argument and converts it into an integer.


1 Answers

There's no built-in converter for ISO-8859-2 in dart:convert. So you have to implement your own codec.

You can look at the code of Latin1Codec to implement a Latin2Codec. Once ready you will be able to do :

import 'dart:convert';

final LATIN2 = new Latin2Codec();

main() {
  List<int> bytesForIso_8859_2 = ...;
  List<int> bytesForUTF8 = LATIN2.fuse(UTF8).encode(bytesForIso_8859_2);
}
like image 136
Alexandre Ardhuin Avatar answered Oct 13 '22 18:10

Alexandre Ardhuin