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 entries = Mtx::IANALanguageSubtagRegistry.fetch_registry entries["region"]. select { |region| %r{^\d+$}.match(region[:subtag]) }. each do |region| rows << [ '""s', '""s', sprintf('%03s', region[:subtag].gsub(%r{^0+}, '')), region[:description].to_u8_cpp_string, '""s', ] end header = <. */ // ------------------------------------------------------------------------ // 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 { std::vector g_regions; void init() { g_regions.reserve(#{rows.size}); EOT footer = < ',', :row_prefix => " g_regions.emplace_back(", :row_suffix => ");").join("\n") + "\n" + footer runq("write", cpp_file_name) { IO.write("#{$source_dir}/#{cpp_file_name}", content); 0 } end