2023-03-24 01:15:19 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2023 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-03-24 01:40:06 +01:00
|
|
|
# quick-and-dirty simplified interface to https://github.com/garabik/unicode
|
2023-03-24 01:15:19 +01:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Encode;
|
|
|
|
|
|
|
|
if (not @ARGV) {
|
2023-03-24 02:20:22 +01:00
|
|
|
print "Usage: unicode <character> | <U+XXXX code-point or U+XXXX..[U+XXXX] range> | -s <search regex>\n";
|
2023-03-24 01:15:19 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV = map { decode('UTF-8', $_, 1) } @ARGV;
|
|
|
|
|
|
|
|
my $args = join ' ', @ARGV;
|
|
|
|
|
|
|
|
my $search = 0;
|
|
|
|
|
2023-03-24 01:40:06 +01:00
|
|
|
if ($args =~ s/^-s\s+//) {
|
2023-03-24 01:15:19 +01:00
|
|
|
$search = 1;
|
|
|
|
}
|
|
|
|
|
2023-03-24 02:20:22 +01:00
|
|
|
if ($args =~ /^(u\+[^.]+)\s*\.\.\s*(.*)$/i) {
|
|
|
|
my ($from, $to) = ($1, $2);
|
|
|
|
|
|
|
|
$from =~ s/u\+//i;
|
|
|
|
$to =~ s/u\+//i;
|
|
|
|
|
|
|
|
$from = hex $from;
|
|
|
|
$to = hex $to;
|
|
|
|
|
|
|
|
if ($to > 0 && $to - $from > 100) {
|
|
|
|
print "Range limited to 100 characters.\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 01:15:19 +01:00
|
|
|
my $result;
|
|
|
|
|
|
|
|
if ($args =~ /^u\+/i) {
|
2023-03-24 02:20:22 +01:00
|
|
|
$result = `unicode --max=100 --color=off \Q$args\E`;
|
2023-03-24 01:15:19 +01:00
|
|
|
} elsif ($search) {
|
2023-03-24 01:56:40 +01:00
|
|
|
$result = `unicode -r --max=100 --color=off \Q$args\E --format 'U+{ordc:04X} {pchar} {name};\n'`;
|
2023-03-24 01:15:19 +01:00
|
|
|
} else {
|
2023-03-24 02:20:22 +01:00
|
|
|
$result = `unicode -s --max=100 --color=off \Q$args\E --format 'U+{ordc:04X} ({utf8}) {pchar} {name} Category: {category} ({category_desc}) {opt_unicode_block}{opt_unicode_block_desc}{mirrored_desc}{opt_combining}{combining_desc}{opt_decomp}{decomp_desc};\n'`;
|
2023-03-24 01:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
print "$result\n";
|