#!/usr/bin/env perl use utf8; ############################################################################### # This program copies an Unicode text input stream to the console # character with the execption of the standard XML character entities # which it encodes. Also encodes codepoints above 127. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Utils; use strict; use warnings; MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); my $c; while (defined($c = Utils::getchar(*STDIN))) { if ($c == ord("<")) { print "<"; } elsif ($c == ord(">")) { print ">"; } elsif ($c == ord("&")) { print "&"; } elsif ($c == ord("'")) { print "'"; } elsif ($c == ord("\"")) { print """; } elsif ($c > 127) { print Utils::messageFormat("&#x\{0:04x\};", $c); } else { print chr($c); } } }