From 1e15b836824ebdf721c011232242c39f918b6009 Mon Sep 17 00:00:00 2001 From: Nicholas Latham Date: Thu, 6 Jul 2023 14:45:51 +0100 Subject: [PATCH] ISO Name method --- codes-iso-3166/build.rs | 6 ++++++ codes-iso-3166/templates/part_2._rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/codes-iso-3166/build.rs b/codes-iso-3166/build.rs index 9940c79..e72ff4d 100644 --- a/codes-iso-3166/build.rs +++ b/codes-iso-3166/build.rs @@ -305,6 +305,12 @@ fn process_part_2_name_data( }; row.insert("name".to_string(), name.into()); + if record.get(6).map(|lang| lang == "eng").unwrap_or(false) { + if let Some(iso_name) = record.get(7) { + row.insert("iso_name".to_string(), iso_name.to_string().into()); + } + } + let name_local_variation = record.get(8).unwrap().to_string(); if !name_local_variation.is_empty() { row.insert( diff --git a/codes-iso-3166/templates/part_2._rs b/codes-iso-3166/templates/part_2._rs index 2f9f262..5afdcd0 100644 --- a/codes-iso-3166/templates/part_2._rs +++ b/codes-iso-3166/templates/part_2._rs @@ -128,4 +128,12 @@ impl {{ type_name }} {{ "{" }} _ => None, {{ "}" }} {{ "}" }} + + /// Returns the name corresponding to the name in iso-codes of this subdivision's name. + pub const fn iso_code_name(&self) -> Option<&'static str> {{ "{" }} + match self {{ "{" }}{% for id in all_ids %}{% if codes[id].iso_name %} + Self::{{ id }} => Some("{{ codes[id].iso_name }}"),{% endif %}{% endfor %} + _ => None, + {{ "}" }} + {{ "}" }} {{ "}" }}