-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen.h
62 lines (58 loc) · 1.6 KB
/
open.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <vector>
#include <string>
#include <sstream>
//***************************
// Opens 'file' (from main directory) and returns vector of tokens from start::'location' to 'location'::end
//***************************
std::vector<std::string> tokens(std::string file, std::string location) {
std::vector<std::string> temp;
std::string word = "";
std::ifstream readFile;
readFile.open(file.c_str());
if (readFile.is_open()) {
while (!readFile.eof()) { // while there is still data
readFile >> word;
if ( word == ("start::"+location) ) {
readFile >> word;
//temp.push_back("Found:");
while (word != (location+"::end") ) {
if (word != "") {
if (word[0] == '\"') {
std::string sentence = word;
while (word[word.size()-1] != '\"') {
readFile >> word;
sentence += " " + word;
}
sentence.erase(0,1);
sentence.erase(sentence.end()-1);
temp.push_back(sentence);
word = "";
}
if (word[0] == '#' && word[1] == '#' && word.size() > 2) { // comment word
readFile >> word;
continue;
}
if (word[word.size()-1]=='.' && word.size() != 1) {
word.erase(word.size()-1);
temp.push_back(word);
temp.push_back(".");
}
else if (word[word.size()-1]==',' && word.size() != 1) {
word.erase(word.size()-1);
temp.push_back(word);
temp.push_back(",");
}
else
if (word != "") temp.push_back(word);
}
readFile >> word;
if (readFile.eof()) return temp;
}
}
word = "";
}
}
readFile.close();
return temp;
}