From 868a81b7adc6fd742347698a037c10157d6a73a4 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 11 Oct 2021 18:06:00 -0700 Subject: [PATCH] Using U+ notation instead of M- for non-printing characters. --- README.md | 7 ++++--- bin/dcat.dart | 2 +- doc/api/index.html | 7 ++++--- lib/dcat.dart | 13 +------------ test/dcat_test.dart | 13 ++++++++----- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 280be91..b183318 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # dcat: Concatenate File(s) to Standard Output -A **cat** command-line implemenation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline). +A **cat** command-line implementation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline). ## Synopsis @@ -30,7 +30,7 @@ With no FILE, or when FILE is -, read standard input. -T, --show-tabs display TAB characters as ^I -s, --squeeze-blank suppress repeated empty output lines --version output version information and exit - -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB + -v, --show-nonprinting use ^ and U+ notation, except for LFD and TAB Examples: dcat f - g Output f's contents, then standard input, then g's contents. @@ -51,4 +51,5 @@ dart compile exe bin/dcat.dart ## Differences from [GNU cat](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation) - No binary file support. - A line is considered terminated by either a `CR` (carriage return), a `LF` (line feed), a `CR+LF` sequence (DOS line ending). - - The non-printing `M-^?` notation is always used for unicode characters. \ No newline at end of file + - A line ending is automatically appended to the last line of any read file. + - The `U+` notation is used instead of `M-` for non-printing characters. \ No newline at end of file diff --git a/bin/dcat.dart b/bin/dcat.dart index 5a74b40..0603278 100644 --- a/bin/dcat.dart +++ b/bin/dcat.dart @@ -57,7 +57,7 @@ Future main(List arguments) async { parser.addFlag(showNonPrintingFlag, negatable: false, abbr: 'v', - help: 'use ^ and M- notation, except for LFD and TAB'); + help: 'use ^ and U+ notation, except for LFD and TAB'); final ArgResults argResults; try { diff --git a/doc/api/index.html b/doc/api/index.html index 08177ec..f61a297 100644 --- a/doc/api/index.html +++ b/doc/api/index.html @@ -47,7 +47,7 @@

License (3-Clause BSD) GitHub CI

dcat: Concatenate File(s) to Standard Output

-

A cat command-line implemenation in Dart, inspired by the Write command-line apps sample code.

+

A cat command-line implementation in Dart, inspired by the Write command-line apps sample code.

Synopsis

dcat copies each file, or standard input if none are given, to standard output.

Command-Line Usage

@@ -68,7 +68,7 @@ With no FILE, or when FILE is -, read standard input. -T, --show-tabs display TAB characters as ^I -s, --squeeze-blank suppress repeated empty output lines --version output version information and exit - -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB + -v, --show-nonprinting use ^ and U+ notation, except for LFD and TAB Examples: dcat f - g Output f's contents, then standard input, then g's contents. @@ -85,7 +85,8 @@ Examples:
  • No binary file support.
  • A line is considered terminated by either a CR (carriage return), a LF (line feed), a CR+LF sequence (DOS line ending).
  • -
  • The non-printing M-^? notation is always used for unicode characters.
  • +
  • A line ending is automatically appended to the last line of any read file.
  • +
  • The U+ notation is used instead of M- for non-printing characters.
diff --git a/lib/dcat.dart b/lib/dcat.dart index 05ae1bb..c95f422 100644 --- a/lib/dcat.dart +++ b/lib/dcat.dart @@ -83,18 +83,7 @@ Future _parseNonPrinting(String line, bool showTabs) async { } else if (ch == 127) { sb.write('^?'); } else { - sb.write('M-'); - if (ch >= 128 + 32) { - if (ch < 128 + 127) { - sb.writeCharCode(ch - 128); - } else { - sb.write('^?'); - } - } else { - sb - ..write('^') - ..writeCharCode(ch - 128 + 64); - } + sb.write('U+' + ch.toRadixString(16).padLeft(4, '0').toUpperCase()); } } else if (ch == 9 && !showTabs) { sb.write('\t'); diff --git a/test/dcat_test.dart b/test/dcat_test.dart index 1c1abc2..1fa3d30 100644 --- a/test/dcat_test.dart +++ b/test/dcat_test.dart @@ -1,4 +1,6 @@ -import 'dart:io'; +// Copyright (c) 2021, Erik C. Thauvin. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be found +// in the LICENSE file. import 'package:dcat/dcat.dart'; import 'package:test/test.dart'; @@ -129,13 +131,13 @@ void main() { test('Test cat -A', () async { await cat(['test/test.txt'], log: log, showNonPrinting: true, showEnds: true, showTabs: true); - expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?\$')); + expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713\$')); }); test('Test cat -t', () async { await cat(['test/test.txt'], log: log, showNonPrinting: true, showTabs: true); - expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?')); + expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713')); }); test('Test cat-Abs', () async { @@ -156,8 +158,7 @@ void main() { }); test('Test cat -v', () async { - await cat(['test/test.txt'], - log: log, showNonPrinting: true); + await cat(['test/test.txt'], log: log, showNonPrinting: true); var hasTab = false; for (final String line in log) { if (line.contains('\t')) { @@ -166,6 +167,8 @@ void main() { } } expect(hasTab, true, reason: "has real tab"); + expect(log.last, equals('\t^A^B^C^DU+00A9^?U+0080U+2713'), + reason: 'non-printing'); }); }); }