2020-06-28 13:45:18 +00:00
|
|
|
def create_iso3166_country_list_file
|
|
|
|
cpp_file_name = "src/common/iso3166_country_list.cpp"
|
|
|
|
iso3166_1 = JSON.parse(IO.readlines("/usr/share/iso-codes/json/iso_3166-1.json").join(''))
|
|
|
|
rows = iso3166_1["3166-1"].
|
|
|
|
map do |entry|
|
|
|
|
[ entry["alpha_2"].upcase.to_cpp_string,
|
|
|
|
entry["alpha_3"].upcase.to_cpp_string,
|
|
|
|
sprintf('%03s', entry["numeric"].gsub(%r{^0+}, '')),
|
|
|
|
entry["name"].to_u8_cpp_string,
|
|
|
|
(entry["official_name"] || '').to_u8_cpp_string,
|
|
|
|
]
|
|
|
|
end
|
2020-09-06 19:30:37 +00:00
|
|
|
|
2020-09-07 15:49:06 +00:00
|
|
|
entries = Mtx::IANALanguageSubtagRegistry.fetch_registry
|
|
|
|
entries["region"].
|
|
|
|
select { |region| %r{^\d+$}.match(region[:subtag]) }.
|
|
|
|
each do |region|
|
2020-09-06 19:30:37 +00:00
|
|
|
|
2020-09-07 15:49:06 +00:00
|
|
|
rows << [
|
|
|
|
'""s', '""s',
|
|
|
|
sprintf('%03s', region[:subtag].gsub(%r{^0+}, '')),
|
|
|
|
region[:description].to_u8_cpp_string,
|
|
|
|
'""s',
|
|
|
|
]
|
2020-09-06 19:30:37 +00:00
|
|
|
end
|
|
|
|
|
2020-06-28 13:45:18 +00:00
|
|
|
header = <<EOT
|
|
|
|
/*
|
|
|
|
mkvmerge -- utility for splicing together matroska files
|
|
|
|
from component media subtypes
|
|
|
|
|
|
|
|
Distributed under the GPL v2
|
|
|
|
see the file COPYING for details
|
2020-08-01 16:03:54 +00:00
|
|
|
or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2020-06-28 13:45:18 +00:00
|
|
|
|
2020-09-06 18:20:51 +00:00
|
|
|
ISO 3166 countries & UN M.49 regions
|
2020-06-28 13:45:18 +00:00
|
|
|
|
|
|
|
Written by Moritz Bunkus <moritz@bunkus.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// NOTE: this file is auto-generated by the "dev:iso3166_list" rake target.
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "common/common_pch.h"
|
|
|
|
|
|
|
|
#include "common/iso3166.h"
|
|
|
|
|
|
|
|
namespace mtx::iso3166 {
|
|
|
|
|
2021-01-25 23:42:56 +00:00
|
|
|
std::vector<region_t> g_regions;
|
|
|
|
|
|
|
|
void
|
|
|
|
init() {
|
|
|
|
g_regions.reserve(#{rows.size});
|
|
|
|
|
2020-06-28 13:45:18 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
footer = <<EOT
|
2021-01-25 23:42:56 +00:00
|
|
|
}
|
2020-06-28 13:45:18 +00:00
|
|
|
|
|
|
|
} // namespace mtx::iso3166
|
|
|
|
EOT
|
|
|
|
|
2020-09-06 19:30:37 +00:00
|
|
|
rows = rows.sort_by { |row| [ row[0], row[1], row[3] ].join('::') }
|
2021-01-25 23:42:56 +00:00
|
|
|
content = header + format_table(rows, :column_suffix => ',', :row_prefix => " g_regions.emplace_back(", :row_suffix => ");").join("\n") + "\n" + footer
|
2020-06-28 13:45:18 +00:00
|
|
|
|
|
|
|
runq("write", cpp_file_name) { IO.write("#{$source_dir}/#{cpp_file_name}", content); 0 }
|
|
|
|
end
|