18
18
#include < unordered_set>
19
19
#include < json.hpp>
20
20
21
- #ifdef _WIN32
22
- #define ENDL " \r\n "
23
- #else
24
- #define ENDL " \n "
25
- #endif
26
-
27
21
using json = nlohmann::ordered_json;
28
22
29
23
namespace minja {
@@ -38,7 +32,7 @@ struct Options {
38
32
39
33
struct ArgumentsValue ;
40
34
41
- static std::string normalize_newlines (const std::string & s) {
35
+ inline std::string normalize_newlines (const std::string & s) {
42
36
#ifdef _WIN32
43
37
static const std::regex nl_regex (" \r\n " );
44
38
return std::regex_replace (s, nl_regex, " \n " );
@@ -91,7 +85,7 @@ class Value : public std::enable_shared_from_this<Value> {
91
85
void dump (std::ostringstream & out, int indent = -1 , int level = 0 , bool to_json = false ) const {
92
86
auto print_indent = [&](int level) {
93
87
if (indent > 0 ) {
94
- out << ENDL ;
88
+ out << " \n " ;
95
89
for (int i = 0 , n = level * indent; i < n; ++i) out << ' ' ;
96
90
}
97
91
};
@@ -594,11 +588,11 @@ static std::string error_location_suffix(const std::string & source, size_t pos)
594
588
auto max_line = std::count (start, end, ' \n ' ) + 1 ;
595
589
auto col = pos - std::string (start, it).rfind (' \n ' );
596
590
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 " ;
602
596
603
597
return out.str ();
604
598
}
@@ -833,7 +827,7 @@ class TemplateNode {
833
827
std::string render (const std::shared_ptr<Context> & context) const {
834
828
std::ostringstream out;
835
829
render (out, context);
836
- return normalize_newlines ( out.str () );
830
+ return out.str ();
837
831
}
838
832
};
839
833
@@ -2695,11 +2689,11 @@ inline std::shared_ptr<Context> Context::builtins() {
2695
2689
while (std::getline (iss, line, ' \n ' )) {
2696
2690
auto needs_indent = !is_first || first;
2697
2691
if (is_first) is_first = false ;
2698
- else out += ENDL ;
2692
+ else out += " \n " ;
2699
2693
if (needs_indent) out += indent;
2700
2694
out += line;
2701
2695
}
2702
- if (!text.empty () && text.back () == ' \n ' ) out += ENDL ;
2696
+ if (!text.empty () && text.back () == ' \n ' ) out += " \n " ;
2703
2697
return out;
2704
2698
}));
2705
2699
globals.set (" selectattr" , Value::callable ([=](const std::shared_ptr<Context> & context, ArgumentsValue & args) {
0 commit comments