-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cpp
51 lines (40 loc) · 1.18 KB
/
Utilities.cpp
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
//Name: Chaoyi Wu
// Seneca Student ID: 154330179
// Seneca email: [email protected]
// Date of completion: Nov. 14th
//
// I confirm that the content of this file is created by me,
// with the exception of the parts provided to me by my professor.
#include <algorithm>
#include "Utilities.h"
char Utilities::m_delimiter;
void Utilities::setDelimiter(const char c) {
m_delimiter = c;
}
const char Utilities::getDelimiter() const {
return m_delimiter;
}
void Utilities::setFieldWidth(size_t wf) {
m_widthField = wf;
}
size_t Utilities::getFieldWidth() const {
return m_widthField;
}
const std::string Utilities::extractToken(const std::string& str, size_t& next_pos, bool& more) {
if(str.at(next_pos) == m_delimiter){
throw std::string("Two Delimiters With No Token Between Them");
}
std::string token = str.substr(next_pos);
auto dIndex = token.find(m_delimiter);
if (token.find(m_delimiter) == std::string::npos) {
next_pos = -1;
more = false;
}
else {
next_pos = str.find(token.substr(dIndex+1));
more = true;
token = token.substr(0, dIndex);
}
m_widthField = std::max(m_widthField, token.length());
return token;
}