- use List::Util qw( first pairfirst pairs );
-
- state $INHERIT = {
- 'cp437' => ['cp850' => 0], # ascii range overridden later
- 'gsm0338' => ['ascii' => '0-127'],
-
- 'iso-8859-2' => ['iso-8859-1' => '160'],
- 'iso-8859-3' => ['iso-8859-1' => '160'],
- 'iso-8859-4' => ['iso-8859-2' => '160'],
- 'iso-8859-5' => ['iso-8859-1' => '160'],
- 'iso-8859-6' => ['iso-8859-1' => '160'],
- 'iso-8859-7' => ['iso-8859-1' => '160'],
- 'iso-8859-8' => ['iso-8859-1' => '160'],
- 'iso-8859-9' => ['iso-8859-1' => '208'],
- 'iso-8859-10' => ['iso-8859-4' => '160'],
- 'iso-8859-11' => ['iso-8859-1' => '160'],
- 'iso-8859-13' => ['iso-8859-4' => '160'],
- 'iso-8859-14' => ['iso-8859-1' => '160'],
- 'iso-8859-15' => ['iso-8859-1' => '160-191'],
- 'iso-8859-16' => ['iso-8859-2' => '160'],
- 'hp-roman8' => ['iso-8859-1' => '160'],
-
- 'cp1252' => ['iso-8859-1' => '128-159'],
- 'cp1250' => ['iso-8859-2' => '128-191'],
- 'cp1254' => ['iso-8859-9' => '128-159'],
- 'cp874' => ['iso-8859-11' => '128-159'], # windows-874 actually cp1162
- 'cp1257' => ['iso-8859-13' => '128'],
- 'cp1251' => ['cp1252' => '128'],
- 'cp1253' => ['cp1252' => '128'],
- 'cp1255' => ['iso-8859-8' => '128-223', 'cp1252' => '128'],
- 'cp1256' => ['cp1252' => '128'],
-
- 'cp850' => ['cp437' => '144'],
- 'cp860' => ['cp437' => '128-175'],
- 'cp861' => ['cp865' => '128-175'],
- 'cp863' => ['cp437' => '128-175'],
- 'cp865' => ['cp437' => '144-175'],
- 'cp852' => ['cp850' => '128', 'cp437' => '128'],
- 'cp857' => ['cp850' => '128-239', 'cp437' => '128'],
- 'cp775' => ['cp850' => '128'], # partial cp437
- 'cp866' => ['cp437' => '128'],
- 'cp855' => ['cp437' => '128'],
- 'cp1006' => ['cp437' => '128'],
- 'cp737' => ['cp437' => '128'],
- 'cp869' => ['cp437' => '128'],
- 'cp862' => ['cp437' => '128'],
- 'cp864' => ['cp437' => '128'],
-
- 'koi8-u' => ['koi8-r' => 128],
- 'koi8-f' => ['koi8-u' => 128],
-
- 'MacRomanian' => ['MacRoman' => '160'],
- 'MacCroatian' => ['MacRoman' => '160'],
- 'MacCentralEurRoman' => ['MacRoman' => '128'],
- 'MacTurkish' => ['MacRoman' => '208-223'], # F5 is unassigned
- 'MacCyrillic' => ['MacRoman' => '128'],
- 'MacHebrew' => ['MacRoman' => '128'],
- };
-
- my @parents = @{ $INHERIT->{$input} || [] };
-
- if (my ($parent, $part) = pairfirst { exists $visible->{$a} } @parents) {