MQTTSuite
Loading...
Searching...
No Matches
inja Namespace Reference

Namespaces

namespace  string_view

Classes

class  FunctionStorage
 Class for builtin functions and user-defined callbacks. More...
struct  SourceLocation
struct  InjaError
struct  ParserError
struct  RenderError
struct  FileError
struct  DataError
class  NodeVisitor
class  AstNode
 Base node class for the abstract syntax tree (AST). More...
class  BlockNode
class  TextNode
class  ExpressionNode
class  LiteralNode
class  DataNode
class  FunctionNode
class  ExpressionListNode
class  StatementNode
class  ForStatementNode
class  ForArrayStatementNode
class  ForObjectStatementNode
class  IfStatementNode
class  IncludeStatementNode
class  ExtendsStatementNode
class  BlockStatementNode
class  SetStatementNode
class  StatisticsVisitor
 A class for counting statistics on a Template. More...
struct  Template
 The main inja Template. More...
struct  LexerConfig
 Class for lexer configuration. More...
struct  ParserConfig
 Class for parser configuration. More...
struct  RenderConfig
 Class for render configuration. More...
struct  Token
 Helper-class for the inja Lexer. More...
class  Lexer
 Class for lexing an inja Template. More...
class  Parser
 Class for parsing an inja Template. More...
class  Renderer
 Class for rendering a Template with data. More...
class  Environment
 Class for changing the configuration. More...

Typedefs

using Arguments = std::vector<const nlohmann::json*>
using json = nlohmann::json
using CallbackFunction = std::function<json(Arguments& args)>
using VoidCallbackFunction = std::function<void(Arguments& args)>
using TemplateStorage = std::map<std::string, Template>

Functions

SourceLocation get_source_location (std::string_view content, size_t pos)
void replace_substring (std::string &s, const std::string &f, const std::string &t)
std::string htmlescape (const std::string &data)
 Escapes HTML.
std::string render (std::string_view input, const json &data)
 render with default settings to a string
void render_to (std::ostream &os, std::string_view input, const json &data)
 render with default settings to the given output stream

Typedef Documentation

◆ Arguments

typedef std::vector< const json * > inja::Arguments = std::vector<const nlohmann::json*>

Definition at line 57 of file MqttMapperPlugin.h.

◆ CallbackFunction

using inja::CallbackFunction = std::function<json(Arguments& args)>

Definition at line 121 of file inja.hpp.

◆ json

using inja::json = nlohmann::json

Definition at line 58 of file MqttMapperPlugin.h.

◆ TemplateStorage

using inja::TemplateStorage = std::map<std::string, Template>

Definition at line 931 of file inja.hpp.

◆ VoidCallbackFunction

using inja::VoidCallbackFunction = std::function<void(Arguments& args)>

Definition at line 122 of file inja.hpp.

Function Documentation

◆ get_source_location()

SourceLocation inja::get_source_location ( std::string_view content,
size_t pos )
inline

Definition at line 357 of file inja.hpp.

357 {
358 // Get line and offset position (starts at 1:1)
359 auto sliced = string_view::slice(content, 0, pos);
360 const std::size_t last_newline = sliced.rfind('\n');
361
362 if (last_newline == std::string_view::npos) {
363 return {1, sliced.length() + 1};
364 }
365
366 // Count newlines
367 size_t count_lines = 0;
368 size_t search_start = 0;
369 while (search_start <= sliced.size()) {
370 search_start = sliced.find('\n', search_start) + 1;
371 if (search_start == 0) {
372 break;
373 }
374 count_lines += 1;
375 }
376
377 return {count_lines + 1, sliced.length() - last_newline};
378 }
static void content(const std::string &contentEncoding, const std::string &contentMediaType, const json &instance)
std::string_view slice(std::string_view view, size_t start, size_t end)
Definition inja.hpp:338

References inja::string_view::slice().

Referenced by inja::Lexer::current_position(), and inja::Renderer::throw_renderer_error().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ htmlescape()

std::string inja::htmlescape ( const std::string & data)
inline

Escapes HTML.

Definition at line 2298 of file inja.hpp.

2298 {
2299 std::string buffer;
2300 buffer.reserve(data.size() + data.size() / 10);
2301 for (size_t pos = 0; pos != data.size(); ++pos) {
2302 switch (data[pos]) {
2303 case '&':
2304 buffer.append("&amp;");
2305 break;
2306 case '\"':
2307 buffer.append("&quot;");
2308 break;
2309 case '\'':
2310 buffer.append("&apos;");
2311 break;
2312 case '<':
2313 buffer.append("&lt;");
2314 break;
2315 case '>':
2316 buffer.append("&gt;");
2317 break;
2318 default:
2319 buffer.append(&data[pos], 1);
2320 break;
2321 }
2322 }
2323 return buffer;
2324 }

Referenced by inja::Renderer::print_data().

Here is the caller graph for this function:

◆ render()

std::string inja::render ( std::string_view input,
const json & data )
inline

render with default settings to a string

Definition at line 3209 of file inja.hpp.

3209 {
3210 return Environment().render(input, data);
3211 }
Class for changing the configuration.
Definition inja.hpp:2993
std::string render(std::string_view input, const json &data)
Definition inja.hpp:3093

References inja::Environment::Environment(), and inja::Environment::render().

Here is the call graph for this function:

◆ render_to()

void inja::render_to ( std::ostream & os,
std::string_view input,
const json & data )
inline

render with default settings to the given output stream

Definition at line 3216 of file inja.hpp.

3216 {
3217 Environment env;
3218 env.render_to(os, env.parse(input), data);
3219 }
std::ostream & render_to(std::ostream &os, const Template &tmpl, const json &data)
Definition inja.hpp:3135
Template parse(std::string_view input)
Definition inja.hpp:3077

References inja::Environment::parse(), and inja::Environment::render_to().

Here is the call graph for this function:

◆ replace_substring()

void inja::replace_substring ( std::string & s,
const std::string & f,
const std::string & t )
inline

Definition at line 380 of file inja.hpp.

380 {
381 if (f.empty()) {
382 return;
383 }
384 for (auto pos = s.find(f); // find first occurrence of f
385 pos != std::string::npos; // make sure f was found
386 s.replace(pos, f.size(), t), // replace with t, and
387 pos = s.find(f, pos + t.size())) // find next occurrence of f
388 {
389 }
390 }

Referenced by inja::Renderer::visit(), and inja::Renderer::visit().

Here is the caller graph for this function: