-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cpp
More file actions
92 lines (70 loc) · 1.66 KB
/
Copy pathUtilities.cpp
File metadata and controls
92 lines (70 loc) · 1.66 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
84
85
86
87
88
89
90
91
92
// Name: Jagbir Singh
// Seneca Student ID: 144019221
// Seneca email: jagbir-singh1@myseneca.ca
// Date of completion: 12/03/2024
//
// I confirm that I am the only author of this file
// and the content was created entirely by me.
#include "Utilities.h"
using namespace std;
namespace seneca
{
char Utilities::m_delimiter = '\n';
string Utilities::trim(const string& str)
{
size_t start = 0;
size_t end = str.length() - 1;
while (start <= end && isspace(str[start]))
{
start++;
}
while (end > start && isspace(str[end]))
{
end--;
}
return str.substr(start, (end - start + 1));
}
void Utilities::setFieldWidth(size_t newWidth)
{
m_widthField = newWidth;
}
size_t Utilities::getFieldWidth() const
{
return m_widthField;
}
string Utilities::extractToken(const string& str, size_t& next_pos, bool& more)
{
string temp = "";
if (str[next_pos] == m_delimiter)
{
more = false;
throw "ERROR: No token.";
}
while (next_pos < str.length() && str[next_pos] == m_delimiter) {
next_pos++;
}
if (next_pos == str.length()) {
more = false;
return temp;
}
size_t end_pos = str.find(m_delimiter, next_pos);
if (end_pos == string::npos) {
end_pos = str.length();
}
temp = trim(str.substr(next_pos, end_pos - next_pos));
next_pos = end_pos + 1;
more = (next_pos < str.length());
if (m_widthField < temp.length()) {
m_widthField = temp.length();
}
return temp;
}
void Utilities::setDelimiter(char newDelimiter)
{
m_delimiter = newDelimiter;
}
char Utilities::getDelimiter()
{
return m_delimiter;
}
}