-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtilities.cpp
More file actions
50 lines (39 loc) · 1.25 KB
/
Utilities.cpp
File metadata and controls
50 lines (39 loc) · 1.25 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
/* I have done all the coding by myself and only copied the code that my professor provided to complete my workshops and assignments.
Name: Hayaturehman Ahmadzai
Email: hahmadzai3@myseneca.ca
Student ID: 122539166
Created on 2021-07-09.*/
#include "Utilities.h"
namespace sdds {
char Utilities::m_delimiter{};
void Utilities::setFieldWidth(size_t newWidth)
{
m_widthField = newWidth;
}
size_t Utilities::getFieldWidth() const
{
return m_widthField;
}
std::string Utilities::extractToken(const std::string& str, size_t& next_pos, bool& more)
{
size_t idxOfDelimiter = (str.find(getDelimiter(), next_pos));
std::string extracted = str.substr(next_pos, idxOfDelimiter - next_pos);
if (idxOfDelimiter == next_pos)
{
more = false;
throw std::string("Failed to find the delimiter");
}
next_pos = idxOfDelimiter + 1;
setFieldWidth(std::max(m_widthField, extracted.size()));
more = idxOfDelimiter != std::string::npos;
return extracted;
}
void Utilities::setDelimiter(char newDelimiter)
{
m_delimiter = newDelimiter;
}
char Utilities::getDelimiter()
{
return m_delimiter;
}
}