From e339da7e2bcb31bf184fbc552cc5c1f850e0e6e2 Mon Sep 17 00:00:00 2001 From: pantor Date: Tue, 20 Mar 2018 17:00:33 +0100 Subject: [PATCH] Use references --- src/inja.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/inja.hpp b/src/inja.hpp index 33011be..57a233b 100644 --- a/src/inja.hpp +++ b/src/inja.hpp @@ -57,7 +57,7 @@ using json = nlohmann::json; /*! @brief throw an error with a given message */ -inline void inja_throw(std::string type, std::string message) { +inline void inja_throw(const std::string& type, const std::string& message) { throw std::runtime_error("[inja.exception." + type + "] " + message); } @@ -131,7 +131,7 @@ public: }; -inline Match search(const std::string& input, Regex regex, size_t position) { +inline Match search(const std::string& input, const Regex& regex, size_t position) { if (position >= input.length()) { return Match(); } Match match{position, regex}; @@ -141,7 +141,7 @@ inline Match search(const std::string& input, Regex regex, size_t position) { template -inline MatchType search(const std::string& input, std::map& regexes, size_t position) { +inline MatchType search(const std::string& input, const std::map& regexes, size_t position) { // Map to vectors std::vector class_vector; std::vector regexes_vector; @@ -208,7 +208,7 @@ inline MatchClosed search_closed(const std::string& input, const Regex& regex_st } template -inline MatchType match(const std::string& input, std::map regexes) { +inline MatchType match(const std::string& input, const std::map& regexes) { MatchType match; for (const auto e : regexes) { if (std::regex_match(input.cbegin(), input.cend(), match, e.second)) { @@ -545,7 +545,7 @@ public: for (unsigned int i = 0; i < list.size(); i++) { json data_loop = data; /* For nested loops, use parent/index */ - if (data_loop.count ("index") == 1 && data_loop.count ("index") == 1) { + if (data_loop.count("index") == 1 && data_loop.count("index1") == 1) { data_loop["parent"]["index"] = data_loop["index"]; data_loop["parent"]["index1"] = data_loop["index1"]; data_loop["parent"]["is_first"] = data_loop["is_first"]; @@ -602,7 +602,7 @@ public: /*! @brief create a corresponding regex for a function name with a number of arguments seperated by , */ - static Regex function_regex(std::string name, int number_arguments) { + static Regex function_regex(const std::string& name, int number_arguments) { std::string pattern = name; pattern.append("(?:\\("); for (int i = 0; i < number_arguments; i++) { @@ -619,7 +619,7 @@ public: /*! @brief dot notation to json pointer notiation */ - static std::string dot_to_json_pointer_notation(std::string dot) { + static std::string dot_to_json_pointer_notation(const std::string& dot) { std::string result = dot; while (result.find(".") != std::string::npos) { result.replace(result.find("."), 1, "/"); @@ -999,7 +999,7 @@ public: return j; } - void add_callback(std::string name, int number_arguments, std::function callback) { + void add_callback(std::string name, int number_arguments, const std::function& callback) { Parsed::CallbackSignature signature = std::make_pair(name, number_arguments); parser.regex_map_callbacks[signature] = Parser::function_regex(name, number_arguments); renderer.map_callbacks[signature] = callback;