Add camelCase constant name alternatives for snake_case names.
Switch to `package:lints`.
Internal tweaks.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b887dee..cf447ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 1.3.0
+
+* Add camelCase constant names as alternatives for current snake_case constants.
+ Example `$doubleQuote` as alternative to `$double_quote`.
+* Internal tweaks to flag parsing.
+* Switch to using `package:lints`.
+
## 1.2.0
* Stable release for null safety.
diff --git a/README.md b/README.md
index a6951f0..23be3f0 100644
--- a/README.md
+++ b/README.md
@@ -38,14 +38,14 @@
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 horisontal 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
+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
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 007066a..6d1ff7a 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -2,9 +2,4 @@
# for details. All rights reserved. Use of this source is governed by a
# BSD-style license that can be found in the LICENSE file.
-include: package:pedantic/analysis_options.1.9.0.yaml
-analyzer:
- errors:
- annotate_overrides: ignore
- prefer_single_quotes: ignore
- use_function_type_syntax_for_parameters: ignore
+include: package:lints/recommended.yaml
diff --git a/bin/charcode.dart b/bin/charcode.dart
index 02ae2a4..3acadb4 100644
--- a/bin/charcode.dart
+++ b/bin/charcode.dart
@@ -70,7 +70,7 @@
..add(FlagConfig("?", null, "help",
description: "Display this usage information"))
..add(FlagConfig.optionalParameter("p", "p", "prefix", "",
- description: "Sets prefix for later generated constants",
+ description: "Sets prefix for later generated constants.",
valueDescription: "PREFIX"))
..add(FlagConfig.requiredParameter("o", "o", "output",
description: "Write generated code to file instead of stdout",
@@ -84,7 +84,7 @@
for (var arg in parseFlags(flags, args, stderr.writeln)) {
var key = arg.key;
- if (key == null) {
+ if (!arg.isFlag) {
// Not a flag, value is command line argument.
declarations.parse(arg.value!);
} else {
@@ -178,8 +178,8 @@
output.writeln("const int $prefix$name = 0x$hex;");
}
- /// Orders entries by [charCode] first, then by
- /// prefixed and name.
+ /// Orders entries by [charCode] first, then by prefixed and name.
+ @override
int compareTo(Entry other) {
var delta = charCode - other.charCode;
if (delta == 0) {
@@ -886,25 +886,32 @@
..rename(0x2666, "diams", "black diamond suit ('♦')");
}
+/// Usage string printed if the `--help` or `-?` flags are passed.
+///
+/// Flag definitions are appended after the text.
const String usageString = r"""
Usage:
charcode [-h] [-oFILE] (<character-range> | <rename> | -pPREFIX | -fFILE)*
+ Emits constant declarations for the characaters specified by character ranges.
+ The constants use the pre-defined names and descriptions for ASCII characters.
+
A <character-range> is either
- - A literal character,
- - An escaped character `\n`, `\r`, `\t`, `\xhh`, `\uhhhh` or `\dd*`,
- where `h` is a hexadecimal digit and `d` is a decimal digit.
- - Two characters separated by `-`,
- - The `\d`, `\w` or `\s` escapes, or
+ - a literal character,
+ - an escaped character `\n`, `\r`, `\t`, `\xHH`, `\uHHHH` or `\DD*`,
+ where `H` is a hexadecimal digit and `D` is a decimal digit.
+ - two such characters separated by `-`,
+ - The `\d` (`0-9`), `\w` (`a-zA-Z0-9$_`) or `\s` (`\x20\t\r\n`) escapes, or
- A sequence of character ranges.
Examples: `a`, `a-z`, `\da-fA-F`, `\x00-\uFFFF`.
A <rename> declaration is a single or escaped character, a `=` and an
identifier name, optionally followed by a `:` and a description
Example: x=cross:\"a cross product.\"
- The declaration names or renames the character and adds or changes
- the associated description, but will not add the character to the output.
- Following occurrences of the character will use the new name.
+ The declaration names or renames the character, and adds or changes
+ the associated description, but will not emit the character to the output.
+ Following occurrences of the character in character ranges
+ will use the new name.
Example: `charcode y y=why x-z` will generate `$y` for the character
code of "y", then `$x`, `$why` and `$z` as well.
diff --git a/bin/src/uflags.dart b/bin/src/uflags.dart
index b261cc3..2a0c6e7 100644
--- a/bin/src/uflags.dart
+++ b/bin/src/uflags.dart
@@ -36,10 +36,11 @@
/// It has a default value to use if the parameter is omitted.
///
/// An unrecognized or malformed flag is reported using the [warn]
-/// function.
+/// function. If omitted, the [warn] function defaults to printing
+/// using the [print] function.
Iterable<CmdLineArg<T>> parseFlags<T>(
Flags<T> flags, Iterable<String> arguments,
- [void warn(String warning)?]) sync* {
+ [void Function(String warning)? warn]) sync* {
warn ??= _printWarning;
var args = arguments.iterator;
while (args.moveNext()) {
@@ -356,15 +357,29 @@
}
}
+/// Converts names to canonical form.
+///
+/// Canonical form consists of only *lower case ASCII letters*,
+/// *decimal digits* and single *dash* characters (`-`) separating letter/digit
+/// sequences.
+///
+/// All upper-case letters are made lower-case.
+/// If the input-name contains sequences of non-letter, non-digit characters,
+/// each sequence is replaced by a single `-`.
+/// Leading and trailing `-`s are then ignored
+/// if the result contains anything other than `-`.
String? canonicalizeName(String? name) {
if (name == null) return name;
const $dash = 0x2d;
var wasDash = false;
var i = 0;
+ var upperCase = 0x20;
while (i < name.length) {
var char = name.codeUnitAt(i++);
- if (char ^ 0x30 <= 9 || char >= 0x61 && char <= 0x7b) {
+ var lcChar = char | 0x20;
+ if (char ^ 0x30 <= 9 || lcChar >= 0x61 && lcChar <= 0x7b) {
wasDash = false;
+ upperCase &= char;
continue;
}
if (char == $dash && !wasDash) {
@@ -375,27 +390,21 @@
var bytes = Uint8List(name.length);
var j = 0;
for (; j < i - 1; j++) {
- bytes[j] = name.codeUnitAt(j);
+ bytes[j] = name.codeUnitAt(j) | 0x20;
}
// Convert all letters to lower-case, all non letter/digits to a single `-`.
outer:
do {
- if (char >= 0x41 && char <= 0x5b) {
- bytes[j++] = char | 0x20;
- i++;
- wasDash = false;
- } else {
- if (!wasDash) {
- bytes[j++] = $dash;
- i++;
- wasDash = true;
- }
+ if (!wasDash) {
+ bytes[j++] = $dash;
+ wasDash = true;
}
while (i < name.length) {
char = name.codeUnitAt(i++);
- if (char ^ 0x30 <= 9 || char >= 0x61 && char <= 0x7b) {
- bytes[j++] = char;
+ var lcChar = char | 0x20;
+ if (char ^ 0x30 <= 9 || lcChar >= 0x61 && lcChar <= 0x7b) {
+ bytes[j++] = lcChar;
wasDash = false;
continue;
}
@@ -408,9 +417,17 @@
}
break;
} while (true);
- return String.fromCharCodes(bytes);
+ var start = 0;
+ var end = j;
+ if (end > start + 1) {
+ // Omit leading/trailing dashes.
+ if (bytes[start] == $dash) start++;
+ if (bytes[end - 1] == $dash) end--;
+ }
+ return String.fromCharCodes(
+ Uint8List.sublistView(bytes, start, end));
}
- return name;
+ return upperCase == 0 ? name.toLowerCase() : name;
}
void _printWarning(String message) {
diff --git a/lib/ascii.dart b/lib/ascii.dart
index 319ab73..8da5b8b 100644
--- a/lib/ascii.dart
+++ b/lib/ascii.dart
@@ -17,12 +17,14 @@
/// For less common symbols, a selection of common names are used.
///
/// For parenthetical markers, there is both a short name, [$lparen]/[$rparen],
-/// and a long name, [$open_paren]/ [$close_paren].
+/// and a long name, [$openParen]/ [$closeParen].
///
/// For common HTML entities, the entity names are also usable as symbolic
/// names: [$apos], [$quot], [$lt], [$gt], and [$amp].
library charcode.ascii.dollar_lowercase;
+// ignore_for_file: constant_identifier_names
+
// Control characters.
/// "Null character" control character.
@@ -132,377 +134,419 @@
/// Space character.
const int $space = 0x20;
-/// Character '!'.
+/// Character `!`.
const int $exclamation = 0x21;
-/// Character '"', short name.
+/// Character `"', short nam`.
const int $quot = 0x22;
-/// Character '"'.
+/// Character `"`.
const int $quote = 0x22;
-/// Character '"'.
+/// Character `"`.
const int $double_quote = 0x22;
-/// Character '"'.
+/// Character `"`.
+const int $doubleQuote = 0x22;
+
+/// Character `"`.
const int $quotation = 0x22;
-/// Character '#'.
+/// Character `#`.
const int $hash = 0x23;
-/// Character '$'.
+/// Character `$`.
const int $$ = 0x24;
-/// Character '$'.
+/// Character `$`.
const int $dollar = 0x24;
-/// Character '%'.
+/// Character `%`.
const int $percent = 0x25;
-/// Character '&', short name.
+/// Character `&`, short name.
const int $amp = 0x26;
-/// Character '&'.
+/// Character `&`.
const int $ampersand = 0x26;
-/// Character "'".
+/// Character `'`.
const int $apos = 0x27;
-/// Character '''.
+/// Character `'`.
const int $apostrophe = 0x27;
-/// Character '''.
+/// Character `'`.
const int $single_quote = 0x27;
-/// Character '('.
+/// Character `'`.
+const int $singleQuote = 0x27;
+
+/// Character `(`.
const int $lparen = 0x28;
-/// Character '('.
+/// Character `(`.
const int $open_paren = 0x28;
-/// Character '('.
+/// Character `(`.
+const int $openParen = 0x28;
+
+/// Character `(`.
const int $open_parenthesis = 0x28;
-/// Character ')'.
+/// Character `(`.
+const int $openParenthesis = 0x28;
+
+/// Character `)`.
const int $rparen = 0x29;
-/// Character ')'.
+/// Character `)`.
const int $close_paren = 0x29;
-/// Character ')'.
+/// Character `)`.
+const int $closeParen = 0x29;
+
+/// Character `)`.
const int $close_parenthesis = 0x29;
-/// Character '*'.
+/// Character `)`.
+const int $closeParenthesis = 0x29;
+
+/// Character `*`.
const int $asterisk = 0x2A;
-/// Character '+'.
+/// Character `+`.
const int $plus = 0x2B;
-/// Character ','.
+/// Character `,`.
const int $comma = 0x2C;
-/// Character '-'.
+/// Character `-`.
const int $minus = 0x2D;
-/// Character '-'.
+/// Character `-`.
const int $dash = 0x2D;
-/// Character '.'.
+/// Character `.`.
const int $dot = 0x2E;
-/// Character '.'.
+/// Character `.`.
const int $fullstop = 0x2E;
-/// Character '/'.
+/// Character `/`.
const int $slash = 0x2F;
-/// Character '/'.
+/// Character `/`.
const int $solidus = 0x2F;
-/// Character '/'.
+/// Character `/`.
const int $division = 0x2F;
-/// Character '0'.
+/// Character `0`.
const int $0 = 0x30;
-/// Character '1'.
+/// Character `1`.
const int $1 = 0x31;
-/// Character '2'.
+/// Character `2`.
const int $2 = 0x32;
-/// Character '3'.
+/// Character `3`.
const int $3 = 0x33;
-/// Character '4'.
+/// Character `4`.
const int $4 = 0x34;
-/// Character '5'.
+/// Character `5`.
const int $5 = 0x35;
-/// Character '6'.
+/// Character `6`.
const int $6 = 0x36;
-/// Character '7'.
+/// Character `7`.
const int $7 = 0x37;
-/// Character '8'.
+/// Character `8`.
const int $8 = 0x38;
-/// Character '9'.
+/// Character `9`.
const int $9 = 0x39;
-/// Character ':'.
+/// Character `:`.
const int $colon = 0x3A;
-/// Character ';'.
+/// Character `;`.
const int $semicolon = 0x3B;
-/// Character '<'.
+/// Character `<`.
const int $lt = 0x3C;
-/// Character '<'.
+/// Character `<`.
const int $less_than = 0x3C;
-/// Character '<'.
+/// Character `<`.
+const int $lessThan = 0x3C;
+
+/// Character `<`.
const int $langle = 0x3C;
-/// Character '<'.
+/// Character `<`.
const int $open_angle = 0x3C;
-/// Character '='.
+/// Character `<`.
+const int $openAngle = 0x3C;
+
+/// Character `=`.
const int $equal = 0x3D;
-/// Character '>'.
+/// Character `>`.
const int $gt = 0x3E;
-/// Character '>'.
+/// Character `>`.
const int $greater_than = 0x3E;
-/// Character '>'.
+/// Character `>`.
+const int $greaterThan = 0x3E;
+
+/// Character `>`.
const int $rangle = 0x3E;
-/// Character '>'.
+/// Character `>`.
const int $close_angle = 0x3E;
-/// Character '?'.
+/// Character `>`.
+const int $closeAngle = 0x3E;
+
+/// Character `?`.
const int $question = 0x3F;
-/// Character '@'.
+/// Character `@`.
const int $at = 0x40;
-/// Character 'A'.
+/// Character `A`.
const int $A = 0x41;
-/// Character 'B'.
+/// Character `B`.
const int $B = 0x42;
-/// Character 'C'.
+/// Character `C`.
const int $C = 0x43;
-/// Character 'D'.
+/// Character `D`.
const int $D = 0x44;
-/// Character 'E'.
+/// Character `E`.
const int $E = 0x45;
-/// Character 'F'.
+/// Character `F`.
const int $F = 0x46;
-/// Character 'G'.
+/// Character `G`.
const int $G = 0x47;
-/// Character 'H'.
+/// Character `H`.
const int $H = 0x48;
-/// Character 'I'.
+/// Character `I`.
const int $I = 0x49;
-/// Character 'J'.
+/// Character `J`.
const int $J = 0x4A;
-/// Character 'K'.
+/// Character `K`.
const int $K = 0x4B;
-/// Character 'L'.
+/// Character `L`.
const int $L = 0x4C;
-/// Character 'M'.
+/// Character `M`.
const int $M = 0x4D;
-/// Character 'N'.
+/// Character `N`.
const int $N = 0x4E;
-/// Character 'O'.
+/// Character `O`.
const int $O = 0x4F;
-/// Character 'P'.
+/// Character `P`.
const int $P = 0x50;
-/// Character 'Q'.
+/// Character `Q`.
const int $Q = 0x51;
-/// Character 'R'.
+/// Character `R`.
const int $R = 0x52;
-/// Character 'S'.
+/// Character `S`.
const int $S = 0x53;
-/// Character 'T'.
+/// Character `T`.
const int $T = 0x54;
-/// Character 'U'.
+/// Character `U`.
const int $U = 0x55;
-/// Character 'V'.
+/// Character `V`.
const int $V = 0x56;
-/// Character 'W'.
+/// Character `W`.
const int $W = 0x57;
-/// Character 'X'.
+/// Character `X`.
const int $X = 0x58;
-/// Character 'Y'.
+/// Character `Y`.
const int $Y = 0x59;
-/// Character 'Z'.
+/// Character `Z`.
const int $Z = 0x5A;
-/// Character '['.
+/// Character `[`.
const int $lbracket = 0x5B;
-/// Character '['.
+/// Character `[`.
const int $open_bracket = 0x5B;
-/// Character '\'.
+/// Character `[`.
+const int $openBracket = 0x5B;
+
+/// Character `\`.
const int $backslash = 0x5C;
-/// Character ']'.
+/// Character `]`.
const int $rbracket = 0x5D;
-/// Character ']'.
+/// Character `]`.
const int $close_bracket = 0x5D;
-/// Character '^'.
+/// Character `]`.
+const int $closeBracket = 0x5D;
+
+/// Character `^`.
const int $circumflex = 0x5E;
-/// Character '^'.
+/// Character `^`.
const int $caret = 0x5E;
-/// Character '^'.
+/// Character `^`.
const int $hat = 0x5E;
-/// Character '_'.
+/// Character `_`.
const int $_ = 0x5F;
-/// Character '_'.
+/// Character `_`.
const int $underscore = 0x5F;
-/// Character '_'.
+/// Character `_`.
const int $underline = 0x5F;
-/// Character '`'.
+/// Character `` ` ``.
const int $backquote = 0x60;
-/// Character '`'.
+/// Character `` ` ``.
const int $grave = 0x60;
-/// Character 'a'.
+/// Character `a`.
const int $a = 0x61;
-/// Character 'b'.
+/// Character `b`.
const int $b = 0x62;
-/// Character 'c'.
+/// Character `c`.
const int $c = 0x63;
-/// Character 'd'.
+/// Character `d`.
const int $d = 0x64;
-/// Character 'e'.
+/// Character `e`.
const int $e = 0x65;
-/// Character 'f'.
+/// Character `f`.
const int $f = 0x66;
-/// Character 'g'.
+/// Character `g`.
const int $g = 0x67;
-/// Character 'h'.
+/// Character `h`.
const int $h = 0x68;
-/// Character 'i'.
+/// Character `i`.
const int $i = 0x69;
-/// Character 'j'.
+/// Character `j`.
const int $j = 0x6A;
-/// Character 'k'.
+/// Character `k`.
const int $k = 0x6B;
-/// Character 'l'.
+/// Character `l`.
const int $l = 0x6C;
-/// Character 'm'.
+/// Character `m`.
const int $m = 0x6D;
-/// Character 'n'.
+/// Character `n`.
const int $n = 0x6E;
-/// Character 'o'.
+/// Character `o`.
const int $o = 0x6F;
-/// Character 'p'.
+/// Character `p`.
const int $p = 0x70;
-/// Character 'q'.
+/// Character `q`.
const int $q = 0x71;
-/// Character 'r'.
+/// Character `r`.
const int $r = 0x72;
-/// Character 's'.
+/// Character `s`.
const int $s = 0x73;
-/// Character 't'.
+/// Character `t`.
const int $t = 0x74;
-/// Character 'u'.
+/// Character `u`.
const int $u = 0x75;
-/// Character 'v'.
+/// Character `v`.
const int $v = 0x76;
-/// Character 'w'.
+/// Character `w`.
const int $w = 0x77;
-/// Character 'x'.
+/// Character `x`.
const int $x = 0x78;
-/// Character 'y'.
+/// Character `y`.
const int $y = 0x79;
-/// Character 'z'.
+/// Character `z`.
const int $z = 0x7A;
-/// Character '{'.
+/// Character `{`.
const int $lbrace = 0x7B;
-/// Character '{'.
+/// Character `{`.
const int $open_brace = 0x7B;
-/// Character '|'.
+/// Character `{`.
+const int $openBrace = 0x7B;
+
+/// Character `|`.
const int $pipe = 0x7C;
-/// Character '|'.
+/// Character `|`.
const int $bar = 0x7C;
-/// Character '}'.
+/// Character `}`.
const int $rbrace = 0x7D;
-/// Character '}'.
+/// Character `}`.
const int $close_brace = 0x7D;
-/// Character '~'.
+/// Character `}`.
+const int $closeBrace = 0x7D;
+
+/// Character `~`.
const int $tilde = 0x7E;
diff --git a/pubspec.yaml b/pubspec.yaml
index 96063f6..fcfbb91 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: charcode
-version: 1.2.0
+version: 1.3.0
repository: https://github.com/lrhn/charcode
description: >-
Constants for ASCII and common non-ASCII character codes.
@@ -9,4 +9,4 @@
dev_dependencies:
test: ^1.16.0-nullsafety
- pedantic: ^1.10.0-nullsafety
+ lints: ^1.0.0
diff --git a/test/charcode_test.dart b/test/charcode_test.dart
index 04cb557..014c84c 100644
--- a/test/charcode_test.dart
+++ b/test/charcode_test.dart
@@ -30,7 +30,7 @@
expect(output, contains(r"int $a = 0x61"));
expect(output, isNot(contains(r"int $b = 0x62")));
expect(output, contains(r"int $bee = 0x62"));
- expect(output, contains(r"int Explanation!"));
+ expect(output, contains(r"Explanation!"));
expect(output, contains(r"int $c = 0x63"));
});
@@ -38,7 +38,7 @@
expect(count(output, r"$"), 2);
expect(output, contains(r"int $b = 0x62"));
expect(output, contains(r"int $bee = 0x62"));
- expect(output, contains(r"int Explanation!"));
+ expect(output, contains(r"Explanation!"));
});
testOutput(["a-c"], (output) {