From: Ian Jackson Date: Thu, 26 Nov 2020 21:32:13 +0000 (+0000) Subject: wip timestamp_abbreviate X-Git-Tag: otter-0.2.0~349 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=91f927976f2c2aafd52153e3e99106573466c27f;p=otter.git wip timestamp_abbreviate Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock.example b/Cargo.lock.example index 6b1e531d..89c6c15c 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -1186,8 +1186,10 @@ dependencies = [ name = "otter-zcoord" version = "0.0.1" dependencies = [ + "arrayvec", "derive_more", "fehler", + "if_chain", "serde", "serde_with", "thiserror", diff --git a/zcoord/Cargo.toml b/zcoord/Cargo.toml index 7a29c1f0..8fa43fa5 100644 --- a/zcoord/Cargo.toml +++ b/zcoord/Cargo.toml @@ -13,8 +13,10 @@ path = "zcoord.rs" [dependencies] +arrayvec = "0" derive_more = "0.99" fehler = "1" +if_chain = "1" thiserror = "1" serde = { version = "1", features = ["derive","rc"] } serde_with = "1" diff --git a/zcoord/misc.rs b/zcoord/misc.rs new file mode 100644 index 00000000..43531cc9 --- /dev/null +++ b/zcoord/misc.rs @@ -0,0 +1,24 @@ +// Copyright 2020 Ian Jackson +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +// This is in this crate for convenience, not because it's to do with +// Z coordinates. + +use if_chain::if_chain; +use arrayvec::ArrayVec; + +pub fn timesting_abbreviate<'x>(base: &str, this: &'x str) -> (&'x str, bool) { + fn split(s: &str) -> ArrayVec<[&str; 3]> { + s.splitn(3, ' ').collect() + } + let base3 = split(base); + let this3 = split(this); + let matches = |i| base3.get(i) == this3.get(i); + if_chain! { + if matches(0) && matches(2); + if let Some(abbrev) = this3.get(1); + then { (abbrev, true) } + else { (this, false) } + } +} diff --git a/zcoord/zcoord.rs b/zcoord/zcoord.rs index 745e4ec9..bab9cfd0 100644 --- a/zcoord/zcoord.rs +++ b/zcoord/zcoord.rs @@ -79,6 +79,8 @@ use thiserror::Error; use serde_with::DeserializeFromStr; use serde_with::SerializeDisplay; +mod misc; + //---------- core definitions ---------- pub type RangeCount = u32;