LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Fix parse_gps for hemisphere-letter-first coordinates without comma
NetterSilver80a342e9e2a7
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex 860cf089f..4a7bcde70 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -1714,7 +1714,14 @@ pub(crate) fn parse_gps(t: &str) -> Option<(f64, f64)> {let (a, b) = match t.split_once(',') {Some((a, b)) => (a.trim().to_string(), b.trim().to_string()),None => {- let i = t.find(['N', 'S', 'n', 's']).map(|i| i + 1).or_else(|| t.find(char::is_whitespace))?;+ let lead = t.starts_with(['N', 'S', 'n', 's']);+ let i = if lead {+ // hemisphere letter first: "N 51.5 W 0.1" splits at the E/W letter+ t.char_indices().skip(1).find(|(_, c)| matches!(c, 'E' | 'W' | 'e' | 'w')).map(|(i, _)| i)+ } else {+ t.find(['N', 'S', 'n', 's']).map(|i| i + 1)+ }+ .or_else(|| t.find(char::is_whitespace))?;(t[..i].trim().to_string(), t[i..].trim().to_string())}};@@ -1746,6 +1753,9 @@ mod gps_tests {assert!((la - 51.50722).abs() < 1e-4 && (lo + 0.1275).abs() < 1e-4, "{la} {lo}");let (la, lo) = p("33.8688 S, 151.2093 E").unwrap();assert!((la + 33.8688).abs() < 1e-9 && (lo - 151.2093).abs() < 1e-9);+ assert_eq!(p("51.5 N 0.1 W"), Some((51.5, -0.1)));+ assert_eq!(p("N 51.5072 W 0.1276"), Some((51.5072, -0.1276)));+ assert_eq!(p("S 33.8688 E 151.2093"), Some((-33.8688, 151.2093)));assert_eq!(p("95, 10"), None);assert_eq!(p("hello"), None);}