パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.5.1

charset_converter

下位プラットフォームを使用する文字セット/エンコーディング変換ツール - 外部依存なし

AndroidiOSWindowsLinux
30日間ダウンロード
3.8万
いいね数
65
Pub ポイント
160

パッケージをインストール

flutter pub add charset_converter

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

異なる文字エンコーディング間でテキストを変換するための軽量なFlutterパッケージであり、下位プラットフォームのネイティブエンコーディングサポートを利用しています。外部依存関係を必要とせず、Android、iOS、Windows、Linuxなどあらゆるプラットフォームで効率的かつ信頼性の高い変換を実現します。国際化されたコンテンツを処理するアプリケーションや、さまざまなファイル形式と連携するアプリケーションにおいて、レガシーやUTF-8以外のテキストデータを扱うのに最適です。

用途

  • ISO-8859-1 から UTF-8 へのレガシーテキストファイルの変換
  • 未知のエンコーディングを持つウェブスクレイピング出力の処理
  • アプリケーションでの多言語ユーザー入力の処理
  • 非標準エンコーディングで設定ファイルを読み込む

主な機能

  • ネイティブプラットフォームのエンコーディングAPIを使用
  • 外部の依存関係なし
  • クロスプラットフォーム互換性
  • シンプルな同期 API
  • 一般的な文字セットをサポートしています

適している対象

  • 国際テキストを処理するアプリ
  • データ移行ツール
  • ファイル形式パーサー
  • レガシーシステム統合

注意事項

  • プラットフォーム固有のエンコーディング実装に依存しています
  • OSがサポートするエンコーディングに制限される
  • 組み込みのフォールバックメカニズムなし
  • 複雑なエンコーディング検出には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Charset converter

pub package Checks status

Encode and decode charsets using platform built-in converter. This saves app package size as you don't need any external charset maps or whole libraries like iconv. This package doesn't even contain any Dart dependencies. However this comes with the dependency on the platform.

This package was originally made to help deal with this StackOverflow question and Dart's lack of support for many specific charset like GBK, Big5, Windows-125X or ISO-8859-XX.

Usage

Checkout these snippets or full example.

Encoding
Uint8List encoded = await CharsetConverter.encode("windows1250", "Polish has óśćł");
Decoding
String decoded = await CharsetConverter.decode("windows1250",
    Uint8List.fromList([0x43, 0x7A, 0x65, 0x9C, 0xE6])); // Hello (Cześć) in Polish
Getting list of available charsets

Helpful if you don't know exact name of the charset.

List<String> charsets = await CharsetConverter.availableCharsets();

Warning: Please note that even if charset is not present on the list, it still might work. This is because the function is not returning the full list of aliases, this is presented in the example of iOS - TIS620 does not appear on the list, but ISO 8859-11, which is actually an alias of TIS620 does. To check if charset is available use CharsetConverter.checkAvailability.

Please also note that names are platform specific and may be different.

Checking availability of charset
bool isAvailable = await CharsetConverter.checkAvailability("EUC-KR");

Preview of what encoding you may find

This can be helpful if you are not sure what you are looking for.

How does it work?

Android comes with Java runtime, which has a built-in Charset class which has convenient encode and decode methods. All it's left to do is use channels to pass the data.

iOS can also work with charsets with CoreFoundation CFString functions fe. CFStringConvertIANACharSetNameToEncoding. We can also easily encode and decode Strings with init and data. It is a little bit cumbersome since we have to convert the values and use ported C API.

Windows can use MultiByteToWideChar and WideCharToMultiByte from Win32.

Linux can use libIconv in GLib. Since Flutter for Linux use GTK, it is pretty suitable. However, it accept a NUL terminated UTF-8 string (like C string end with\0), so in Dart side, String will be dealt by transferring into Uint8List, and add 0 at the end.

Contributing

Feel free to create issues, fix bugs, add new functionalities even if you are not sure about. Everyone is welcome!

See also

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト