fix: add break to forbidden word loops to count each word only once in for_loops method

This commit is contained in:
JestDotty
2025-03-24 03:23:40 +00:00
parent 7c87f28599
commit 12a95bb8d8
2 changed files with 36 additions and 2 deletions
+5 -2
View File
@@ -58,8 +58,8 @@ impl Stats {
return;
};
self.file_count += 1;
self.muncher(&text);
// self.for_loops(&text);
// self.muncher(&text);
self.for_loops(&text);
}
#[allow(dead_code)]
/// probably buggy. for example, are new lines sentences? what if the text has no last period?
@@ -89,6 +89,7 @@ impl Stats {
for forbidden_word in FORBIDDEN_WORDS {
if lowercase_word.contains(forbidden_word) {
self.forbidden_count += 1;
break; //if you find one count it as a whole word
}
}
word = String::new();
@@ -113,6 +114,7 @@ impl Stats {
for forbidden_word in FORBIDDEN_WORDS {
if lowercase_word.contains(forbidden_word) {
self.forbidden_count += 1;
break; //if you find one count it as a whole word
}
}
word = String::new();
@@ -161,6 +163,7 @@ impl Stats {
for forbidden_word in FORBIDDEN_WORDS {
if lowercase_word.contains(forbidden_word) {
self.forbidden_count += 1;
break; //if you find one count it as a whole word
}
}
}