Source Code
#!/usr/bin/perl
# viqr2unicode.pl v0.9
# Convert VIQR coding to Unicode
# AffectiveSilicon.com
# This work is licensed under CC BY-NC-SA 4.0
# Usage examples:-
# (chmod +x viqr2unicode.pl)
# cat viqr.txt | /path/to/viqr2unicode.pl > processed.txt
# /path/to/viqr2unicode.pl viqr.txt | less
use v5.8;
use strict;
use utf8;
use charnames();
use List::Util 'first';
binmode(STDOUT, ":utf8");
my %VIQR; # for lookup table, VIQR coding => unicode char
# setup the transliteration lookup table %VIQR
# unaccented characters, lower and upper case, space
$VIQR{$_} = $_ for ( split(//, ' abcdeghiklmnopqrstuvxy' . uc('abcdeghiklmnopqrstuvxy')) );
# escaped characters
$VIQR{ '\\' . $_ } = $_ for ( split(//, q{.,?~'}) );
# accented characters, lower and upper case, read from __DATA__ section below
while ( <DATA> ) {
chomp;
my ($VIQR, $Charname) = split /:::/;
if ( length $Charname ) {
$VIQR{$VIQR} = charnames::string_vianame( $Charname );
}
}
# we want the keys sorted by length
my @viqr_keys = sort { length($b) <=> length($a) } keys %VIQR;
while ( <> ) { # read from passed file or direct from stdin
my $string = $_;
chomp($string);
my $unicode = q{};
while ( length $string ) {
my $val = first { $string =~ /^\Q$_\E/ } @viqr_keys; # find the first longest literal match in the VIQR table
$unicode .= $VIQR{$val} || q{}; # and update the unicode with it
$string = substr($string, length($val)); # decrease the length of the string until all processed
}
# it is anticipated the output will be manually redirected or piped to somewhere
print $unicode, "\n";
}
exit;
# data below taken from http://vietunicode.sourceforge.net/charset/
__DATA__
A`:::LATIN CAPITAL LETTER A WITH GRAVE
A':::LATIN CAPITAL LETTER A WITH ACUTE
A^:::LATIN CAPITAL LETTER A WITH CIRCUMFLEX
A~:::LATIN CAPITAL LETTER A WITH TILDE
E`:::LATIN CAPITAL LETTER E WITH GRAVE
E':::LATIN CAPITAL LETTER E WITH ACUTE
E^:::LATIN CAPITAL LETTER E WITH CIRCUMFLEX
I`:::LATIN CAPITAL LETTER I WITH GRAVE
I':::LATIN CAPITAL LETTER I WITH ACUTE
O`:::LATIN CAPITAL LETTER O WITH GRAVE
O':::LATIN CAPITAL LETTER O WITH ACUTE
O^:::LATIN CAPITAL LETTER O WITH CIRCUMFLEX
O~:::LATIN CAPITAL LETTER O WITH TILDE
U`:::LATIN CAPITAL LETTER U WITH GRAVE
U':::LATIN CAPITAL LETTER U WITH ACUTE
Y':::LATIN CAPITAL LETTER Y WITH ACUTE
a`:::LATIN SMALL LETTER A WITH GRAVE
a':::LATIN SMALL LETTER A WITH ACUTE
a^:::LATIN SMALL LETTER A WITH CIRCUMFLEX
a~:::LATIN SMALL LETTER A WITH TILDE
e`:::LATIN SMALL LETTER E WITH GRAVE
e':::LATIN SMALL LETTER E WITH ACUTE
e^:::LATIN SMALL LETTER E WITH CIRCUMFLEX
i`:::LATIN SMALL LETTER I WITH GRAVE
i':::LATIN SMALL LETTER I WITH ACUTE
o`:::LATIN SMALL LETTER O WITH GRAVE
o':::LATIN SMALL LETTER O WITH ACUTE
o^:::LATIN SMALL LETTER O WITH CIRCUMFLEX
o~:::LATIN SMALL LETTER O WITH TILDE
u`:::LATIN SMALL LETTER U WITH GRAVE
u':::LATIN SMALL LETTER U WITH ACUTE
y':::LATIN SMALL LETTER Y WITH ACUTE
A(:::LATIN CAPITAL LETTER A WITH BREVE
a(:::LATIN SMALL LETTER A WITH BREVE
DD:::LATIN CAPITAL LETTER D WITH STROKE
dd:::LATIN SMALL LETTER D WITH STROKE
I~:::LATIN CAPITAL LETTER I WITH TILDE
i~:::LATIN SMALL LETTER I WITH TILDE
U~:::LATIN CAPITAL LETTER U WITH TILDE
u~:::LATIN SMALL LETTER U WITH TILDE
O+:::LATIN CAPITAL LETTER O WITH HORN
o+:::LATIN SMALL LETTER O WITH HORN
U+:::LATIN CAPITAL LETTER U WITH HORN
u+:::LATIN SMALL LETTER U WITH HORN
A.:::LATIN CAPITAL LETTER A WITH DOT BELOW
a.:::LATIN SMALL LETTER A WITH DOT BELOW
A?:::LATIN CAPITAL LETTER A WITH HOOK ABOVE
a?:::LATIN SMALL LETTER A WITH HOOK ABOVE
A^':::LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND ACUTE
a^':::LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE
A^`:::LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND GRAVE
a^`:::LATIN SMALL LETTER A WITH CIRCUMFLEX AND GRAVE
A^?:::LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE
a^?:::LATIN SMALL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE
A^~:::LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND TILDE
a^~:::LATIN SMALL LETTER A WITH CIRCUMFLEX AND TILDE
A^.:::LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND DOT BELOW
a^.:::LATIN SMALL LETTER A WITH CIRCUMFLEX AND DOT BELOW
A(':::LATIN CAPITAL LETTER A WITH BREVE AND ACUTE
a(':::LATIN SMALL LETTER A WITH BREVE AND ACUTE
A(`:::LATIN CAPITAL LETTER A WITH BREVE AND GRAVE
a(`:::LATIN SMALL LETTER A WITH BREVE AND GRAVE
A(?:::LATIN CAPITAL LETTER A WITH BREVE AND HOOK ABOVE
a(?:::LATIN SMALL LETTER A WITH BREVE AND HOOK ABOVE
A(~:::LATIN CAPITAL LETTER A WITH BREVE AND TILDE
a(~:::LATIN SMALL LETTER A WITH BREVE AND TILDE
A(.:::LATIN CAPITAL LETTER A WITH BREVE AND DOT BELOW
a(.:::LATIN SMALL LETTER A WITH BREVE AND DOT BELOW
E.:::LATIN CAPITAL LETTER E WITH DOT BELOW
e.:::LATIN SMALL LETTER E WITH DOT BELOW
E?:::LATIN CAPITAL LETTER E WITH HOOK ABOVE
e?:::LATIN SMALL LETTER E WITH HOOK ABOVE
E~:::LATIN CAPITAL LETTER E WITH TILDE
e~:::LATIN SMALL LETTER E WITH TILDE
E^':::LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE
e^':::LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE
E^`:::LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND GRAVE
e^`:::LATIN SMALL LETTER E WITH CIRCUMFLEX AND GRAVE
E^?:::LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE
e^?:::LATIN SMALL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE
E^~:::LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND TILDE
e^~:::LATIN SMALL LETTER E WITH CIRCUMFLEX AND TILDE
E^.:::LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND DOT BELOW
e^.:::LATIN SMALL LETTER E WITH CIRCUMFLEX AND DOT BELOW
I?:::LATIN CAPITAL LETTER I WITH HOOK ABOVE
i?:::LATIN SMALL LETTER I WITH HOOK ABOVE
I.:::LATIN CAPITAL LETTER I WITH DOT BELOW
i.:::LATIN SMALL LETTER I WITH DOT BELOW
O.:::LATIN CAPITAL LETTER O WITH DOT BELOW
o.:::LATIN SMALL LETTER O WITH DOT BELOW
O?:::LATIN CAPITAL LETTER O WITH HOOK ABOVE
o?:::LATIN SMALL LETTER O WITH HOOK ABOVE
O^':::LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND ACUTE
o^':::LATIN SMALL LETTER O WITH CIRCUMFLEX AND ACUTE
O^`:::LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND GRAVE
o^`:::LATIN SMALL LETTER O WITH CIRCUMFLEX AND GRAVE
O^?:::LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE
o^?:::LATIN SMALL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE
O^~:::LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND TILDE
o^~:::LATIN SMALL LETTER O WITH CIRCUMFLEX AND TILDE
O^.:::LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND DOT BELOW
o^.:::LATIN SMALL LETTER O WITH CIRCUMFLEX AND DOT BELOW
O+':::LATIN CAPITAL LETTER O WITH HORN AND ACUTE
o+':::LATIN SMALL LETTER O WITH HORN AND ACUTE
O+`:::LATIN CAPITAL LETTER O WITH HORN AND GRAVE
o+`:::LATIN SMALL LETTER O WITH HORN AND GRAVE
O+?:::LATIN CAPITAL LETTER O WITH HORN AND HOOK ABOVE
o+?:::LATIN SMALL LETTER O WITH HORN AND HOOK ABOVE
O+~:::LATIN CAPITAL LETTER O WITH HORN AND TILDE
o+~:::LATIN SMALL LETTER O WITH HORN AND TILDE
O+.:::LATIN CAPITAL LETTER O WITH HORN AND DOT BELOW
o+.:::LATIN SMALL LETTER O WITH HORN AND DOT BELOW
U.:::LATIN CAPITAL LETTER U WITH DOT BELOW
u.:::LATIN SMALL LETTER U WITH DOT BELOW
U?:::LATIN CAPITAL LETTER U WITH HOOK ABOVE
u?:::LATIN SMALL LETTER U WITH HOOK ABOVE
U+':::LATIN CAPITAL LETTER U WITH HORN AND ACUTE
u+':::LATIN SMALL LETTER U WITH HORN AND ACUTE
U+`:::LATIN CAPITAL LETTER U WITH HORN AND GRAVE
u+`:::LATIN SMALL LETTER U WITH HORN AND GRAVE
U+?:::LATIN CAPITAL LETTER U WITH HORN AND HOOK ABOVE
u+?:::LATIN SMALL LETTER U WITH HORN AND HOOK ABOVE
U+~:::LATIN CAPITAL LETTER U WITH HORN AND TILDE
u+~:::LATIN SMALL LETTER U WITH HORN AND TILDE
U+.:::LATIN CAPITAL LETTER U WITH HORN AND DOT BELOW
u+.:::LATIN SMALL LETTER U WITH HORN AND DOT BELOW
Y`:::LATIN CAPITAL LETTER Y WITH GRAVE
y`:::LATIN SMALL LETTER Y WITH GRAVE
Y.:::LATIN CAPITAL LETTER Y WITH DOT BELOW
y.:::LATIN SMALL LETTER Y WITH DOT BELOW
Y?:::LATIN CAPITAL LETTER Y WITH HOOK ABOVE
y?:::LATIN SMALL LETTER Y WITH HOOK ABOVE
Y~:::LATIN CAPITAL LETTER Y WITH TILDE
y~:::LATIN SMALL LETTER Y WITH TILDE