-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.cpp
More file actions
44 lines (37 loc) · 1.4 KB
/
functions.cpp
File metadata and controls
44 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include "functions.hpp"
using namespace std;
void bleep(string BadWord, string &CensorThis) {
string temp = "";
for(int i = 0; i <= CensorThis.size(); i++) {
//check to see if it is end of a word or end the sentance
if (CensorThis[i] == ' ' || CensorThis[i] == '.' || CensorThis[i] == ',' || CensorThis[i] == '!' || CensorThis[i] == '?' || CensorThis[i] == ';' || i == CensorThis.size()) {
// if so, then checks to see if temp matches BadWord
if (temp == BadWord) {
// if so, replaces BadWord letters with *
for (int j = 0; j < BadWord.size(); j++) {
CensorThis[i-temp.size()+j] = '*';
}
}
// and then resets temp to emtpy
temp = "";
// if it is not the end of a word or sentence, then cycle through the letters of the sentence word to see if they match the forbidden word
}
else {
bool flag = false;
int k = 0;
// this while loop cancels after flag is set to true AND censored word length is reached
while(!flag && k < BadWord.size()){
// add letters to temp as long as the word is matching
// first, convert BadWord letters to lower case
CensorThis[k] = tolower(CensorThis[k]);
if (CensorThis[i] == BadWord[k]){
temp += CensorThis[i];
flag = true;
}
k++;
}
}
}
}