Refactor string-formatting routines to append to an existing string

This commit is contained in:
ISSOtm
2024-03-21 20:21:51 -04:00
committed by Sylvie
parent 52e8e1f9fc
commit 412073774c
4 changed files with 16 additions and 24 deletions

View File

@@ -1170,20 +1170,20 @@ static char const *readInterpolation(size_t depth) {
// Don't return before `lexerState->disableInterpolation` is reset!
lexerState->disableInterpolation = disableInterpolation;
static char buf[MAXSTRLEN + 1];
Symbol const *sym = sym_FindScopedValidSymbol(fmtBuf);
if (!sym) {
error("Interpolated symbol \"%s\" does not exist\n", fmtBuf.c_str());
} else if (sym->type == SYM_EQUS) {
std::string str = fmt.formatString(*sym->getEqus());
memcpy(buf, str.c_str(), str.length() + 1);
return buf;
static std::string buf;
buf.clear();
fmt.appendString(buf, *sym->getEqus());
return buf.c_str();
} else if (sym->isNumeric()) {
std::string str = fmt.formatNumber(sym->getConstantValue());
memcpy(buf, str.c_str(), str.length() + 1);
return buf;
static std::string buf;
buf.clear();
fmt.appendNumber(buf, sym->getConstantValue());
return buf.c_str();
} else {
error("Only numerical and string symbols can be interpolated\n");
}