4 title => 'country code cheat sheet',
7 "Table of ISO-3166-1 country codes with the names of reserved territories.",
8 keywords => [qw'country code cc tld cctld continent territory land table'],
9 data => ['data/countries.inc.pl'],
13 <h1>ISO-3166-1α2 Country codes</h1>
16 my $cc = Data('data/countries');
19 printf '<table class="ccmap">';
20 print '<col><colgroup span="26">';
21 for my $section (qw{thead}) {
22 print "<$section><tr><th>↳";
23 print '<th>', $_ for 'a' .. 'z';
27 for my $row ('a' .. 'z') {
28 print '<tr><th>', $row;
29 for my $col ('a' .. 'z') {
30 my $code = $row . $col;
31 my $country = $cc->{$code} or do {
32 print $code =~ /^x|^q[m-z]|^aa|^zz/ ? '<td class="X Co">' : '<td>';
35 my ($name, $class, $short, $ref) = @$country;
36 $name .= " → $ref" if $ref;
39 if (exists $get{show}) {
42 my $img = "data/flag/$cc.png";
44 sprintf '<img src="/%s" alt="%s">', $img, $cc;
47 $cell = showflag($code) // join(' ',
48 map { showflag($_) || $_ } split(/ /, $ref)
52 $cell = EscapeHTML($short || $name);
54 printf "\n".'<td class="%s" title="%s">%s',
55 $cell ? 'X '.$class : '', EscapeHTML("$code: $name"), $cell;
66 <table class="glyphs"><tr>
67 <td class="X c-af">africa
68 <td class="X c-eu">europe
69 <td class="X c-as">asia
70 <td class="X c-an">antarctica
71 <td class="X c-oc">oceania
72 <td class="X c-sa">south america
73 <td class="X c-na">north america
74 <td class="X Xr">reserved
77 <td class="X Co">user-assigned
81 <ul class="legend legend-set">
82 <li><strong>show</strong>
83 <em><:= exists $get{show} ? 'flag images' : 'english names' :></em><:=
84 !exists $get{show} && ' by default' :>
85 <li>default <strong>style</strong> is
86 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
91 <: exit unless exists $get{v}; :>
92 <script type="text/javascript"><!--
93 const table = document.querySelector('.ccmap');
94 const label = Array.prototype.map.call(table.tHead.rows[0].children, i => i.textContent);
95 const flagchr = 0x1F1E5; // regional indicator symbol letter base
97 for (let row = 0; row < label.length; row++) {
98 for (let col = 0; col < label.length; col++) {
99 let cell = table.rows[row].cells[col];
100 if (!cell.className) continue;
101 let flag = String.fromCodePoint(flagchr + row) + String.fromCodePoint(flagchr + col);
102 cell.innerHTML = `<big>${flag}</big> ` + cell.innerHTML;
103 if (nowidth === undefined) {
104 // assume AA is invalid, compare its size to validate following glyphs
105 nowidth = cell.firstChild.offsetWidth;
107 if (cell.firstChild.offsetWidth == nowidth) {
108 cell.firstChild.remove();