pub fn remove_double_quotas(mut string: String) -> String {
string.retain(|c| c != '"');
return string
}
pub fn grep(path_to_file: &std::ffi::OsStr, search_text: &str) -> Result<String, Box<dyn std::error::Error>> {
match std::fs::File::open(path_to_file) {
Ok(file) => {
let reader = std::io::BufReader::new(file);
for line in std::io::BufRead::lines(reader) {
let res: String = line.unwrap();
if res.contains(search_text) {
return Ok(res.to_string())
}
}
Err("Searching text not found".into())
},
Err(_) => {
return Err("Unable to open the file.".into())
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn remove_double_quotas_test() {
let result = remove_double_quotas("\"test\"".to_string());
assert!(result == "test");
}
}