Skip to content

Commit 9d8ebd6

Browse files
committed
Update minja from google/minja#27
1 parent ff2cce5 commit 9d8ebd6

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

common/minja.hpp

+10-16
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
#include <unordered_set>
1919
#include <json.hpp>
2020

21-
#ifdef _WIN32
22-
#define ENDL "\r\n"
23-
#else
24-
#define ENDL "\n"
25-
#endif
26-
2721
using json = nlohmann::ordered_json;
2822

2923
namespace minja {
@@ -38,7 +32,7 @@ struct Options {
3832

3933
struct ArgumentsValue;
4034

41-
static std::string normalize_newlines(const std::string & s) {
35+
inline std::string normalize_newlines(const std::string & s) {
4236
#ifdef _WIN32
4337
static const std::regex nl_regex("\r\n");
4438
return std::regex_replace(s, nl_regex, "\n");
@@ -91,7 +85,7 @@ class Value : public std::enable_shared_from_this<Value> {
9185
void dump(std::ostringstream & out, int indent = -1, int level = 0, bool to_json = false) const {
9286
auto print_indent = [&](int level) {
9387
if (indent > 0) {
94-
out << ENDL;
88+
out << "\n";
9589
for (int i = 0, n = level * indent; i < n; ++i) out << ' ';
9690
}
9791
};
@@ -594,11 +588,11 @@ static std::string error_location_suffix(const std::string & source, size_t pos)
594588
auto max_line = std::count(start, end, '\n') + 1;
595589
auto col = pos - std::string(start, it).rfind('\n');
596590
std::ostringstream out;
597-
out << " at row " << line << ", column " << col << ":" ENDL;
598-
if (line > 1) out << get_line(line - 1) << ENDL;
599-
out << get_line(line) << ENDL;
600-
out << std::string(col - 1, ' ') << "^" << ENDL;
601-
if (line < max_line) out << get_line(line + 1) << ENDL;
591+
out << " at row " << line << ", column " << col << ":\n";
592+
if (line > 1) out << get_line(line - 1) << "\n";
593+
out << get_line(line) << "\n";
594+
out << std::string(col - 1, ' ') << "^\n";
595+
if (line < max_line) out << get_line(line + 1) << "\n";
602596

603597
return out.str();
604598
}
@@ -833,7 +827,7 @@ class TemplateNode {
833827
std::string render(const std::shared_ptr<Context> & context) const {
834828
std::ostringstream out;
835829
render(out, context);
836-
return normalize_newlines(out.str());
830+
return out.str();
837831
}
838832
};
839833

@@ -2695,11 +2689,11 @@ inline std::shared_ptr<Context> Context::builtins() {
26952689
while (std::getline(iss, line, '\n')) {
26962690
auto needs_indent = !is_first || first;
26972691
if (is_first) is_first = false;
2698-
else out += ENDL;
2692+
else out += "\n";
26992693
if (needs_indent) out += indent;
27002694
out += line;
27012695
}
2702-
if (!text.empty() && text.back() == '\n') out += ENDL;
2696+
if (!text.empty() && text.back() == '\n') out += "\n";
27032697
return out;
27042698
}));
27052699
globals.set("selectattr", Value::callable([=](const std::shared_ptr<Context> & context, ArgumentsValue & args) {

0 commit comments

Comments
 (0)