LR-META-LOCATION: fall back to whitespace GPS split

This commit is contained in:
ronibalthazar
2026-10-24 20:04:04 +01:00
parent 647ed93df2
commit 6ea7906109
+9 -2
View File
@@ -1841,8 +1841,10 @@ pub(crate) fn parse_gps(t: &str) -> Option<(f64, f64)> {
let mut latitude_markers = t.char_indices().filter(|(_, c)| matches!(c, 'N' | 'S' | 'n' | 's'));
if let Some((first, marker)) = latitude_markers.next() {
if first == 0 {
if let Some((second, _)) = t.char_indices().skip(1).find(|(_, c)| is_gps_hemisphere(*c)) {
parsed = Some(parse_gps_pair(t.get(..second)?, t.get(second..)?)?);
if let Some((second, _)) = t.char_indices().skip(1).find(|(_, c)| is_gps_hemisphere(*c))
&& let Some(pair) = parse_gps_pair(t.get(..second)?, t.get(second..)?)
{
parsed = Some(pair);
}
} else {
let end = first.checked_add(marker.len_utf8())?;
@@ -2039,6 +2041,11 @@ mod gps_tests {
assert_eq!(p("45N 7NE"), None);
}
#[test]
fn gps_tries_whitespace_split_when_prefix_marker_split_fails() {
assert_eq!(super::parse_gps("N51 0E"), Some((51.0, 0.0)));
}
#[test]
fn gps_rejects_unconsumed_coordinate_text() {
assert_eq!(super::parse_gps("garbage45, 7junk"), None);