-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cpp
More file actions
45 lines (32 loc) · 842 Bytes
/
Copy pathUtilities.cpp
File metadata and controls
45 lines (32 loc) · 842 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
39
40
41
42
43
44
45
//Author Name: Victor A.
#include <iostream>
#include <string>
#include "Utilities.h"
namespace std
{
char Utilities::m_delimiter = '\0';
void Utilities::setFieldWidth(size_t fieldWidth)
{
m_widthField = fieldWidth;
}
const std::string Utilities::extractToken(const std::string& str, size_t& next_pos, bool& more)
{
const auto tempPos = str.find(getDelimiter(), next_pos);
auto token = str.substr(next_pos, tempPos - next_pos);
more = tempPos != std::string::npos;
if (tempPos == next_pos)
{
std::string err = "ERROR - two delimiters with no token between them";
throw err;
}
if (token.length() > getFieldWidth())
{
this->setFieldWidth(token.length());
}
next_pos = tempPos + 1u;
return token;
}
void Utilities::setDelimiter(const char u_delimiter) {
m_delimiter = u_delimiter;
}
}