pub mod format;
pub mod parse;
pub mod sequence;
pub use format::{output_error, output_error_with_context, output_result, OutputFormat};
pub use parse::{
parse_genome_build, parse_shuffle_direction, parse_vcf_line, parse_vcf_line_with_build,
};
pub use sequence::reverse_complement;
const UTF8_BOM: &str = "\u{feff}";
pub fn strip_bom(s: &str) -> &str {
s.strip_prefix(UTF8_BOM).unwrap_or(s)
}
pub fn strip_inline_comment(s: &str) -> &str {
match s.find('#') {
Some(pos) => s[..pos].trim(),
None => s.trim(),
}
}
pub fn process_input_line(line: &str, is_first_line: bool) -> Option<&str> {
let line = line.trim();
let line = if is_first_line { strip_bom(line) } else { line };
let line = strip_inline_comment(line);
if line.is_empty() {
None
} else {
Some(line)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_strip_bom() {
assert_eq!(strip_bom("\u{feff}test"), "test");
assert_eq!(strip_bom("test"), "test");
assert_eq!(strip_bom("\u{feff}"), "");
assert_eq!(strip_bom(""), "");
}
#[test]
fn test_strip_inline_comment() {
assert_eq!(strip_inline_comment("variant # comment"), "variant");
assert_eq!(strip_inline_comment("variant#comment"), "variant");
assert_eq!(strip_inline_comment("# full comment"), "");
assert_eq!(strip_inline_comment("variant"), "variant");
assert_eq!(strip_inline_comment(" variant "), "variant");
}
#[test]
fn test_process_input_line() {
assert_eq!(process_input_line("variant", false), Some("variant"));
assert_eq!(
process_input_line("variant # comment", false),
Some("variant")
);
assert_eq!(process_input_line("\u{feff}variant", true), Some("variant"));
assert_eq!(
process_input_line("\u{feff}variant", false),
Some("\u{feff}variant")
);
assert_eq!(process_input_line("", false), None);
assert_eq!(process_input_line(" ", false), None);
assert_eq!(process_input_line("# comment", false), None);
}
}