mirror of
https://github.com/pantor/inja.git
synced 2026-10-08 13:27:18 +00:00
clang-tidy applied and CMake installation of the single header added (#287)
* Fixed headers and linter marks applied Headers were wrong. Applied some linter suggestions. There are still many left. * CMake adjusted for single header CMake can now install the single header. Removed an unneeded header. --------- Co-authored-by: Berscheid <1885260+pantor@users.noreply.github.com>
This commit is contained in:
1 parent
1281271fda
commit
92994bec0a
17 files changed
+163
-71
No files matched your search
@@ -3,17 +3,16 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "function_storage.hpp"
|
||||
#include "inja.hpp"
|
||||
#include "parser.hpp"
|
||||
#include "renderer.hpp"
|
||||
#include "template.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace inja {
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef INCLUDE_INJA_EXCEPTIONS_HPP_
|
||||
#define INCLUDE_INJA_EXCEPTIONS_HPP_
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#ifndef INCLUDE_INJA_FUNCTION_STORAGE_HPP_
|
||||
#define INCLUDE_INJA_FUNCTION_STORAGE_HPP_
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "inja.hpp"
|
||||
|
||||
namespace inja {
|
||||
|
||||
using Arguments = std::vector<const json*>;
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#define INCLUDE_INJA_LEXER_HPP_
|
||||
|
||||
#include <cctype>
|
||||
#include <locale>
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "exceptions.hpp"
|
||||
#include "token.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
@@ -311,7 +313,7 @@ public:
|
||||
pos += open_start;
|
||||
|
||||
// try to match one of the opening sequences, and get the close
|
||||
std::string_view open_str = m_in.substr(pos);
|
||||
const std::string_view open_str = m_in.substr(pos);
|
||||
bool must_lstrip = false;
|
||||
if (inja::string_view::starts_with(open_str, config.expression_open)) {
|
||||
if (inja::string_view::starts_with(open_str, config.expression_open_force_lstrip)) {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#ifndef INCLUDE_INJA_NODE_HPP_
|
||||
#define INCLUDE_INJA_NODE_HPP_
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "function_storage.hpp"
|
||||
#include "inja.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace inja {
|
||||
|
||||
+13
-9
@@ -1,20 +1,24 @@
|
||||
#ifndef INCLUDE_INJA_PARSER_HPP_
|
||||
#define INCLUDE_INJA_PARSER_HPP_
|
||||
|
||||
#include <limits>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "exceptions.hpp"
|
||||
#include "function_storage.hpp"
|
||||
#include "inja.hpp"
|
||||
#include "lexer.hpp"
|
||||
#include "node.hpp"
|
||||
#include "template.hpp"
|
||||
#include "token.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace inja {
|
||||
|
||||
@@ -64,7 +68,7 @@ class Parser {
|
||||
}
|
||||
|
||||
inline void add_literal(Arguments &arguments, const char* content_ptr) {
|
||||
std::string_view data_text(literal_start.data(), tok.text.data() - literal_start.data() + tok.text.size());
|
||||
const std::string_view data_text(literal_start.data(), tok.text.data() - literal_start.data() + tok.text.size());
|
||||
arguments.emplace_back(std::make_shared<LiteralNode>(data_text, data_text.data() - content_ptr));
|
||||
}
|
||||
|
||||
@@ -88,8 +92,8 @@ class Parser {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string original_path = static_cast<std::string>(path);
|
||||
std::string original_name = template_name;
|
||||
const std::string original_path = static_cast<std::string>(path);
|
||||
const std::string original_name = template_name;
|
||||
|
||||
if (config.search_included_templates_in_files) {
|
||||
// Build the relative path
|
||||
@@ -103,7 +107,7 @@ class Parser {
|
||||
std::ifstream file;
|
||||
file.open(template_name);
|
||||
if (!file.fail()) {
|
||||
std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
const std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
|
||||
auto include_template = Template(text);
|
||||
template_storage.emplace(template_name, include_template);
|
||||
@@ -472,7 +476,7 @@ class Parser {
|
||||
throw_parser_error("expected id, got '" + tok.describe() + "'");
|
||||
}
|
||||
|
||||
Token key_token = std::move(value_token);
|
||||
const Token key_token = std::move(value_token);
|
||||
value_token = tok;
|
||||
get_next_token();
|
||||
|
||||
@@ -533,7 +537,7 @@ class Parser {
|
||||
throw_parser_error("expected variable name, got '" + tok.describe() + "'");
|
||||
}
|
||||
|
||||
std::string key = static_cast<std::string>(tok.text);
|
||||
const std::string key = static_cast<std::string>(tok.text);
|
||||
get_next_token();
|
||||
|
||||
auto set_statement_node = std::make_shared<SetStatementNode>(key, tok.text.data() - tmpl.content.c_str());
|
||||
@@ -627,7 +631,7 @@ public:
|
||||
}
|
||||
|
||||
void parse_into_template(Template& tmpl, std::string_view filename) {
|
||||
std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1);
|
||||
const std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1);
|
||||
|
||||
// StringRef path = sys::path::parent_path(filename);
|
||||
auto sub_parser = Parser(config, lexer.get_config(), template_storage, function_storage);
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
#define INCLUDE_INJA_RENDERER_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "exceptions.hpp"
|
||||
#include "function_storage.hpp"
|
||||
#include "inja.hpp"
|
||||
#include "node.hpp"
|
||||
#include "template.hpp"
|
||||
#include "utils.hpp"
|
||||
@@ -69,7 +79,7 @@ class Renderer : public NodeVisitor {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void print_data(const std::shared_ptr<json> value) {
|
||||
void print_data(const std::shared_ptr<json>& value) {
|
||||
if (value->is_string()) {
|
||||
if (config.html_autoescape) {
|
||||
*output_stream << htmlescape(value->get_ref<const json::string_t&>());
|
||||
@@ -107,7 +117,7 @@ class Renderer : public NodeVisitor {
|
||||
throw_renderer_error("expression could not be evaluated", expression_list);
|
||||
}
|
||||
|
||||
auto node = not_found_stack.top();
|
||||
const auto node = not_found_stack.top();
|
||||
not_found_stack.pop();
|
||||
|
||||
throw_renderer_error("variable '" + static_cast<std::string>(node->name) + "' not found", *node);
|
||||
@@ -116,7 +126,7 @@ class Renderer : public NodeVisitor {
|
||||
}
|
||||
|
||||
void throw_renderer_error(const std::string& message, const AstNode& node) {
|
||||
SourceLocation loc = get_source_location(current_template->content, node.pos);
|
||||
const SourceLocation loc = get_source_location(current_template->content, node.pos);
|
||||
INJA_THROW(RenderError(message, loc));
|
||||
}
|
||||
|
||||
@@ -158,7 +168,7 @@ class Renderer : public NodeVisitor {
|
||||
|
||||
template <bool throw_not_found = true> Arguments get_argument_vector(const FunctionNode& node) {
|
||||
const size_t N = node.arguments.size();
|
||||
for (auto a : node.arguments) {
|
||||
for (const auto& a : node.arguments) {
|
||||
a->accept(*this);
|
||||
}
|
||||
|
||||
@@ -184,7 +194,7 @@ class Renderer : public NodeVisitor {
|
||||
}
|
||||
|
||||
void visit(const BlockNode& node) {
|
||||
for (auto& n : node.nodes) {
|
||||
for (const auto& n : node.nodes) {
|
||||
n->accept(*this);
|
||||
|
||||
if (break_rendering) {
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace inja {
|
||||
*/
|
||||
class StatisticsVisitor : public NodeVisitor {
|
||||
void visit(const BlockNode& node) {
|
||||
for (auto& n : node.nodes) {
|
||||
for (const auto& n : node.nodes) {
|
||||
n->accept(*this);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class StatisticsVisitor : public NodeVisitor {
|
||||
}
|
||||
|
||||
void visit(const FunctionNode& node) {
|
||||
for (auto& n : node.arguments) {
|
||||
for (const auto& n : node.arguments) {
|
||||
n->accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "node.hpp"
|
||||
#include "statistics.hpp"
|
||||
@@ -23,7 +22,7 @@ struct Template {
|
||||
explicit Template(const std::string& content): content(content) {}
|
||||
|
||||
/// Return number of variables (total number, not distinct ones) in the template
|
||||
int count_variables() {
|
||||
int count_variables() const {
|
||||
auto statistic_visitor = StatisticsVisitor();
|
||||
root.accept(statistic_visitor);
|
||||
return statistic_visitor.variable_counter;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define INCLUDE_INJA_UTILS_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@@ -19,7 +19,7 @@ inline std::string_view slice(std::string_view view, size_t start, size_t end) {
|
||||
}
|
||||
|
||||
inline std::pair<std::string_view, std::string_view> split(std::string_view view, char Separator) {
|
||||
size_t idx = view.find(Separator);
|
||||
const size_t idx = view.find(Separator);
|
||||
if (idx == std::string_view::npos) {
|
||||
return std::make_pair(view, std::string_view());
|
||||
}
|
||||
@@ -34,7 +34,7 @@ inline bool starts_with(std::string_view view, std::string_view prefix) {
|
||||
inline SourceLocation get_source_location(std::string_view content, size_t pos) {
|
||||
// Get line and offset position (starts at 1:1)
|
||||
auto sliced = string_view::slice(content, 0, pos);
|
||||
std::size_t last_newline = sliced.rfind("\n");
|
||||
const std::size_t last_newline = sliced.rfind('\n');
|
||||
|
||||
if (last_newline == std::string_view::npos) {
|
||||
return {1, sliced.length() + 1};
|
||||
@@ -44,7 +44,7 @@ inline SourceLocation get_source_location(std::string_view content, size_t pos)
|
||||
size_t count_lines = 0;
|
||||
size_t search_start = 0;
|
||||
while (search_start <= sliced.size()) {
|
||||
search_start = sliced.find("\n", search_start) + 1;
|
||||
search_start = sliced.find('\n', search_start) + 1;
|
||||
if (search_start == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user