From 740ca9818cda0ec54da80e540201a42f71177cb1 Mon Sep 17 00:00:00 2001
From: Marcela Ribeiro de Oliveira <mro15@inf.ufpr.br>
Date: Sun, 13 May 2018 18:00:49 -0300
Subject: [PATCH] =?UTF-8?q?colocando=20os=20filtros=20em=20fun=C3=A7=C3=B5?=
 =?UTF-8?q?es=20separadas=20e=20acho=20que=20deu=20bom=20o=20filtro=203?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 include/playunfair.h |  4 ++++
 playunfair.cpp       | 51 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/include/playunfair.h b/include/playunfair.h
index 1365890..3997bec 100644
--- a/include/playunfair.h
+++ b/include/playunfair.h
@@ -4,3 +4,7 @@
 
 int filter(std::string text);
 void parser(std::string &text);
+	int isVowel(char c);
+int filter1(std::string text);
+int filter2(std::string text);
+int filter3(std::string text);
diff --git a/playunfair.cpp b/playunfair.cpp
index cc4006e..4bcc60c 100644
--- a/playunfair.cpp
+++ b/playunfair.cpp
@@ -3,8 +3,8 @@
 
 
 int main(int argc, char *argv[]){
-	if(argc!=4){
-		std::cout << "Uso: ./playunfair <file-in> <file-out> <dicionarion>" << std::endl;
+	if(argc!=3){
+		std::cout << "Uso: ./playunfair <file-in> <dicionarion>" << std::endl;
 		return 0;
 	}
 	std::fstream input, output, dict;
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]){
 	std::ostringstream text, keys;
 
 	inputName = argv[1];
-	dictName = argv[3];
+	dictName = argv[2];
 
 	input.open(inputName, std::ifstream::in);
 	if(!input.good()){
@@ -63,7 +63,16 @@ int filter(std::string text){
 	//
 	//          )
 	//         { elimina texto: muda pra proxima chave}
-	size_t i, j;
+	return (filter1(text) && filter2(text) && filter3(text));
+}
+
+int isVowel(char c){
+	int result;
+	result = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
+		return result;
+}
+
+int filter1(std::string text){
 	int rej = REJECTED;
 	for(int i=0; i<4; ++i){
 		if(text[i] == 'a' || text[i] == 'e' || text[i] == 'i' || text[i] == 'o' ||
@@ -72,6 +81,12 @@ int filter(std::string text){
 			break;
 		}
 	}
+	return rej;
+}
+
+int filter2(std::string text){
+	size_t i, j;
+	int rej = ACCEPTED;
 	for(i=0; i<text.size()-3; ++i){
 		char l = text[i];
 		int lim=3, cont=0;
@@ -84,7 +99,7 @@ int filter(std::string text){
 			} else if (text[j] == l){
 				++cont;
 				continue;
-			} if (text[j] != l){
+			} else if (text[j] != l){
 				break;
 			}
 		}
@@ -96,3 +111,29 @@ int filter(std::string text){
 
 	return rej;
 }
+
+int filter3(std::string text){
+	size_t i, j;
+	int rej = ACCEPTED;
+	for(i=0; i<text.size()-5; ++i){
+		int lim = 5, cont = 0;
+		char l = text[i];
+		if(isVowel(l))
+			continue;
+		for(j=i+1; j<i+lim; ++j){
+			if(text[j]=='x'){
+				++lim;
+				continue;
+			} else if (!isVowel(text[j])){
+				++cont;
+			} else if(isVowel(text[j])){
+				break;
+			}
+		}
+		if(cont==5){
+			rej = REJECTED;
+			break;
+		}
+	}
+	return rej;
+}
-- 
GitLab