charcode 패키지는 ASCII 및 일반적인 비-ASCII 문자 코드에 대한 정수 상수를 제공하여 문자 코드 포인트에 쉽게 접근할 수 있도록 합니다. 'a', 'A', '0' 및 '@', '€'와 같은 기호에 대한 이름이 지정된 상수를 포함하여 문자 인코딩 작업 시 가독성과 유지보수가 쉬운 코드를 가능하게 합니다. 직접 코드 포인트 참조가 필요한 파싱, 문자열 조작 및 저수준 텍스트 처리 작업에 적합합니다. 이 패키지는 가볍고 모든 주요 플랫폼과 호환됩니다.
사용 사례
문자열 파싱
문자 인코딩 작업
텍스트 처리 유틸리티
저수준 I/O 작업
기호 상수 정의
주요 기능
이름 붙은 문자 코드 상수
ASCII 및 일반적인 유니코드 문자 지원
경량이며 최소한의 종속성
크로스 플랫폼 호환성
pub를 통한 간편한 통합
런타임 오버헤드 없음
적합한 대상
원시 문자 코드를 사용하는 개발자
파싱 라이브러리
텍스트 변환 도구
문자 인코딩에 관한 교육 프로젝트
고려 사항
일반적인 문자열 처리를 위한 것이 아님
사전 정의된 문자 세트로 제한
동적 문자 검색을 지원하지 않습니다
다른 텍스트 처리 패키지와 함께 사용하는 것이 가장 좋습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Character code constants
This package can generate constant symbolic names for character codes.
The constants can used when working directly with characters as integers,
to make the code more readable: if (firstChar == $A) ... vs
if (firstChar == 0x41 /*A*/).
Pre-defined constants
The package also provides a set of pre-defined constants covering all
ASCII characters and all HTML entities.
Those constants are intended for use while developing
a new package or application. When development is done,
it's recommended that you generate a file for yourself,
containing only the constants that you actually use,
and include that in your project.
Usage
To generate a set of constants, run the charcode application with a list
of the characters you want to reference.
Example:
dart run charcode -o lib/src/charcodes.dart "09.e\-ftn{}[],:"
Run dart run charcode --help to see other options.
After switching to the generated constants file, you can, and should,
remove your dependency on this package, or keep it as a dev-dependency
in case you want to generate the file again.
To use the pre-defined constants, import either the ASCII or the HTML library
or import both libraries using the combined charcode.dart library:
import"package:charcode/charcode.dart";
(Importing both libraries directly causes some conflicting names
to be inaccessible.)
Naming
The character names are preceded by a $ to avoid conflicting with other
variables, due to their short and common names (for example "$i").
Characters that are valid in a Dart identifier directly follow the $.
Examples: $_, $a, $B and $3. Other characters are given symbolic names.
The names of letters are lower-case for lower-case letters ($sigma for σ),
and mixed- or upper-case for upper-case letters ($Sigma for Σ).
The names of symbols and punctuation are all lower-case or camelCase,
and omit suffixes like "sign", "symbol" and "mark".
Examples: $plus, $exclamation, $tilde, $doubleQuote.
The ascii.dart library defines a symbolic name for each ASCII character.
Some characters have more than one name. For example the common name $tab
and the official abbreviation $ht for the horizontal tab.
The html_entity.dart library defines a constant for each HTML 4.01 character
entity using their standard entity abbreviation, including case.
Examples: $nbsp for &nbps;, $aring for the lower-case å
and $Aring for the upper-case Å.
The HTML entities include all characters in the Latin-1 code page, Greek
letters and some mathematical symbols.
The charcode.dart library exports both ascii.dart and
html_entity.dart. Where both libraries define the same name,
the HTML entity name is preferred.
Rationale
The Dart language doesn't have character literals.
If that ever changes, this package will become irrelevant.
Until then, this package can be used for the most common characters.
See request for character literals.