搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目