Skip to main content

asv_to_usv/
lib.rs

1use std::convert::AsRef;
2use usv::style::Style;
3
4pub mod examples;
5
6pub fn asv_to_usv<
7    S: AsRef<str> + Sized
8>(
9    usv: S,
10    style: &Style,
11) -> String {
12    usv.as_ref()
13    .replace("\u{001F}", &style.unit_separator)
14    .replace("\u{001E}", &format!("{}{}", style.unit_separator, style.record_separator))
15    .replace("\u{001D}", &format!("{}{}{}", style.unit_separator, style.record_separator, style.group_separator))
16    .replace("\u{001C}", &format!("{}{}{}{}", style.unit_separator, style.record_separator, style.group_separator, style.file_separator))
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use usv::style::Style;
23    use crate::examples::*;
24
25    #[test]
26    fn asv_to_usv_test() {
27        let asv = EXAMPLE_ASV_FILES;
28        let usv = usv::examples::EXAMPLE_FILES_STYLE_SYMBOLS;
29        let style = Style::default();
30        assert_eq!(asv_to_usv(&asv, &style), usv);
31    }
32
33}