-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_euler.cpp
More file actions
45 lines (39 loc) · 1.2 KB
/
project_euler.cpp
File metadata and controls
45 lines (39 loc) · 1.2 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
#include "project_euler.h"
#include <sstream>
// public functions
bool Parse::string_to_bool(std::string const &string) {
if (string == "1" || string == "true" || string == "True") {
return true;
} else {
return false;
}
}
Parse::tokens Parse::get_tokens(std::ifstream &input_file, const char comment,
const char delim) {
// Ignore comments, lines starting with a whitespace, and lines with no
// characters
std::string line;
do {
if (input_file.eof()) break;
std::getline(input_file, line);
} while (line[0] == comment || line[0] == ' ' || line.size() == 0);
// Now that we have our line, break it into tokens
return break_line_into_tokens(line, delim);
}
// private functions
void Parse::strip_whitespace(std::string &token) {
while (token[0] == ' ') {
token.erase(token.begin());
}
}
Parse::tokens Parse::break_line_into_tokens(std::string const &line,
const char delim) {
std::stringstream ss(line);
tokens hold_broken_pieces;
std::string token;
while (std::getline(ss, token, delim)) {
strip_whitespace(token);
hold_broken_pieces.push_back(token);
}
return hold_broken_pieces;
}