This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.C
More file actions
83 lines (67 loc) · 1.77 KB
/
Copy pathFileReader.C
File metadata and controls
83 lines (67 loc) · 1.77 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Submitted by:
* Nate Anderson
* Nathan Hansen
* Cody Foltz
* Eric Olson
*
* For Assignment #2, cs3505, January 2012
*/
#include "ctype.h"
#include "FileReader.h"
using namespace std;
FileReader::FileReader() {
}
bool FileReader::open(string filename) {
this->input.open(filename.c_str());
return this->input.is_open();
}
FileReader::~FileReader() {
this->input.close();
}
vector<string> * FileReader::readLine() {
return this->readLine(' ');
}
//void cleanString(vector<string> * cleanUp);
string cleanWord(string word);
vector<string> * FileReader::readLine(char delim) {
string line;
vector<string> * temp = 0;
if (input.good()) {
temp = new vector<string>;
getline(input, line);
stringstream stream(line);
string word;
while (getline(stream, word, delim)) {
word = cleanWord(word);
if (word.compare("") == 0)
continue;
temp->push_back(word);
}
//temp = split(line, delim);
// FIXED!!!
//cleanString(temp);
}
return temp;
}
vector<string> * FileReader::readLine(stringstream * stm) {
vector<string> *temp = new vector<string>;
string word;
while (getline(*stm, word, ' ')) {
word = cleanWord(word);
if (word.compare("") == 0)
continue;
temp->push_back(word);
}
return temp;
}
string cleanWord(string word) {
stringstream temp;
for (unsigned int i = 0; i < word.length(); i++) {
unsigned int tempCharValue = word[i];
if (tempCharValue < 256 && isalpha(tempCharValue)) {
temp << (char) tempCharValue;
}
}
return temp.str();
}