Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- using namespace std;
- string *fromStrings=new string[1000];
- string *toStrings=new string[1000];
- int members;
- /**
- * Loads a language into the arrays.
- * The syntax of the file should be old:new
- * @param filename - The path to the file
- */
- void loadLanguage(string filename,int lines)
- {
- string buffer;
- members=lines;
- ifstream file(filename.c_str());
- for(int index=0; index<lines; index++)
- {
- getline(file,buffer);
- if(buffer.find(":")!=-1){
- toStrings[index]=buffer.substr(0,buffer.find(":"));
- fromStrings[index]=buffer.substr(buffer.find(":"),buffer.length());
- }
- }
- }
- //!Not my work
- void replaceAll(std::string& str, std::string& from, std::string& to) {
- size_t start_pos = 0;
- while((start_pos = str.find(from, start_pos)) < std::string::npos) {
- str.replace(start_pos, from.length(), to);
- start_pos += to.length();
- }
- }
- /**
- * Compiles the language set up by loadLangauge.
- * It really just places it in a text file in C++.
- * @param fileName - Where to find the file
- * @param lines - How many lines the file has.
- */
- void compile(string fileName,int lines){
- string line[lines];
- ifstream reader(fileName.c_str());
- for(int index=0; index<lines; index++)
- getline(reader, line[index]);
- for(int index=0; index<lines; index++)
- {
- for(int secInd=0; secInd<members; secInd++)
- {
- replaceAll(line[index],toStrings[secInd],fromStrings[secInd]);
- }
- cout << line[index]<<endl;
- }
- reader.close();
- }
- int main(){
- loadLanguage("/home/nate/langdefines",10);
- compile("/home/nate/code",3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement