|
1 | 1 | #include "helpers.h"
|
2 | 2 |
|
3 | 3 | #include <fmt/format.h>
|
| 4 | +#include <fmt/xchar.h> |
4 | 5 | #include <jinja2cpp/error_info.h>
|
| 6 | +#include <iterator> |
5 | 7 |
|
6 | 8 | namespace
|
7 | 9 | {
|
@@ -110,146 +112,146 @@ template<typename CharT>
|
110 | 112 | void RenderErrorInfo(std::basic_string<CharT>& result, const ErrorInfoTpl<CharT>& errInfo)
|
111 | 113 | {
|
112 | 114 | using string_t = std::basic_string<CharT>;
|
113 |
| - fmt::basic_memory_buffer<CharT> out; |
| 115 | + auto out = fmt::basic_memory_buffer<CharT>(); |
114 | 116 |
|
115 | 117 | auto& loc = errInfo.GetErrorLocation();
|
116 | 118 |
|
117 |
| - fmt::format_to(out, UNIVERSAL_STR("{}:{}:{}: error: ").GetValue<CharT>(), ConvertString<string_t>(loc.fileName), loc.line, loc.col); |
| 119 | + fmt::format_to(std::back_inserter(out), UNIVERSAL_STR("{}:{}:{}: error: ").GetValue<CharT>(), ConvertString<string_t>(loc.fileName), loc.line, loc.col); |
118 | 120 | ErrorCode errCode = errInfo.GetCode();
|
119 | 121 | switch (errCode)
|
120 | 122 | {
|
121 | 123 | case ErrorCode::Unspecified:
|
122 |
| - format_to(out, UNIVERSAL_STR("Parse error").GetValue<CharT>()); |
| 124 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Parse error").GetValue<CharT>()); |
123 | 125 | break;
|
124 | 126 | case ErrorCode::UnexpectedException:
|
125 | 127 | {
|
126 | 128 | auto& extraParams = errInfo.GetExtraParams();
|
127 |
| - format_to(out, UNIVERSAL_STR("Unexpected exception occurred during template processing. Exception: {}").GetValue<CharT>(), extraParams[0]); |
| 129 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected exception occurred during template processing. Exception: {}").GetValue<CharT>(), extraParams[0]); |
128 | 130 | break;
|
129 | 131 | }
|
130 | 132 | case ErrorCode::MetadataParseError:
|
131 | 133 | {
|
132 | 134 | auto& extraParams = errInfo.GetExtraParams();
|
133 |
| - format_to(out, UNIVERSAL_STR("Error occurred during template metadata parsing. Error: {}").GetValue<CharT>(), extraParams[0]); |
| 135 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Error occurred during template metadata parsing. Error: {}").GetValue<CharT>(), extraParams[0]); |
134 | 136 | break;
|
135 | 137 | }
|
136 | 138 | case ErrorCode::YetUnsupported:
|
137 |
| - format_to(out, UNIVERSAL_STR("This feature has not been supported yet").GetValue<CharT>()); |
| 139 | + format_to(std::back_inserter(out), UNIVERSAL_STR("This feature has not been supported yet").GetValue<CharT>()); |
138 | 140 | break;
|
139 | 141 | case ErrorCode::FileNotFound:
|
140 |
| - format_to(out, UNIVERSAL_STR("File not found").GetValue<CharT>()); |
| 142 | + format_to(std::back_inserter(out), UNIVERSAL_STR("File not found").GetValue<CharT>()); |
141 | 143 | break;
|
142 | 144 | case ErrorCode::ExpectedStringLiteral:
|
143 |
| - format_to(out, UNIVERSAL_STR("String expected").GetValue<CharT>()); |
| 145 | + format_to(std::back_inserter(out), UNIVERSAL_STR("String expected").GetValue<CharT>()); |
144 | 146 | break;
|
145 | 147 | case ErrorCode::ExpectedIdentifier:
|
146 |
| - format_to(out, UNIVERSAL_STR("Identifier expected").GetValue<CharT>()); |
| 148 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Identifier expected").GetValue<CharT>()); |
147 | 149 | break;
|
148 | 150 | case ErrorCode::ExpectedSquareBracket:
|
149 |
| - format_to(out, UNIVERSAL_STR("']' expected").GetValue<CharT>()); |
| 151 | + format_to(std::back_inserter(out), UNIVERSAL_STR("']' expected").GetValue<CharT>()); |
150 | 152 | break;
|
151 | 153 | case ErrorCode::ExpectedRoundBracket:
|
152 |
| - format_to(out, UNIVERSAL_STR("')' expected").GetValue<CharT>()); |
| 154 | + format_to(std::back_inserter(out), UNIVERSAL_STR("')' expected").GetValue<CharT>()); |
153 | 155 | break;
|
154 | 156 | case ErrorCode::ExpectedCurlyBracket:
|
155 |
| - format_to(out, UNIVERSAL_STR("'}}' expected").GetValue<CharT>()); |
| 157 | + format_to(std::back_inserter(out), UNIVERSAL_STR("'}}' expected").GetValue<CharT>()); |
156 | 158 | break;
|
157 | 159 | case ErrorCode::ExpectedToken:
|
158 | 160 | {
|
159 | 161 | auto& extraParams = errInfo.GetExtraParams();
|
160 |
| - format_to(out, UNIVERSAL_STR("Unexpected token '{}'").GetValue<CharT>(), extraParams[0]); |
| 162 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected token '{}'").GetValue<CharT>(), extraParams[0]); |
161 | 163 | if (extraParams.size() > 1)
|
162 | 164 | {
|
163 |
| - format_to(out, UNIVERSAL_STR(". Expected: ").GetValue<CharT>()); |
| 165 | + format_to(std::back_inserter(out), UNIVERSAL_STR(". Expected: ").GetValue<CharT>()); |
164 | 166 | for (std::size_t i = 1; i < extraParams.size(); ++ i)
|
165 | 167 | {
|
166 | 168 | if (i != 1)
|
167 |
| - format_to(out, UNIVERSAL_STR(", ").GetValue<CharT>()); |
168 |
| - format_to(out, UNIVERSAL_STR("\'{}\'").GetValue<CharT>(), extraParams[i]); |
| 169 | + format_to(std::back_inserter(out), UNIVERSAL_STR(", ").GetValue<CharT>()); |
| 170 | + format_to(std::back_inserter(out), UNIVERSAL_STR("\'{}\'").GetValue<CharT>(), extraParams[i]); |
169 | 171 | }
|
170 | 172 | }
|
171 | 173 | break;
|
172 | 174 | }
|
173 | 175 | case ErrorCode::ExpectedExpression:
|
174 | 176 | {
|
175 | 177 | auto& extraParams = errInfo.GetExtraParams();
|
176 |
| - format_to(out, UNIVERSAL_STR("Expected expression, got: '{}'").GetValue<CharT>(), extraParams[0]); |
| 178 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Expected expression, got: '{}'").GetValue<CharT>(), extraParams[0]); |
177 | 179 | break;
|
178 | 180 | }
|
179 | 181 | case ErrorCode::ExpectedEndOfStatement:
|
180 | 182 | {
|
181 | 183 | auto& extraParams = errInfo.GetExtraParams();
|
182 |
| - format_to(out, UNIVERSAL_STR("Expected end of statement, got: '{}'").GetValue<CharT>(), extraParams[0]); |
| 184 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Expected end of statement, got: '{}'").GetValue<CharT>(), extraParams[0]); |
183 | 185 | break;
|
184 | 186 | }
|
185 | 187 | case ErrorCode::ExpectedRawEnd:
|
186 |
| - format_to(out, UNIVERSAL_STR("Expected end of raw block").GetValue<CharT>()); |
| 188 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Expected end of raw block").GetValue<CharT>()); |
187 | 189 | break;
|
188 | 190 | case ErrorCode::ExpectedMetaEnd:
|
189 |
| - format_to(out, UNIVERSAL_STR("Expected end of meta block").GetValue<CharT>()); |
| 191 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Expected end of meta block").GetValue<CharT>()); |
190 | 192 | break;
|
191 | 193 | case ErrorCode::UnexpectedToken:
|
192 | 194 | {
|
193 | 195 | auto& extraParams = errInfo.GetExtraParams();
|
194 |
| - format_to(out, UNIVERSAL_STR("Unexpected token: '{}'").GetValue<CharT>(), extraParams[0]); |
| 196 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected token: '{}'").GetValue<CharT>(), extraParams[0]); |
195 | 197 | break;
|
196 | 198 | }
|
197 | 199 | case ErrorCode::UnexpectedStatement:
|
198 | 200 | {
|
199 | 201 | auto& extraParams = errInfo.GetExtraParams();
|
200 |
| - format_to(out, UNIVERSAL_STR("Unexpected statement: '{}'").GetValue<CharT>(), extraParams[0]); |
| 202 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected statement: '{}'").GetValue<CharT>(), extraParams[0]); |
201 | 203 | break;
|
202 | 204 | }
|
203 | 205 | case ErrorCode::UnexpectedCommentBegin:
|
204 |
| - format_to(out, UNIVERSAL_STR("Unexpected comment begin").GetValue<CharT>()); |
| 206 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected comment begin").GetValue<CharT>()); |
205 | 207 | break;
|
206 | 208 | case ErrorCode::UnexpectedCommentEnd:
|
207 |
| - format_to(out, UNIVERSAL_STR("Unexpected comment end").GetValue<CharT>()); |
| 209 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected comment end").GetValue<CharT>()); |
208 | 210 | break;
|
209 | 211 | case ErrorCode::UnexpectedRawBegin:
|
210 |
| - format_to(out, UNIVERSAL_STR("Unexpected raw block begin").GetValue<CharT>()); |
| 212 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected raw block begin").GetValue<CharT>()); |
211 | 213 | break;
|
212 | 214 | case ErrorCode::UnexpectedRawEnd:
|
213 |
| - format_to(out, UNIVERSAL_STR("Unexpected raw block end").GetValue<CharT>()); |
| 215 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected raw block end").GetValue<CharT>()); |
214 | 216 | break;
|
215 | 217 | case ErrorCode::UnexpectedMetaBegin:
|
216 |
| - format_to(out, UNIVERSAL_STR("Unexpected meta block begin").GetValue<CharT>()); |
| 218 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected meta block begin").GetValue<CharT>()); |
217 | 219 | break;
|
218 | 220 | case ErrorCode::UnexpectedMetaEnd:
|
219 |
| - format_to(out, UNIVERSAL_STR("Unexpected meta block end").GetValue<CharT>()); |
| 221 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected meta block end").GetValue<CharT>()); |
220 | 222 | break;
|
221 | 223 | case ErrorCode::UnexpectedExprBegin:
|
222 |
| - format_to(out, UNIVERSAL_STR("Unexpected expression block begin").GetValue<CharT>()); |
| 224 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected expression block begin").GetValue<CharT>()); |
223 | 225 | break;
|
224 | 226 | case ErrorCode::UnexpectedExprEnd:
|
225 |
| - format_to(out, UNIVERSAL_STR("Unexpected expression block end").GetValue<CharT>()); |
| 227 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected expression block end").GetValue<CharT>()); |
226 | 228 | break;
|
227 | 229 | case ErrorCode::UnexpectedStmtBegin:
|
228 |
| - format_to(out, UNIVERSAL_STR("Unexpected statement block begin").GetValue<CharT>()); |
| 230 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected statement block begin").GetValue<CharT>()); |
229 | 231 | break;
|
230 | 232 | case ErrorCode::UnexpectedStmtEnd:
|
231 |
| - format_to(out, UNIVERSAL_STR("Unexpected statement block end").GetValue<CharT>()); |
| 233 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected statement block end").GetValue<CharT>()); |
232 | 234 | break;
|
233 | 235 | case ErrorCode::TemplateNotParsed:
|
234 |
| - format_to(out, UNIVERSAL_STR("Template not parsed").GetValue<CharT>()); |
| 236 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Template not parsed").GetValue<CharT>()); |
235 | 237 | break;
|
236 | 238 | case ErrorCode::TemplateNotFound:
|
237 |
| - format_to(out, UNIVERSAL_STR("Template(s) not found: {}").GetValue<CharT>(), errInfo.GetExtraParams()[0]); |
| 239 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Template(s) not found: {}").GetValue<CharT>(), errInfo.GetExtraParams()[0]); |
238 | 240 | break;
|
239 | 241 | case ErrorCode::InvalidTemplateName:
|
240 |
| - format_to(out, UNIVERSAL_STR("Invalid template name: {}").GetValue<CharT>(), errInfo.GetExtraParams()[0]); |
| 242 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Invalid template name: {}").GetValue<CharT>(), errInfo.GetExtraParams()[0]); |
241 | 243 | break;
|
242 | 244 | case ErrorCode::InvalidValueType:
|
243 |
| - format_to(out, UNIVERSAL_STR("Invalid value type").GetValue<CharT>()); |
| 245 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Invalid value type").GetValue<CharT>()); |
244 | 246 | break;
|
245 | 247 | case ErrorCode::ExtensionDisabled:
|
246 |
| - format_to(out, UNIVERSAL_STR("Extension disabled").GetValue<CharT>()); |
| 248 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Extension disabled").GetValue<CharT>()); |
247 | 249 | break;
|
248 | 250 | case ErrorCode::TemplateEnvAbsent:
|
249 |
| - format_to(out, UNIVERSAL_STR("Template environment doesn't set").GetValue<CharT>()); |
| 251 | + format_to(std::back_inserter(out), UNIVERSAL_STR("Template environment doesn't set").GetValue<CharT>()); |
250 | 252 | break;
|
251 | 253 | }
|
252 |
| - format_to(out, UNIVERSAL_STR("\n{}").GetValue<CharT>(), errInfo.GetLocationDescr()); |
| 254 | + format_to(std::back_inserter(out), UNIVERSAL_STR("\n{}").GetValue<CharT>(), errInfo.GetLocationDescr()); |
253 | 255 | result = to_string(out);
|
254 | 256 | }
|
255 | 257 |
|
|
0 commit comments