Skip to content

Commit

Permalink
[rust] Fix keymap regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jan 8, 2024
1 parent 7ec8c10 commit b911ddc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rust/agama-locale-data/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ impl FromStr for KeymapId {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let re = KEYMAP_ID_REGEX
.get_or_init(|| Regex::new(r"(\w+)((\((?<var1>\w+)\)|-(?<var2>\w+)))?").unwrap());
.get_or_init(||
Regex::new(r"([\w.]+)((\((?<var1>.+)\)|-(?<var2>.+)))?").unwrap());

if let Some(parts) = re.captures(s) {
let mut variant = None;
Expand Down Expand Up @@ -153,5 +154,23 @@ mod test {
},
keymap_id2
);

let keymap_id3 = KeymapId::from_str("pt-nativo-us").unwrap();
assert_eq!(
KeymapId {
layout: "pt".to_string(),
variant: Some("nativo-us".to_string())
},
keymap_id3
);

let keymap_id4 = KeymapId::from_str("lt.std").unwrap();
assert_eq!(
KeymapId {
layout: "lt.std".to_string(),
variant: None
},
keymap_id4
);
}
}

0 comments on commit b911ddc

Please sign in to comment.