MCPcopy Create free account
hub / github.com/SmingHub/Sming / evaluate

Method evaluate

Sming/Core/Data/Stream/SectionTemplate.cpp:300–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300String SectionTemplate::evaluate(char*& expr)
301{
302 if(*expr != '!') {
303 auto sep = findSep(expr);
304 if(sep == nullptr) {
305 sep = expr + strlen(expr);
306 } else {
307 *sep = '\0';
308 }
309 String s = getValue(expr);
310 *sep = '_';
311 expr = sep + 1;
312 return s;
313 }
314
315 auto exprStart = expr;
316 *expr = 'Q';
317
318 // Process conditional expressions such as {length:varname}, {width:10:text to pad}
319 ArgList args(*this);
320
321 auto ptr = findSep(expr + 1);
322 if(*ptr == '}') {
323 *ptr++ = '\0';
324 } else if(*ptr != '\0') {
325 // {cmd} or {cmd:value...}
326 *ptr++ = '\0'; // Terminate cmd
327 ptr = args.parse(ptr);
328 }
329
330 int i = commandStrings.indexOf(expr);
331 auto field = Command(i + 1);
332
333 expr = ptr;
334
335 switch(field) {
336 case Command::Qunknown:
337 break;
338
339 case Command::Qas_int:
340 return String(args[0].toInt());
341
342 case Command::Qas_float:
343 return String(args[0].toFloat());
344
345 case Command::Qas_string: {
346 /*
347 * TODO: Find/write strQuote() helper function to ensure any containing quotes are escaped.
348 * This will be format-specific so perhaps another callback or look at putting Stream/Format
349 * functions into classes.
350 */
351 String s;
352 s += '"';
353 s += args[0];
354 s += '"';
355 return s;
356 }
357

Callers 1

parseMethod · 0.45

Calls 15

findSepFunction · 0.85
asCharMethod · 0.80
setLengthMethod · 0.80
reserveMethod · 0.80
subMethod · 0.80
getSectionMethod · 0.80
CommandEnum · 0.70
getValueFunction · 0.50
StringClass · 0.50
fromFullFileNameFunction · 0.50
parseMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected