-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringData.cpp
More file actions
76 lines (69 loc) · 1.6 KB
/
Copy pathStringData.cpp
File metadata and controls
76 lines (69 loc) · 1.6 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
#include <string>
#include "StringData.h"
using namespace std;
using namespace insight;
/* Constructor
*
*/
StringData::StringData()
{
}
/* Construct to define header
*
* header - header string, left justified in the zone
*/
StringData::StringData(string header)
{
setHeader(header);
}
/* Get the formatted string for the zone
*
* lengthOfZone - lenght to format to
*
*/
std::string StringData::getFormattedString(char lengthOfZone)
{
if(m_updateString)
{
m_formattedString.clear();
m_updateString = false;
if(m_stringHeader.length() + m_stringData.length() > lengthOfZone)
{
string tmpString = m_stringData;
if(m_stringData.length() > lengthOfZone)
{
tmpString.erase(tmpString.end() - (tmpString.length() - lengthOfZone), tmpString.end());
}
m_formattedString = m_stringHeader.substr(0, lengthOfZone - tmpString.length()) + tmpString;
}
else
{
m_formattedString = m_stringHeader + string(lengthOfZone - (m_stringHeader.length() + m_stringData.length()), ' ').
append(m_stringData);
}
}
return m_formattedString;
}
/* Set the data. This is called to set the data, as the display runs
* the updated values will be displayed
*
* data - the data to display
*
*/
void StringData::setData(string data)
{
m_updateString = true;
m_stringData.clear();
m_stringData = data;
}
/* Set the header. This is called to set or change the header, as the display
* runs the updated value will be displayed
*
* header - data description to display
*/
void StringData::setHeader(string header)
{
m_updateString = true;
m_stringHeader.clear();
m_stringHeader = header;
}