cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
help_formatter.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Help Formatter
4
5
Author: Daniel Kroening, dkr@amazon.com
6
7
\*******************************************************************/
8
9
#include "
help_formatter.h
"
10
11
#include "
console.h
"
12
13
#include <ostream>
14
15
void
help_formattert::emit_word
(
statet
&state, std::ostream &out)
16
{
17
if
(state.
word
.empty())
18
return
;
19
20
// screen width exceeded when aligning?
21
if
(state.
column
+ state.
word
.size() >
consolet::width
() && state.
aligning
)
22
{
23
out <<
'\n'
<< std::string(
first_column_width
+ 1,
' '
);
24
state.
column
=
first_column_width
+ 1;
25
}
26
27
out << state.
word
;
28
state.
column
+= state.
word
.size();
29
state.
word
.clear();
30
}
31
32
void
help_formattert::operator()
(std::ostream &out)
const
33
{
34
std::size_t
pos
= 0;
35
auto
next = [
this
, &
pos
]() ->
char
{
36
if
(
pos
<
s
.size())
37
return
s
[
pos
++];
38
else
39
return
0;
40
};
41
42
statet
state;
43
44
while
(
pos
<
s
.size())
45
{
46
auto
ch = next();
47
48
if
(ch ==
'{'
)
49
{
50
emit_word
(state, out);
51
52
auto
what = next();
53
// spaces in formatted text are non-breakable
54
while
(
pos
<
s
.size() && (ch = next()) !=
'}'
)
55
state.
word
+= ch;
56
57
switch
(what)
58
{
59
case
'b'
:
60
out <<
consolet::bold
;
61
break
;
62
case
'u'
:
63
out <<
consolet::underline
;
64
break
;
65
case
'y'
:
66
out <<
consolet::yellow
;
67
break
;
68
default
:
69
break
;
70
}
71
72
emit_word
(state, out);
73
out <<
consolet::reset
;
74
}
75
else
if
(ch ==
'\t'
)
76
{
77
emit_word
(state, out);
78
if
(state.
column
<
first_column_width
)
79
{
80
out << std::string(
first_column_width
- state.
column
,
' '
);
81
state.
column
=
first_column_width
;
82
}
83
state.
aligning
=
true
;
84
}
85
else
if
(ch ==
'\n'
)
86
{
87
emit_word
(state, out);
88
out <<
'\n'
;
89
state.
column
= 0;
90
state.
aligning
=
false
;
91
}
92
else
93
{
94
state.
word
+= ch;
95
if
(ch ==
' '
)
96
emit_word
(state, out);
97
}
98
}
99
100
emit_word
(state, out);
101
}
consolet::yellow
static std::ostream & yellow(std::ostream &)
Definition
console.cpp:136
consolet::underline
static std::ostream & underline(std::ostream &)
Definition
console.cpp:168
consolet::reset
static std::ostream & reset(std::ostream &)
Definition
console.cpp:176
consolet::width
static std::size_t width()
Definition
console.cpp:196
consolet::bold
static std::ostream & bold(std::ostream &)
Definition
console.cpp:152
help_formattert::first_column_width
static const std::size_t first_column_width
Definition
help_formatter.h:37
help_formattert::operator()
void operator()(std::ostream &) const
Definition
help_formatter.cpp:32
help_formattert::emit_word
static void emit_word(statet &, std::ostream &)
Definition
help_formatter.cpp:15
help_formattert::s
const std::string & s
Definition
help_formatter.h:25
console.h
Console.
help_formatter.h
Help Formatter.
pos
literalt pos(literalt a)
Definition
literal.h:194
help_formattert::statet
Definition
help_formatter.h:30
help_formattert::statet::column
std::size_t column
Definition
help_formatter.h:31
help_formattert::statet::word
std::string word
Definition
help_formatter.h:33
help_formattert::statet::aligning
bool aligning
Definition
help_formatter.h:32
util
help_formatter.cpp
Generated by
1.17.0