패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.5.1

charset_converter

기반 플랫폼을 사용하는 문자 집합/인코딩 변환기 - 외부 종속성 없음

AndroidiOSWindowsLinux
30일 다운로드
3.8만
좋아요
65
Pub 점수
160

패키지 설치

flutter pub add charset_converter

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

다양한 문자 인코딩 간에 텍스트를 변환하기 위한 가벼운 플러터 패키지로, 기반 플랫폼의 네이티브 인코딩 지원을 활용합니다. 외부 종속성이 필요 없으며, 안드로이드, iOS, 윈도우, 리눅스 등 다양한 플랫폼에서 효율적이고 신뢰할 수 있는 변환이 가능합니다. 국제화된 콘텐츠를 처리하거나 다양한 파일 형식과 함께 작업하는 애플리케이션에서 레거시 또는 UTF-8이 아닌 텍스트 데이터를 다루는 데 이상적입니다.

사용 사례

  • ISO-8859-1에서 UTF-8로 레거시 텍스트 파일 변환
  • 알 수 없는 인코딩을 가진 웹 스크래핑 출력 처리
  • 앱에서 다국어 사용자 입력 처리
  • 비표준 인코딩으로 구성 파일 읽기

주요 기능

  • 네이티브 플랫폼 인코딩 API를 사용합니다
  • 외부 종속성 없음
  • 크로스 플랫폼 호환성
  • 간단한 동기식 API
  • 일반적인 문자 집합을 지원합니다

적합한 대상

  • 국제 텍스트를 처리하는 앱
  • 데이터 마이그레이션 도구
  • 파일 형식 파서
  • 레거시 시스템 통합

고려 사항

  • 플랫폼 고유의 인코딩 구현에 의존합니다
  • 운영체제에서 지원하는 인코딩에 제한됨
  • 내장된 백업 메커니즘이 없음
  • 복잡한 인코딩 감지에 적합하지 않음

원본 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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트