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 a5553f98af
This commit is contained in:
link2xt
2021-01-27 23:55:51 +03:00
committed by link2xt
parent 785cc795e3
commit 47a6e31047

View File

@@ -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"));
}
}