forked from domi91c/Submitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.cpp
More file actions
105 lines (103 loc) · 2.52 KB
/
Copy pathLine.cpp
File metadata and controls
105 lines (103 loc) · 2.52 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <cstring>
#include "Line.h"
#include "colors.h"
#include "debug.h"
namespace sict {
bool Line::m_colored = false;
Line::Line(const char* line, int highLight):m_line(line), m_highlightIndex(highLight) {
}
std::ostream& Line::display(std::ostream& os)const {
int i = 0;
m_colored = (&os == &std::cout);
while (m_line[i]) {
if (i == m_highlightIndex && m_colored) os << col_red;
if (m_line[i] == '\b') { // don't think this is needed anymore since all the backspaces are removed!
os << "\\b";
}
else {
os << m_line[i];
}
if (i == m_highlightIndex && m_colored) os << col_end;
i++;
}
if (m_highlightIndex >= 0) {
os << std::endl;
for (i = 0; i < m_highlightIndex; i++) os << " ";
if (m_colored) os << col_red;
os << "^" ;
if (m_colored) os << col_end;
}
return os;
}
const char* Line::operator[](int index){
m_buf[0] = 0;
if (m_colored) copy(m_buf, col_red);
cat(m_buf, charName( m_line[index]));
if (m_colored) cat(m_buf, col_end);
return m_buf;
}
void Line::copy(char* des, const char* src) {
while (*src) *des++ = *src++;
*des = 0;
}
void Line::cat(char* des, const char* src) {
while (*des) des++;
while (*src) *des++ = *src++;
*des = 0;
}
void Line::cat(char* des, char src) {
while (*des) des++;
*des++ = src;
*des = 0;
}
const char* Line::charName(char ch) {
char chName[34][39] = {
"Empty Line",
"Start Of Heading",
"Start Of Text",
"End Of Text",
"End Of Transmission",
"Enquiry",
"Acknoledge",
"Bell (\\a)",
"Backspace (\\b)",
"Tab (\\t)",
"New Line (\\n)",
"Vertical Tab",
"Form Feed (\\f)",
"Newline (\\n) or Carriage Retrun (\\r)",
"Shift out",
"Shift in",
"Data Link Escape",
"Device Control 1",
"Device Control 2",
"Device Control 3",
"Device Control 4",
"Negative Acknoledge",
"Synchronous Idle",
"End of Tran. Block",
"Cancel",
"End Of Medium",
"Substitude",
"Escape",
"File Separator",
"Groupu Separator",
"Record Separator",
"Unit Separator",
"Space",
"Non printable char"
};
if (ch >= 33) {
m_chName[0] = ch;
m_chName[1] = '\0';
ch = 33;
}
else {
copy(m_chName, chName[int(ch)]);
}
return m_chName;
}
std::ostream& operator<<(std::ostream& os, const Line& L) {
return L.display(os);
}
}