/*
Write a program that removes all vowels from a 
file (“disemvowels”). For example, Once upon a 
time! becomes nc pn tm!. Surprisingly often, the 
result is still readable; try it on your friends.
*/

#include "std_lib_facilities.h"

void disemvowel(ifstream&);
string disemvowel(string&);

// check if letter is a vowel
bool isvowel(char ch) {
	ch = tolower(ch);
	return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

// check if string consists of vowels only
bool allvowels(const string& s) {
	for (int i = 0; i < s.size(); ++i)
		if (!isvowel(s[i])) return false;
	return true;
}

int main() {
	string fname, inString;
	cout << "What file would you like to disemvowel? ";
	cin >> fname;
	ifstream in(fname);
	disemvowel(in);
	cout << "What string would you like to disemvowel?";
	cin >> inString;
	cout << disemvowel(inString);
}

// take all vowels out of string
string disemvowel(string& s) {
	string s_novow;
	for (int i = 0; i < s.size(); ++i) {
		if (!isvowel(s[i])) s_novow.push_back(s[i]);
	}
	s = s_novow;
	return s;
}

void disemvowel(ifstream& ifs) {
	string vowels{ "aeiou" };
	char c{ 0 };
	ifs >> c;
	char* buffer = &c;
	ifs.unget();
	while (ifs.read(buffer, 1)) {
		if (char(tolower(*buffer)) == vowels[0]
			|| char(tolower(*buffer)) == vowels[1]
			|| char(tolower(*buffer)) == vowels[2]
			|| char(tolower(*buffer)) == vowels[3]
			|| char(tolower(*buffer)) == vowels[4])
			continue;
		cout << *buffer;
	}
}