forked from andreasfertig/cppinsights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputFormatHelper.cpp
77 lines (61 loc) · 2.05 KB
/
OutputFormatHelper.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#include "OutputFormatHelper.h"
#include "InsightsHelpers.h"
//-----------------------------------------------------------------------------
namespace clang::insights {
static const std::string MakeIndent(const int indent)
{
std::string str{};
for(int i = 1; i < indent; i++) {
str += ' ';
}
return str;
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::Indent(unsigned count)
{
mOutput.append(MakeIndent(count + 1));
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::AppendParameterList(const ArrayRef<ParmVarDecl*> parameters, const NameOnly nameOnly)
{
ForEachArg(parameters, [&](const auto& p) {
const auto& name{GetName(*p)};
if(NameOnly::No == nameOnly) {
const auto& type{p->getType()};
Append(GetTypeNameAsParameter(type, name));
} else {
Append(name);
}
});
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::CloseScope(const NoNewLineBefore newLineBefore)
{
if(NoNewLineBefore::No == newLineBefore) {
NewLine();
}
RemoveIndent();
Append('}');
DecreaseIndent();
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::RemoveIndent()
{
/* After a newline we are already indented by one level to much. Try to decrease it. */
if(0 != mDefaultIndent) {
for(unsigned i = 0; i < SCOPE_INDENT; ++i) {
if(' ' != mOutput.back()) {
break;
}
mOutput.pop_back();
}
}
}
//-----------------------------------------------------------------------------
} // namespace clang::insights