diff options
author | Till Höppner | 2016-02-25 06:48:03 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-25 06:48:03 +0100 |
commit | 9f5dd9dad6b13476bab2c6eb3c6528f8ad49311a (patch) | |
tree | 1ca71876029cb466aa6230f1aead05b32f19bf6d /base/src/format.rs | |
parent | 685aac1cc537692b2cf9342dcb6c26fa74c3c920 (diff) | |
download | ilc-9f5dd9dad6b13476bab2c6eb3c6528f8ad49311a.tar.gz ilc-9f5dd9dad6b13476bab2c6eb3c6528f8ad49311a.tar.xz ilc-9f5dd9dad6b13476bab2c6eb3c6528f8ad49311a.zip |
Refactor... everything.
Diffstat (limited to 'base/src/format.rs')
-rw-r--r-- | base/src/format.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/src/format.rs b/base/src/format.rs new file mode 100644 index 0000000..46b2da6 --- /dev/null +++ b/base/src/format.rs @@ -0,0 +1,18 @@ +use std::borrow::Cow; + +pub fn rejoin(s: &[&str], splits: &[char]) -> Cow<'static, str> { + let len = s.iter().map(|s| s.len()).fold(0, |a, b| a + b); + let mut out = s.iter() + .zip(splits.iter()) + .fold(String::with_capacity(len), |mut s, (b, &split)| { + s.push_str(b); + s.push(split); + s + }); + out.pop(); + Cow::Owned(out) +} + +pub fn strip_one(s: &str) -> String { + if s.len() >= 2 { s[1..(s.len() - 1)].to_owned() } else { String::new() } +} |