搜尋套件、儲存庫與 APP 分類

套件詳情v1.4.0

charcode

ASCII 和常見非 ASCII 字符代碼的常量。對應單個字元編碼點的整數常量。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
405萬
喜歡數
33
Pub 分數
160

安裝套件

flutter pub add charcode

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

charcode 套件提供 ASCII 和常見非 ASCII 字元碼的整數常數,提供便捷的字元碼點存取。它包含像 'a'、'A'、'0' 以及 '@' 和 '€' 等符號的命名常數,讓處理字元編碼時程式碼更具可讀性與可維護性。非常適合需要直接代碼點參考的解析、字串操作及底層文字處理工作。此套件輕量且跨所有主要平台相容。

適用情境

  • 字串解析
  • 字元編碼工作
  • 文字處理工具
  • 低階級 I/O 操作
  • 符號常量定義

主要特色

  • 命名字元代碼常數
  • 支援 ASCII 與常見的 Unicode 字元
  • 輕量且依賴極少
  • 跨平台相容性
  • 透過 pub 實現輕鬆整合
  • 無執行時間開銷

適合對象

  • 使用原始字元代碼的開發人員
  • 解析庫
  • 文字轉換工具
  • 關於字元編碼的教育專案

使用建議

  • 不適用於一般字串處理
  • 限制為預定義的字元集
  • 不支援動態字元查詢
  • 最好與其他文字處理套件結合使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Pub package publisher

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

import "package:charcode/ascii.dart";
// or
import "package:charcode/html_entity.dart";

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.

所屬分類

原始碼儲存庫

使用此套件的專案