Skip to content

Commit 692175d

Browse files
committed
switch
1 parent 538c5c4 commit 692175d

6 files changed

Lines changed: 224 additions & 63 deletions

File tree

.uncrustify.cfg

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Uncrustify-0.80.1_f
2+
3+
# The original size of tabs in the input.
4+
#
5+
# Default: 8
6+
input_tab_size = 4 # unsigned number
7+
8+
# The size of tabs in the output (only used if align_with_tabs=true).
9+
#
10+
# Default: 8
11+
output_tab_size = 4 # unsigned number
12+
13+
# Add or remove space between 'while' and '('.
14+
sp_while_paren_open = add # ignore/add/remove/force
15+
16+
# Add or remove space around boolean operators '&&' and '||'.
17+
sp_bool = force # ignore/add/remove/force
18+
19+
# Add or remove space inside '(' and ')'.
20+
sp_inside_paren = remove # ignore/add/remove/force
21+
22+
# Add or remove space between nested parentheses, i.e. '((' vs. ') )'.
23+
sp_paren_paren = remove # ignore/add/remove/force
24+
25+
# Add or remove space between ')' and '{'.
26+
sp_paren_brace = force # ignore/add/remove/force
27+
28+
# Add or remove space between pointer stars '*'.
29+
sp_between_ptr_star = remove # ignore/add/remove/force
30+
31+
# Add or remove space before '<'.
32+
sp_before_angle = remove # ignore/add/remove/force
33+
34+
# Add or remove space inside '<' and '>'.
35+
sp_inside_angle = remove # ignore/add/remove/force
36+
37+
# Add or remove space after '>'.
38+
sp_after_angle = add # ignore/add/remove/force
39+
40+
# Add or remove space between '>' and '(' as found in 'new List<byte>(foo);'.
41+
sp_angle_paren = remove # ignore/add/remove/force
42+
43+
# Add or remove space between '>' and a word as in 'List<byte> m;' or
44+
# 'template <typename T> static ...'.
45+
sp_angle_word = add # ignore/add/remove/force
46+
47+
# Add or remove space between '>' and '>' in '>>' (template stuff).
48+
#
49+
# Default: add
50+
sp_angle_shift = ignore # ignore/add/remove/force
51+
52+
# (C++11) Permit removal of the space between '>>' in 'foo<bar<int> >'. Note
53+
# that sp_angle_shift cannot remove the space without this option.
54+
sp_permit_cpp11_shift = true # true/false
55+
56+
# Add or remove space before '(' of control statements ('if', 'for', 'switch',
57+
# 'while', etc.).
58+
sp_before_sparen = force # ignore/add/remove/force
59+
60+
# Add or remove space inside '(' and ')' of control statements.
61+
sp_inside_sparen = remove # ignore/add/remove/force
62+
63+
# Add or remove space after ')' of control statements.
64+
sp_after_sparen = force # ignore/add/remove/force
65+
66+
# Add or remove space between ')' and '{' of of control statements.
67+
sp_sparen_brace = force # ignore/add/remove/force
68+
69+
# Add or remove space before ';' in non-empty 'for' statements.
70+
sp_before_semi_for = remove # ignore/add/remove/force
71+
72+
# Add or remove space after the final semicolon of an empty part of a for
73+
# statement, as in 'for ( ; ; <here> )'.
74+
sp_after_semi_for_empty = remove # ignore/add/remove/force
75+
76+
# Add or remove space before '[]'.
77+
sp_before_squares = remove # ignore/add/remove/force
78+
79+
# Add or remove space before C++17 structured bindings.
80+
sp_cpp_before_struct_binding = ignore # ignore/add/remove/force
81+
82+
# Add or remove space inside a non-empty '[' and ']'.
83+
sp_inside_square = remove # ignore/add/remove/force
84+
85+
# Add or remove space after class ':'.
86+
sp_after_class_colon = force # ignore/add/remove/force
87+
88+
# Add or remove space before class ':'.
89+
sp_before_class_colon = force # ignore/add/remove/force
90+
91+
# Add or remove space inside '{}'.
92+
sp_inside_braces_empty = remove # ignore/add/remove/force
93+
94+
# Add or remove space between 'else' and '{' if on the same line.
95+
sp_else_brace = force # ignore/add/remove/force
96+
97+
# Add or remove space between '}' and 'else' if on the same line.
98+
sp_brace_else = force # ignore/add/remove/force
99+
100+
# Add or remove space before the '{' of a 'catch' statement, if the '{' and
101+
# 'catch' are on the same line, as in 'catch (decl) <here> {'.
102+
sp_catch_brace = force # ignore/add/remove/force
103+
104+
# Add or remove space between '}' and 'catch' if on the same line.
105+
sp_brace_catch = force # ignore/add/remove/force
106+
107+
# The number of columns to indent per level. Usually 2, 3, 4, or 8.
108+
#
109+
# Default: 8
110+
indent_columns = 4 # unsigned number
111+
112+
# How to use tabs when indenting code.
113+
#
114+
# 0: Spaces only
115+
# 1: Indent with tabs to brace level, align with spaces (default)
116+
# 2: Indent and align with tabs, using spaces when not on a tabstop
117+
#
118+
# Default: 1
119+
indent_with_tabs = 0 # unsigned number
120+
121+
# Whether to indent the body of a 'namespace'.
122+
indent_namespace = true # true/false
123+
124+
# Whether the 'class' body is indented.
125+
indent_class = true # true/false
126+
127+
# How to indent access specifiers that are followed by a
128+
# colon.
129+
#
130+
# >0: Absolute column where 1 is the leftmost column
131+
# <=0: Subtract from brace indent
132+
#
133+
# Default: 1
134+
indent_access_spec = -4 # number
135+
136+
# Whether to collapse empty blocks between '{' and '}' except for functions.
137+
# Use nl_collapse_empty_body_functions to specify how empty function braces
138+
# should be formatted.
139+
nl_collapse_empty_body = true # true/false
140+
141+
# Whether to collapse empty blocks between '{' and '}' for functions only.
142+
# If true, overrides nl_inside_empty_func.
143+
nl_collapse_empty_body_functions = true # true/false
144+
145+
# Whether to convert all tabs to spaces in comments. If false, tabs in
146+
# comments are left alone, unless used for indenting.
147+
cmt_convert_tab_to_spaces = true # true/false
148+
149+
# An offset value that controls the indentation of the body of a multiline #define.
150+
# 'body' refers to all the lines of a multiline #define except the first line.
151+
# Requires 'pp_ignore_define_body = false'.
152+
#
153+
# <0: Absolute column: the body indentation starts off at the specified column
154+
# (ex. -3 ==> the body is indented starting from column 3)
155+
# >=0: Relative to the column of the '#' of '#define'
156+
# (ex. 3 ==> the body is indented starting 3 columns at the right of '#')
157+
#
158+
# Default: 8
159+
pp_multiline_define_body_indent = 4 # number
160+
161+
# The value might be used twice:
162+
# - at the assignment
163+
# - at the opening brace
164+
#
165+
# To prevent the double use of the indentation value, use this option with the
166+
# value 'true'.
167+
#
168+
# true: indentation will be used only once
169+
# false: indentation will be used every time (default)
170+
indent_cpp_lambda_only_once = true # true/false

runastyle

Lines changed: 0 additions & 23 deletions
This file was deleted.

runastyle.bat

Lines changed: 0 additions & 26 deletions
This file was deleted.

runformat

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
# uncrustify-0.72 is used to format simplecpp and cppcheck source code.
4+
#
5+
# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.zip
6+
# It's important that all developers use the exact same version so we don't get a "format battle".
7+
# 2. Building:
8+
# - Linux: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make
9+
# - Windows: mkdir build && cd build && cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. && nmake
10+
# 3. Ensure that the binary "uncrustify" is found by runformat. Either:
11+
# - you can put uncrustify in your PATH
12+
# - you can create an environment variable UNCRUSTIFY that has the full path of the binary
13+
14+
UNCRUSTIFY_VERSION="0.72.0"
15+
UNCRUSTIFY="${UNCRUSTIFY-uncrustify}"
16+
17+
DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+')
18+
if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then
19+
echo "You should use version: ${UNCRUSTIFY_VERSION}"
20+
echo "Detected version: ${DETECTED_VERSION}"
21+
exit 1
22+
fi
23+
24+
# OS variables
25+
[ $(uname -s) = "Darwin" ] && export OSX=1 && export UNIX=1
26+
[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1
27+
uname -s | grep -q "_NT-" && export WINDOWS=1
28+
29+
if [ $OSX ]
30+
then
31+
export CPUCOUNT=$(sysctl -n hw.ncpu)
32+
elif [ $LINUX ]
33+
then
34+
export CPUCOUNT=$(nproc)
35+
else
36+
export CPUCOUNT="1"
37+
fi
38+
39+
$UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h

simplecpp.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#include <ctime>
2424
#include <exception>
2525
#include <fstream>
26-
#include <iostream>
26+
//#include <iostream>
2727
#include <istream>
2828
#include <limits>
2929
#include <list>
3030
#include <map>
31+
#include <ostream>
3132
#include <set>
3233
#include <sstream>
3334
#include <stack>
@@ -205,29 +206,29 @@ bool simplecpp::Token::endsWithOneOf(const char c[]) const
205206
return std::strchr(c, string[string.size() - 1U]) != nullptr;
206207
}
207208

208-
void simplecpp::Token::printAll() const
209+
void simplecpp::Token::printAll(std::ostream& ostr) const
209210
{
210211
const Token *tok = this;
211212
while (tok->previous)
212213
tok = tok->previous;
213214
for (; tok; tok = tok->next) {
214215
if (tok->previous) {
215-
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
216+
ostr << (sameline(tok, tok->previous) ? ' ' : '\n');
216217
}
217-
std::cout << tok->str();
218+
ostr << tok->str();
218219
}
219-
std::cout << std::endl;
220+
ostr << std::endl;
220221
}
221222

222-
void simplecpp::Token::printOut() const
223+
void simplecpp::Token::printOut(std::ostream& ostr) const
223224
{
224225
for (const Token *tok = this; tok; tok = tok->next) {
225226
if (tok != this) {
226-
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
227+
ostr << (sameline(tok, tok->previous) ? ' ' : '\n');
227228
}
228-
std::cout << tok->str();
229+
ostr << tok->str();
229230
}
230-
std::cout << std::endl;
231+
ostr << std::endl;
231232
}
232233

233234
// cppcheck-suppress noConstructor - we call init() in the inherited to initialize the private members
@@ -553,9 +554,9 @@ void simplecpp::TokenList::push_back(Token *tok)
553554
backToken = tok;
554555
}
555556

556-
void simplecpp::TokenList::dump() const
557+
void simplecpp::TokenList::dump(std::ostream& ostr) const
557558
{
558-
std::cout << stringify() << std::endl;
559+
ostr << stringify() << std::endl;
559560
}
560561

561562
std::string simplecpp::TokenList::stringify() const

simplecpp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ namespace simplecpp {
176176
return mExpandedFrom.find(m) != mExpandedFrom.end();
177177
}
178178

179-
void printAll() const;
180-
void printOut() const;
179+
void printAll(std::ostream& ostr) const;
180+
void printOut(std::ostream& ostr) const;
181181
private:
182182
TokenString string;
183183

@@ -235,7 +235,7 @@ namespace simplecpp {
235235
}
236236
void push_back(Token *tok);
237237

238-
void dump() const;
238+
void dump(std::ostream& ostr) const;
239239
std::string stringify() const;
240240

241241
void readfile(Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);

0 commit comments

Comments
 (0)