#![allow(unknown_lints)]
use std::collections::HashSet;
use std::hash::Hash;
#[allow(needless_pass_by_value)]
pub fn insert_or_get<T>(set: &mut HashSet<T>, value: T) -> &T
where T: Hash + Eq + Clone
{
if set.contains(&value) {
set.get(&value)
.expect("insert_or_get: HashSet API is fubar, get after contains got us nothing...")
} else {
set.insert(value.clone());
set.get(&value)
.expect("insert_or_get: HashSet API is fubar, get after insert got us nothing...")
}
}
pub fn string_unescape(string: &str) -> String {
let mut result = String::with_capacity(string.len() - 2);
let mut copy = true;
for chunk in string[1..string.len() - 1].split('\\') {
if copy {
result.push_str(chunk);
copy = false;
} else if chunk.len() == 0 {
result.push('\\');
copy = true;
} else {
match &chunk[0..1] {
"n" => result.push('\n'),
"r" => result.push('\r'),
"t" => result.push('\t'),
char => result.push_str(char),
}
result.push_str(&chunk[1..])
}
}
result
}