refactor: extract parser module with muncher and for_loops submodules from main.rs
Move Stats processing methods into dedicated parser module with separate muncher and for_loops implementations, update .gitignore to exclude test_books directory, and simplify README to remove outdated benchmark instructions
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
use crate::{FORBIDDEN_WORDS, stats::Stats};
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// typically 5000ms
|
||||
/// with trie this is 1600ms
|
||||
pub fn parse(stats: &mut Stats, text: &str) {
|
||||
for sentence in text
|
||||
.split('.')
|
||||
.map(|s| s.trim())
|
||||
.filter(|s| !s.is_empty())
|
||||
{
|
||||
stats.sentence_count += 1;
|
||||
for word in sentence
|
||||
.split_whitespace()
|
||||
.map(|s| s.trim())
|
||||
.filter(|s| !s.is_empty())
|
||||
{
|
||||
stats.word_count += 1;
|
||||
//get all numbers counted
|
||||
let mut all_capitalized = true;
|
||||
for char in word.chars() {
|
||||
if char.is_numeric() {
|
||||
stats.numeric_count += 1;
|
||||
//TODO are numbers capitalized or not? I don't know!
|
||||
}
|
||||
if !char.is_ascii_uppercase() {
|
||||
all_capitalized = false;
|
||||
}
|
||||
}
|
||||
if all_capitalized {
|
||||
stats.capitalized_count += 1;
|
||||
}
|
||||
let lowercase_word = word.to_lowercase();
|
||||
if FORBIDDEN_WORDS.contains(&lowercase_word) {
|
||||
stats.forbidden_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user