Skip to content

Commit eb04bfc

Browse files
committed
clang-format
1 parent 81cfa14 commit eb04bfc

19 files changed

+556
-610
lines changed

.clang-format

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
---
2+
BasedOnStyle: LLVM
3+
IndentWidth: 2
4+
ColumnLimit: 160
5+
16
---
27
Language: Cpp
38

4-
BasedOnStyle: LLVM
5-
ColumnLimit: 120
69
SpaceBeforeCpp11BracedList: true
10+
PointerAlignment: Left
11+
AllowShortFunctionsOnASingleLine: Empty
12+
AllowShortBlocksOnASingleLine: Empty
13+
SpaceBeforeCtorInitializerColon: false
714
...

include/inja/environment.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ class Environment {
3232
TemplateStorage template_storage;
3333

3434
public:
35-
Environment() : Environment("") {}
35+
Environment(): Environment("") {}
3636

37-
explicit Environment(const std::string& global_path) : input_path(global_path), output_path(global_path) {}
37+
explicit Environment(const std::string& global_path): input_path(global_path), output_path(global_path) {}
3838

39-
Environment(const std::string& input_path, const std::string& output_path)
40-
: input_path(input_path), output_path(output_path) {}
39+
Environment(const std::string& input_path, const std::string& output_path): input_path(input_path), output_path(output_path) {}
4140

4241
/// Sets the opener and closer for template statements
4342
void set_statement(const std::string& open, const std::string& close) {
@@ -109,7 +108,9 @@ class Environment {
109108
return parse_template(filename);
110109
}
111110

112-
std::string render(std::string_view input, const json& data) { return render(parse(input), data); }
111+
std::string render(std::string_view input, const json& data) {
112+
return render(parse(input), data);
113+
}
113114

114115
std::string render(const Template& tmpl, const json& data) {
115116
std::stringstream os;
@@ -138,8 +139,7 @@ class Environment {
138139
file.close();
139140
}
140141

141-
void write_with_json_file(const std::string& filename, const std::string& filename_data,
142-
const std::string& filename_out) {
142+
void write_with_json_file(const std::string& filename, const std::string& filename_data, const std::string& filename_out) {
143143
const json data = load_json(filename_data);
144144
write(filename, data, filename_out);
145145
}
@@ -195,7 +195,10 @@ class Environment {
195195
@brief Adds a void callback with given number or arguments
196196
*/
197197
void add_void_callback(const std::string& name, int num_args, const VoidCallbackFunction& callback) {
198-
function_storage.add_callback(name, num_args, [callback](Arguments& args) { callback(args); return json(); });
198+
function_storage.add_callback(name, num_args, [callback](Arguments& args) {
199+
callback(args);
200+
return json();
201+
});
199202
}
200203

201204
/** Includes a template with a given name into the environment.

include/inja/exceptions.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,29 @@ struct InjaError : public std::runtime_error {
1717

1818
const SourceLocation location;
1919

20-
explicit InjaError(const std::string &type, const std::string &message)
20+
explicit InjaError(const std::string& type, const std::string& message)
2121
: std::runtime_error("[inja.exception." + type + "] " + message), type(type), message(message), location({0, 0}) {}
2222

23-
explicit InjaError(const std::string &type, const std::string &message, SourceLocation location)
24-
: std::runtime_error("[inja.exception." + type + "] (at " + std::to_string(location.line) + ":" +
25-
std::to_string(location.column) + ") " + message),
23+
explicit InjaError(const std::string& type, const std::string& message, SourceLocation location)
24+
: std::runtime_error("[inja.exception." + type + "] (at " + std::to_string(location.line) + ":" + std::to_string(location.column) + ") " + message),
2625
type(type), message(message), location(location) {}
2726
};
2827

2928
struct ParserError : public InjaError {
30-
explicit ParserError(const std::string &message, SourceLocation location) : InjaError("parser_error", message, location) {}
29+
explicit ParserError(const std::string& message, SourceLocation location): InjaError("parser_error", message, location) {}
3130
};
3231

3332
struct RenderError : public InjaError {
34-
explicit RenderError(const std::string &message, SourceLocation location) : InjaError("render_error", message, location) {}
33+
explicit RenderError(const std::string& message, SourceLocation location): InjaError("render_error", message, location) {}
3534
};
3635

3736
struct FileError : public InjaError {
38-
explicit FileError(const std::string &message) : InjaError("file_error", message) {}
39-
explicit FileError(const std::string &message, SourceLocation location) : InjaError("file_error", message, location) {}
37+
explicit FileError(const std::string& message): InjaError("file_error", message) {}
38+
explicit FileError(const std::string& message, SourceLocation location): InjaError("file_error", message, location) {}
4039
};
4140

4241
struct DataError : public InjaError {
43-
explicit DataError(const std::string &message, SourceLocation location) : InjaError("data_error", message, location) {}
42+
explicit DataError(const std::string& message, SourceLocation location): InjaError("data_error", message, location) {}
4443
};
4544

4645
} // namespace inja

include/inja/function_storage.hpp

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <string_view>
55
#include <vector>
66

7-
87
namespace inja {
98

109
using Arguments = std::vector<const json*>;
@@ -69,7 +68,7 @@ class FunctionStorage {
6968
};
7069

7170
struct FunctionData {
72-
explicit FunctionData(const Operation& op, const CallbackFunction& cb = CallbackFunction{}) : operation(op), callback(cb) {}
71+
explicit FunctionData(const Operation& op, const CallbackFunction& cb = CallbackFunction {}): operation(op), callback(cb) {}
7372
const Operation operation;
7473
const CallbackFunction callback;
7574
};
@@ -78,60 +77,60 @@ class FunctionStorage {
7877
const int VARIADIC {-1};
7978

8079
std::map<std::pair<std::string, int>, FunctionData> function_storage = {
81-
{std::make_pair("at", 2), FunctionData { Operation::At }},
82-
{std::make_pair("default", 2), FunctionData { Operation::Default }},
83-
{std::make_pair("divisibleBy", 2), FunctionData { Operation::DivisibleBy }},
84-
{std::make_pair("even", 1), FunctionData { Operation::Even }},
85-
{std::make_pair("exists", 1), FunctionData { Operation::Exists }},
86-
{std::make_pair("existsIn", 2), FunctionData { Operation::ExistsInObject }},
87-
{std::make_pair("first", 1), FunctionData { Operation::First }},
88-
{std::make_pair("float", 1), FunctionData { Operation::Float }},
89-
{std::make_pair("int", 1), FunctionData { Operation::Int }},
90-
{std::make_pair("isArray", 1), FunctionData { Operation::IsArray }},
91-
{std::make_pair("isBoolean", 1), FunctionData { Operation::IsBoolean }},
92-
{std::make_pair("isFloat", 1), FunctionData { Operation::IsFloat }},
93-
{std::make_pair("isInteger", 1), FunctionData { Operation::IsInteger }},
94-
{std::make_pair("isNumber", 1), FunctionData { Operation::IsNumber }},
95-
{std::make_pair("isObject", 1), FunctionData { Operation::IsObject }},
96-
{std::make_pair("isString", 1), FunctionData { Operation::IsString }},
97-
{std::make_pair("last", 1), FunctionData { Operation::Last }},
98-
{std::make_pair("length", 1), FunctionData { Operation::Length }},
99-
{std::make_pair("lower", 1), FunctionData { Operation::Lower }},
100-
{std::make_pair("max", 1), FunctionData { Operation::Max }},
101-
{std::make_pair("min", 1), FunctionData { Operation::Min }},
102-
{std::make_pair("odd", 1), FunctionData { Operation::Odd }},
103-
{std::make_pair("range", 1), FunctionData { Operation::Range }},
104-
{std::make_pair("round", 2), FunctionData { Operation::Round }},
105-
{std::make_pair("sort", 1), FunctionData { Operation::Sort }},
106-
{std::make_pair("upper", 1), FunctionData { Operation::Upper }},
107-
{std::make_pair("super", 0), FunctionData { Operation::Super }},
108-
{std::make_pair("super", 1), FunctionData { Operation::Super }},
109-
{std::make_pair("join", 2), FunctionData { Operation::Join }},
80+
{std::make_pair("at", 2), FunctionData {Operation::At}},
81+
{std::make_pair("default", 2), FunctionData {Operation::Default}},
82+
{std::make_pair("divisibleBy", 2), FunctionData {Operation::DivisibleBy}},
83+
{std::make_pair("even", 1), FunctionData {Operation::Even}},
84+
{std::make_pair("exists", 1), FunctionData {Operation::Exists}},
85+
{std::make_pair("existsIn", 2), FunctionData {Operation::ExistsInObject}},
86+
{std::make_pair("first", 1), FunctionData {Operation::First}},
87+
{std::make_pair("float", 1), FunctionData {Operation::Float}},
88+
{std::make_pair("int", 1), FunctionData {Operation::Int}},
89+
{std::make_pair("isArray", 1), FunctionData {Operation::IsArray}},
90+
{std::make_pair("isBoolean", 1), FunctionData {Operation::IsBoolean}},
91+
{std::make_pair("isFloat", 1), FunctionData {Operation::IsFloat}},
92+
{std::make_pair("isInteger", 1), FunctionData {Operation::IsInteger}},
93+
{std::make_pair("isNumber", 1), FunctionData {Operation::IsNumber}},
94+
{std::make_pair("isObject", 1), FunctionData {Operation::IsObject}},
95+
{std::make_pair("isString", 1), FunctionData {Operation::IsString}},
96+
{std::make_pair("last", 1), FunctionData {Operation::Last}},
97+
{std::make_pair("length", 1), FunctionData {Operation::Length}},
98+
{std::make_pair("lower", 1), FunctionData {Operation::Lower}},
99+
{std::make_pair("max", 1), FunctionData {Operation::Max}},
100+
{std::make_pair("min", 1), FunctionData {Operation::Min}},
101+
{std::make_pair("odd", 1), FunctionData {Operation::Odd}},
102+
{std::make_pair("range", 1), FunctionData {Operation::Range}},
103+
{std::make_pair("round", 2), FunctionData {Operation::Round}},
104+
{std::make_pair("sort", 1), FunctionData {Operation::Sort}},
105+
{std::make_pair("upper", 1), FunctionData {Operation::Upper}},
106+
{std::make_pair("super", 0), FunctionData {Operation::Super}},
107+
{std::make_pair("super", 1), FunctionData {Operation::Super}},
108+
{std::make_pair("join", 2), FunctionData {Operation::Join}},
110109
};
111110

112111
public:
113112
void add_builtin(std::string_view name, int num_args, Operation op) {
114-
function_storage.emplace(std::make_pair(static_cast<std::string>(name), num_args), FunctionData { op });
113+
function_storage.emplace(std::make_pair(static_cast<std::string>(name), num_args), FunctionData {op});
115114
}
116115

117116
void add_callback(std::string_view name, int num_args, const CallbackFunction& callback) {
118-
function_storage.emplace(std::make_pair(static_cast<std::string>(name), num_args), FunctionData { Operation::Callback, callback });
117+
function_storage.emplace(std::make_pair(static_cast<std::string>(name), num_args), FunctionData {Operation::Callback, callback});
119118
}
120119

121120
FunctionData find_function(std::string_view name, int num_args) const {
122121
auto it = function_storage.find(std::make_pair(static_cast<std::string>(name), num_args));
123122
if (it != function_storage.end()) {
124123
return it->second;
125124

126-
// Find variadic function
125+
// Find variadic function
127126
} else if (num_args > 0) {
128127
it = function_storage.find(std::make_pair(static_cast<std::string>(name), VARIADIC));
129128
if (it != function_storage.end()) {
130129
return it->second;
131130
}
132131
}
133132

134-
return FunctionData { Operation::None };
133+
return FunctionData {Operation::None};
135134
}
136135
};
137136

include/inja/inja.hpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| || '_ \ | |/ _` | Licensed under the MIT License <http://opensource.org/licenses/MIT>.
55
| || | | || | (_| |
66
|___|_| |_|/ |\__,_| Copyright (c) 2018-2021 Lars Berscheid
7-
|__/
7+
|__/
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal
1010
in the Software without restriction, including without limitation the rights
@@ -29,24 +29,26 @@ SOFTWARE.
2929

3030
namespace inja {
3131
#ifndef INJA_DATA_TYPE
32-
using json = nlohmann::json;
32+
using json = nlohmann::json;
3333
#else
34-
using json = INJA_DATA_TYPE;
34+
using json = INJA_DATA_TYPE;
3535
#endif
36-
}
36+
} // namespace inja
3737

3838
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION)
39-
#ifndef INJA_THROW
40-
#define INJA_THROW(exception) throw exception
41-
#endif
39+
#ifndef INJA_THROW
40+
#define INJA_THROW(exception) throw exception
41+
#endif
4242
#else
43-
#include <cstdlib>
44-
#ifndef INJA_THROW
45-
#define INJA_THROW(exception) std::abort(); std::ignore = exception
46-
#endif
47-
#ifndef INJA_NOEXCEPTION
48-
#define INJA_NOEXCEPTION
49-
#endif
43+
#include <cstdlib>
44+
#ifndef INJA_THROW
45+
#define INJA_THROW(exception) \
46+
std::abort(); \
47+
std::ignore = exception
48+
#endif
49+
#ifndef INJA_NOEXCEPTION
50+
#define INJA_NOEXCEPTION
51+
#endif
5052
#endif
5153

5254
#include "environment.hpp"

include/inja/lexer.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Lexer {
4343
size_t tok_start;
4444
size_t pos;
4545

46-
4746
Token scan_body(std::string_view close, Token::Kind closeKind, std::string_view close_trim = std::string_view(), bool trim = false) {
4847
again:
4948
// skip whitespace (except for \n as it might be a close)
@@ -224,7 +223,9 @@ class Lexer {
224223
return make_token(Token::Kind::String);
225224
}
226225

227-
Token make_token(Token::Kind kind) const { return Token(kind, string_view::slice(m_in, tok_start, pos)); }
226+
Token make_token(Token::Kind kind) const {
227+
return Token(kind, string_view::slice(m_in, tok_start, pos));
228+
}
228229

229230
void skip_whitespaces_and_newlines() {
230231
if (pos < m_in.size()) {
@@ -270,7 +271,7 @@ class Lexer {
270271
}
271272

272273
public:
273-
explicit Lexer(const LexerConfig& config) : config(config), state(State::Text), minus_state(MinusState::Number) {}
274+
explicit Lexer(const LexerConfig& config): config(config), state(State::Text), minus_state(MinusState::Number) {}
274275

275276
SourceLocation current_position() const {
276277
return get_source_location(m_in, tok_start);
@@ -322,7 +323,7 @@ class Lexer {
322323
} else if (inja::string_view::starts_with(open_str, config.statement_open)) {
323324
if (inja::string_view::starts_with(open_str, config.statement_open_no_lstrip)) {
324325
state = State::StatementStartNoLstrip;
325-
} else if (inja::string_view::starts_with(open_str, config.statement_open_force_lstrip )) {
326+
} else if (inja::string_view::starts_with(open_str, config.statement_open_force_lstrip)) {
326327
state = State::StatementStartForceLstrip;
327328
must_lstrip = true;
328329
} else {

0 commit comments

Comments
 (0)