-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.cpp
More file actions
38 lines (31 loc) · 812 Bytes
/
FileReader.cpp
File metadata and controls
38 lines (31 loc) · 812 Bytes
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
#include <algorithm>
#include "FileReader.h"
using std::string;
FileReader::FileReader(std::string path)
: m_file(path) {}
FileReader::~FileReader() {}
std::string FileReader::getWord() {
while(1) { // Break by 'return' only when a word is found
if(!m_line_reader) {
string line;
if(!getline(m_file,line)) {
return "";
}
m_line_reader = std::istringstream(line);
}
string word;
m_line_reader >> word;
word = processWord(word);
if (word != "") {
return word;
}
}
}
string FileReader::processWord(string str) {
// Erase non alphanumeric characters
str.erase(std::remove_if(str.begin(), str.end(),
std::not1(std::ptr_fun((int(*)(int))std::isalpha))), str.end());
// covert to lower case
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}