Quick actions

cmd+k|ctrl+k

Navigation

Languages

parse_abbreviations_v2

Snippet info

Language

Cpp

Visibility

public

Author

tsotnep

Created

2016-06-01T20:45:41Z

Updated

2016-06-01T22:39:58Z

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <set>
#include <fstream>
#include <vector>
using namespace std;

string checkABBR(string s){
    if (isupper(s[0]) && isupper(s[s.size()-1])) {
        return s;
    }
    return "";
}

void addToSet (set <string> *SET, string s){
    for (int i=1; i<s.size(); i++){
        if ((s[i-1]==' ' && s[i] != ' ') || (s[i-1]=='(' && s[i] != ')')){
            for (int j=i+1; j<s.size()-1; j++){
                if (j-i > 1 && s[j]==' '){
                    SET->insert(checkABBR(s.substr(i,j-i)));
                    break;
                }
            }
        }
    }
}

void printSET(set <string> *SET){
    ofstream MyFile;
    MyFile.open("ABBR.txt", ios::out | ios::app);
    set<string>::iterator it;
    for (it=SET->begin(); it!=SET->end(); ++it){
        MyFile << *it << endl;
    }
}


void readFile(ifstream *MyFile, set <string> *SET){ //
    string line;
    while ( getline (*MyFile, line) ) {
        addToSet(SET," " + line + " ");
    }
    MyFile->close();
}

int main ()
{

    ifstream MyFile0 ("./files/abstract.tex");
    ifstream MyFile1 ("./files/bistfi.tex");
    ifstream MyFile2 ("./files/connectedpe.tex");
    ifstream MyFile3 ("./files/faults.tex");
    ifstream MyFile4 ("./files/introduction.tex");
    ifstream MyFile5 ("./files/linksharing.tex");
    ifstream MyFile6 ("./files/litrev.tex");
    ifstream MyFile7 ("./files/noc.tex");
    ifstream MyFile8 ("./files/proposed.tex");
    ifstream MyFile9 ("./files/summary.tex");
    ifstream MyFile11 ("./files/v0.tex");
    ifstream MyFile22 ("./files/v1.tex");
    ifstream MyFile33 ("./files/v2.tex");
    ifstream MyFile44 ("./files/v3.tex");
    ifstream MyFile55 ("./files/z_examples.tex");
    ifstream MyFile66 ("./files/z_main.tex");

    set <string> SET;

    readFile(&MyFile0, &SET);
    readFile(&MyFile1, &SET);
    readFile(&MyFile2, &SET);
    readFile(&MyFile3, &SET);
    readFile(&MyFile4, &SET);
    readFile(&MyFile5, &SET);
    readFile(&MyFile6, &SET);
    readFile(&MyFile7, &SET);
    readFile(&MyFile8, &SET);
    readFile(&MyFile9, &SET);
    readFile(&MyFile11, &SET);
    readFile(&MyFile22, &SET);
    readFile(&MyFile33, &SET);
    readFile(&MyFile44, &SET);
    readFile(&MyFile55, &SET);
    readFile(&MyFile66, &SET);

    printSET(&SET);

    return 0;
}
INFO