All pastes #159558 Raw Edit

Unnamed

public cpp v1 · immutable
·published 2006-09-03 06:03 UTC
rendered paste body
// leet converter v.1// © Copyright Brandon Weeks 2006// 8/30/2006// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA#include <iostream>#include <string>#include <fstream>#include <vector>using namespace std;// Function Declarationsstring converter(string);string lowercase(string);int main (int argc, char * const argv[]) {	string input; // Variable for the text to be converted 	string output; // Variable for converted text to be outputted to console	string arg[argc]; // Variable where console args in string form	bool fileOutput; // Set to true if output to file instead of console	string outputFileName; // If file output, this is the output file name		if (argc == 1) {									// If the user doesn't give a arg print and exit		cout << "leet: [file or input] file" << endl;	// 		return 1;										// Exit with code 1	}		for (int i=1;i < argc;i++) // Place the argv's into the string array 'arg'		arg[i]=argv[i];		for (int i=1;i < argc;i++) { 			if (arg[i] == "-o") { // Test if one of the args is "-o"				fileOutput=true; // If true, set fileOutput=true				outputFileName=arg[i+1]; // Also set the next arg as outputFileName				break; // Leave the loop			}	}		if (arg[1] == "file") { // If we are input from a file		vector<string> container; // Vector to hold file contents		string buffer; // String buffer to hold the file contents before we put them in the vector				if (arg[2].empty()) {					// If no input file, tell the user and exit code 1			cout << "No input file!" << endl;			return 1;		}				ifstream inputFile(arg[2].c_str()); // Open the input file				if (!inputFile) {												// If the file didn't open, warn the user and exit code 1			cout << "An error has occurred opening the file!" << endl;			return 1;		}				while (!inputFile.eof()) {		 // Loop intil we hit the end of file			getline(inputFile,buffer);	 // Put the curent line into the buffer			container.push_back(buffer); // Place the buffer into the vactor		}				for (unsigned i=0; i < container.size();i++) // Loop till we convert the whole vector			container[i]=converter(container[i]);	 // Run every line thru the converter fuction				inputFile.close(); // Close the input file		if (fileOutput==true) {										// If we are going output to file			ofstream outputFile(outputFileName.c_str());			// Open the output file			if (!outputFile) {										// If we can't open the output file, warn the user and exit code 1				cout << "Error creating the output file!" << endl;				return 1;			}			for (unsigned i=0;i < container.size();i++) { // Place the contents of the vector into the file					outputFile << container[i];					outputFile << endl;					  // Go to next line			} 						outputFile.close();							  // Close the output file		}		 else {											  // If we are not going to output to file, just output to console			for (unsigned i=0;i < container.size();i++) 				cout << container[i] << endl; 		}	}	else if (arg[1] == "input") {		 if (argc >= 3) {			for (int i=2; i < argc;i++) {				input.append(arg[i]+ " ");			}		}		else {			cout << "Welcome to BJ's l33t converter"				 << endl				 <<  "Enter something to be converted to l33t: ";			getline(cin, input);		}				output=converter(input);		cout << output << endl;		return 0; 	}	else {										// If the user inputs an unknown arg, warn user and exit code 1		cout << "leet: unknown option" << endl; 		return 1;	}}string converter(string foo) {				// This fuction does the 	for (unsigned i=0;i < foo.size();i++)		foo[i]=tolower(foo[i]);		for (int i=0;i < foo.size(); i++)		if (foo[i] == 'a' )			foo[i] = '4';		else if (foo[i] == 'b')			foo[i] = '8';		else if (foo[i] == 'e')			foo[i] = '3';		else if (foo[i] == 'i')			foo[i] = '1';		else if (foo[i] == 'l')			foo[i] = '1';		else if (foo[i] == 'o')			foo[i] = '0';		else if (foo[i] == 's')			foo[i] = '5';		else if (foo[i] == 't')			foo[i] = '7';		return foo;}