Skip to content

Commit

Permalink
stable
Browse files Browse the repository at this point in the history
  • Loading branch information
leodutra committed Nov 27, 2021
1 parent 7209668 commit fcbee20
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ use countries::{COUNTRIES, COUNTRIES_CODE_MAP, COUNTRIES_FLAG_MAP};

const FLAG_MAGIC_NUMBER: u32 = 127462 - 65;


#[derive(Clone)]
pub(crate) struct Country {
code: &'static str,
flag: String,
names: Vec<&'static str>,
}

impl Country {
pub(crate) fn new(code: &'static str, names: Vec<&'static str>) -> Self {
Country {
code,
names,
flag: internal_code_to_flag(code),
}
}

pub(crate) fn name(&self) -> &'static str {
self.names[0]
}
}


fn trim_upper(text: &str) -> String {
text.trim().to_uppercase()
}
Expand Down Expand Up @@ -43,27 +66,6 @@ fn get_by_flag(flag: &str) -> Option<&'static Country> {
COUNTRIES_FLAG_MAP.get(flag.trim()).map(|x| *x)
}

#[derive(Clone)]
pub(crate) struct Country {
code: &'static str,
flag: String,
names: Vec<&'static str>,
}

impl Country {
pub(crate) fn new(code: &'static str, names: Vec<&'static str>) -> Self {
Country {
code,
names,
flag: internal_code_to_flag(code),
}
}

pub(crate) fn name(&self) -> &'static str {
self.names[0]
}
}

pub fn code(input: &str) -> Option<&'static str> {
flag_to_code(input).or_else(|| name_to_code(input))
}
Expand Down

0 comments on commit fcbee20

Please sign in to comment.