-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbyte.cpp
62 lines (49 loc) · 1.01 KB
/
byte.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 "Byte.h"
Byte::Byte(unsigned char c, bool isTerminator)
{
this->c = c;
this->isTerminator = isTerminator;
}
Byte::Byte()
{
}
Byte::~Byte()
{
}
unsigned char Byte::getChar() const
{
return c;
}
bool Byte::getIsTerminator() const
{
return isTerminator;
}
bool operator < (const Byte &lhs, const Byte &rhs)
{
if (lhs.getChar() == rhs.getChar())
return (lhs.getIsTerminator() > rhs.getIsTerminator()); //So that the terminator (0x00, true) is first
return (lhs.getChar() < rhs.getChar());
}
bool Byte::operator == (unsigned char c)
{
return (this->c == c);
}
std::string Byte::getPrintable() const
{
if (c == '\n')
return "\\n ";
if (c == '\t')
return "\\t ";
std::string s = " ";
s[0] = char(c);
return s;
}
std::string Byte::getHexPrintable() const
{
char hexOutput[10];
if (!isTerminator)
sprintf_s(hexOutput, " (0x%02x):\t", c);
else
sprintf_s(hexOutput, " (Term):\t");
return std::string(hexOutput);
}