From 47a6e31047660643f22ee4fc007a629c571e3acd Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 27 Jan 2021 23:55:51 +0300 Subject: [PATCH] fix: allow emojis for location markers is_marker() should check for length in characters, not bytes. This was broken during the Rust translation in changeset a5553f98af5df262abd54f3171f53360258655dd --- src/location.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/location.rs b/src/location.rs index fe93bd0da..ec0482582 100644 --- a/src/location.rs +++ b/src/location.rs @@ -372,7 +372,12 @@ pub async fn get_range( } fn is_marker(txt: &str) -> bool { - txt.len() == 1 && !txt.starts_with(' ') + let mut chars = txt.chars(); + if let Some(c) = chars.next() { + !c.is_whitespace() && chars.next().is_none() + } else { + false + } } /// Deletes all locations from the database. @@ -777,4 +782,13 @@ mod tests { assert!(locations_ref[0].accuracy.abs() < f64::EPSILON); assert_eq!(locations_ref[0].timestamp, timestamp); } + + #[test] + fn test_is_marker() { + assert!(is_marker("f")); + assert!(!is_marker("foo")); + assert!(is_marker("🏠")); + assert!(!is_marker(" ")); + assert!(!is_marker("\t")); + } }