-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cpp
62 lines (57 loc) · 1.44 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
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include "Utilities.h"
#include "Station.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)
{
std::string token{};
std::size_t position = str.find(getDelimiter(), next_pos);
if (position == next_pos)
{
more = false;
throw std::string("Not found!");
}
else if (position != std::string::npos)
{
token = str.substr(next_pos, position - next_pos);
next_pos = token.find_first_not_of(" ");
token.erase(token.begin(), token.begin() + next_pos);
size_t end = token.find_last_not_of(" ");
token.erase(end + 1);
m_widthField = std::max(m_widthField, token.length());
next_pos = position + 1;
more = true;
}
else if (position == std::string::npos)
{
token = str.substr(next_pos, position - next_pos);
next_pos = token.find_first_not_of(" ");
token.erase(token.begin(), token.begin() + next_pos);
size_t end = token.find_last_not_of(" ");
token.erase(end + 1);
m_widthField = std::max(m_widthField, token.length());
next_pos = position + 1;
more = false;
}
return token;
}
void Utilities::setDelimiter(char newDelimiter)
{
m_delimiter = newDelimiter;
}
char Utilities::getDelimiter()
{
return m_delimiter;
}
}