Case-Insensitive Option (--ignore, -i): Implementing a case-insensitive option would allow for more flexible and user-friendly search functionality.
Regex Support: Regular expressions provide powerful pattern matching capabilities. Enhancing the grep command with full regex support would greatly increase its functionality and make it more applicable for complex searching needs.
Proposed Solutions
Implement Case-Insensitive Option
Add the --ignore or -i flags to the grep command to allow users to perform searches without considering letter casing.
When the option is enabled it simply compares the pattern to each line after changing it to lowercase. I think it shouldn't be too difficult to implement.
pub async fn grep_file(
&mut self,
path: &Path,
pattern_tree: &mut PatternTree,
patterns: &Vec<String>,
) -> io::Result<()> {
let file = File::open(path).await?;
let mut reader = BufReader::new(file);
let mut line_bytes = Vec::new();
let mut i = 0;
while reader.read_until(b'\n', &mut line_bytes).await? > 0 {
// fix here
let line = String::from_utf8_lossy(&line_bytes).to_string();
self.process_line(line, i, path, pattern_tree, patterns);
line_bytes.clear();
i += 1;
}
Ok(())
}
Integrate Full Regex Support
Use regex crate
Need to put a special character in front of the pattern to indicate that it's a Regex to distinguish it from a plain string. e.g., /.../
Description
Proposed Solutions
Implement Case-Insensitive Option
--ignore
or-i
flags to the grep command to allow users to perform searches without considering letter casing.When the option is enabled it simply compares the pattern to each line after changing it to lowercase. I think it shouldn't be too difficult to implement.
Integrate Full Regex Support
/.../