Commit 42e0681d authored by Jason Rhinelander's avatar Jason Rhinelander
Browse files

Various fixes

parent 5ed7cb80
......@@ -31,6 +31,10 @@ my $arg = qr{
(?:utf)?8\+? [[:xdigit:]]+ (?:[_ ][[:xdigit:]]+)* # Hex such as UTF8+E2_80_BD or 8+42, representing a UTF8 representation
)
|
(
[D0]\+ \d+ (?:[_ ]\d+)* # Decimal, such as 0+8253 or D+82_53
)
|
(
0?b[01]+(?:[_ ][01]+)* # Binary, such as: 0b100000_00111101, b00100000_00111101, b10000000111101, etc. single _'s allowed.
)
......@@ -131,7 +135,7 @@ if ($opts{search} or $opts{regex}) {
my @chars;
for (@ARGV) {
if (/^($arg)(?:-($arg))?\z/) {
my ($char, $to) = ($1, $6);
my ($char, $to) = ($1, $7);
push @chars, defined $to
? (codepoint($char) .. codepoint($to))
: codepoint($char);
......@@ -146,7 +150,7 @@ for (@ARGV) {
if ($error or $opts{help}) {
print "\n";
usage();
exit $error ? 1 : 0;
exit($error ? 1 : 0);
}
......@@ -221,7 +225,11 @@ else {
for my $col (0 .. $#max) {
push @tpl, join(' ', map { '%' . ($formats[$_] eq 'c' ? '-' : '') . "$max[$col][$_]s" } 0 .. $#formats);
}
print join(' ', map sprintf($_, map $header{$_}, @formats), @tpl), "\n";
unless (@formats == 1 and length($header{$formats[0]}) == 1) {
# A single-letter header just looks wrong when there is only
# one column, so just suppress it.
print join(' ', map sprintf($_, map $header{$_}, @formats), @tpl), "\n";
}
for my $row (0 .. $rows-1) {
my @cells;
......@@ -248,8 +256,9 @@ sub bytes {
sub codepoint {
my $value = shift;
$value =~ /^$arg$/ or die "Cannot compute codepoint of `$value'";
my ($hex, $utf8_code, $bin, $chr) = ($1, $2, $3, $4);
my ($hex, $utf8_code, $decimal, $bin, $chr) = ($1, $2, $3, $4, $5);
$hex =~ s/^(?:U\+?|0?x)//i if defined $hex;
$decimal =~ s/^[0D]\+//i if defined $decimal;
if (defined $utf8_code) {
$utf8_code =~ s/.*\+//;
(my $c = $utf8_code) =~ y/ _//d;
......@@ -258,7 +267,7 @@ sub codepoint {
length($bytes) == 1 or die "Invalid input: 'UTF8+$utf8_code' decodes to multiple characters\n";
return ord $bytes;
}
return defined $hex ? hex($hex) : defined $bin ? oct($bin) : ord $chr
return defined $hex ? hex($hex) : defined $decimal ? 0+$decimal : defined $bin ? oct($bin) : ord $chr
}
sub usage {
......@@ -268,14 +277,15 @@ Usage: $0 [OPTION]... [FROM-TO]... [CHARACTER]...
Displays UTF-8 characters from FROM to TO, or from each character in the list
provided. FROM, TO and CHARACTER can be hexadecimal numbers (optionally
beginning with 0x or the unicode-style U+ prefix), binary numbers (beginning
with 0b), or single UTF-8 characters. If no FROM-TO pairs nor CHARACTERs are
specified, characters from 0 to 255 are displayed.
with 0b), decimal numbers prefixed with "0+" or "D+", or single UTF-8
characters. If no FROM-TO pairs nor CHARACTERs are specified, characters from
0 to 255 are displayed.
Recognized options:
-h, -?, --help This help screen.
--[no]details Display [or not] character details [Default: display
details if no FROM-TO sequences specified]
details when not using a FROM-TO range]
-s, --search="name" Searches for characters with unicode names containing
"name". Search is case-insensitive.
-r, --regex="regex" Like --search, but uses the supplied perl regular
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment